Skip to content

Fix FunWithFlags boolean gate migration#13

Merged
Ch4s3 merged 1 commit into
mainfrom
fix/fun-with-flags-boolean-gate-migration
Jun 1, 2026
Merged

Fix FunWithFlags boolean gate migration#13
Ch4s3 merged 1 commit into
mainfrom
fix/fun-with-flags-boolean-gate-migration

Conversation

@Ch4s3

@Ch4s3 Ch4s3 commented Jun 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • Prevents duplicate boolean gate rows: adds a boolean-specific put/2 to the Ecto store that deletes any existing boolean row (regardless of target sentinel) before inserting the new one. FunWithFlags used a different target value than Bandera's "_bandera_none" sentinel, so the upsert conflict key (flag_name, gate_type, target) didn't match — a second row was inserted instead of updating the first.
  • Fixes existing data: adds Bandera.Ecto.Migrations.fix_fun_with_flags_boolean_gates/0, a migration helper for the one-time cleanup of duplicate rows already in the database.
  • Generates the migration: adds mix bandera.gen.fix_fun_with_flags_migration to scaffold the migration file in one command.
  • Documents the trap: adds a warning block to the migration guide's Step 5 (Option A — keep existing table) explaining the issue and linking to the fix.

Symptom

After migrating from FunWithFlags with an existing table, a flag's dashboard toggle showed "on" while the summary showed "off · N actors", and clicking the toggle appeared to do nothing.

Test Plan

  • mix test — 406 passing, 13 excluded
  • mix bandera.gen.fix_fun_with_flags_migration --path /tmp/smoke && cat /tmp/smoke/*.exs — generates a correctly timestamped migration file
  • Migrate a real FunWithFlags table: run mix ecto.migrate with the generated migration; confirm legacy target = "boolean" rows become target = "_bandera_none" and duplicates are removed

Prevents and fixes duplicate boolean gate rows that occur when migrating
from FunWithFlags to Bandera using an existing Ecto table.

Root cause: FunWithFlags stored boolean gates with a legacy target value;
Bandera uses "_bandera_none". The upsert conflict key is
(flag_name, gate_type, target), so the two sentinels don't conflict —
a second row is inserted rather than updating the first. The symptom is
a dashboard toggle that shows "on" while the summary shows "off", and
clicking the toggle appears to do nothing.

Changes:
- Add boolean-specific put/2 to the Ecto store that deletes any existing
  boolean row before inserting, preventing duplicates going forward
- Add Bandera.Ecto.Migrations.fix_fun_with_flags_boolean_gates/0, a
  migration helper for one-time cleanup of duplicates already in the DB
- Add mix bandera.gen.fix_fun_with_flags_migration to scaffold the
  migration file in one command
- Add a warning block to the migration guide Step 5 (Option A)
@Ch4s3
Ch4s3 force-pushed the fix/fun-with-flags-boolean-gate-migration branch from 3e2bf56 to 3b4b54b Compare June 1, 2026 20:28
@Ch4s3
Ch4s3 merged commit 0d2e7cf into main Jun 1, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant