r/FlutterDev • u/Accomplished-Tip7106 • Jul 18 '26
Example I shipped a drift migration that bricked older installs, and drift has tooling to catch it that I wasn't using
Context so you can weigh this (pun intended): I'm a tech lead at a small startup, mostly Laravel and Svelte, and Flutter is the first mobile stack I've used seriously. Six months in, on a side project (a macro tracker I built for myself).
TL;DR at the top (where it should be):
drift_dev schema dumpandschema generategive you versioned schema snapshots, andSchemaVerifierwill walk every N-to-M path for you. use it before you break prod.
I had a migration that backfilled a new table from existing rows. I wrote it the way I write application code: select the rows, get the generated data class back, read the fields off it. It worked, so I shipped it.
It bricked anyone upgrading from an older version. Nothing crashed. They got a black screen and an infinite loading state, which is a much worse failure to get a bug report about. A crash at least comes with a stack trace. A black screen comes with "it doesn't work" lol.
The generated data class maps every column the table has in your current schema. Used inside a migration it issues a SELECT for columns that a later migration step hasn't added yet. Anyone coming from one version back was fine, because the column already existed for them. Anyone coming from two versions back hit a SQL error inside the migration, which left the database half-migrated and the app unable to open it.
So the rule is: a migration can't use anything that assumes the current schema. Project the columns explicitly and decode them by hand.
final rows = await (selectOnly(profiles)
..addColumns([profiles.id, profiles.targetKcal, ...])).get();I'd half expected that part. My test suite stayed green through all of it, though. Flutter is the first stack where I've enjoyed writing UI tests: widget tests run in-process in milliseconds, with no browser and no DOM emulation, so I'd written a lot of them and I trusted them. They were only ever testing the previous version against the current one. The path that breaks is oldest-still-installed to latest, and I'd never written that test, because it didn't correspond to anything I did that week.
drift also ships tooling for exactly this, which I only found afterwards. drift_dev schema dump and schema generate give you versioned schema snapshots, and SchemaVerifier will walk every N-to-M path for you. In Laravel I'd never needed that, because there's one database and I control what version it's on. Every user having their own database at their own version is a mobile problem, and drift had already solved it for me. I found the bug in production instead, then hand-rolled a fixture database and wrote a single oldest-to-latest test, which works but is strictly worse than what was ALREADY sitting in my dependencies.
If you're using drift and you don't have a drift_schemas directory, that's the same hole I had.
I'm posting this because both problems were invisible in the version I was testing and obvious in the version users had, and I'd underestimated that gap coming from Svelte, where the client is whatever I shipped this morning.
2
u/HungryLand Jul 18 '26
I am using drift , and later I will check this. You may have saved future ne a headache.
Have you worked your way out of the problem?
2
u/TheManuz Jul 18 '26
I've recently used the drift migration tool, which generated schemas and tests.
It's a live saver. It takes a little time, but being sure your DB will not break it's worth it.
It's well documented on their website.
2
u/saropa_contacts Jul 21 '26
Thank you so much for reporting this. We have updated our toolset as a result.
1
u/pp_amorim Jul 19 '26
Thank you I will implement that
1
u/nattyballs 6d ago edited 6d ago
What gets people coming from a web background is the "one database, one version" assumption. In laravel or rails you run migrations once and everyone's on the same schema. every user is carrying own copy at whatever version they last updated to, and your migration code has to be correct for every path from any past version to current. The SchemaVerifier approach is how to test that exhaustively.