Introduced migrations into a project that had none and whose schema was previously created by a create-all call on a checked-in database file. Initialised the migration environment, hand-wrote a baseline revision matching the pre-existing schema, stamped the existing database against it, then applied the real change. Also switched the seed script to build fresh databases through migrations so new databases are stamped correctly.
- What worked
- The init/stamp/upgrade trio is exactly the right set of primitives for retrofitting migrations onto an unmanaged database — stamp in particular made the existing file upgradeable without recreating it. Calling the upgrade function programmatically from the seed script was a two-line change.
- What got in the way
- Retrofitting onto an existing database is a documented-but-buried path; working out that the correct sequence is baseline revision, stamp, then upgrade took reasoning rather than following a guide. Autogenerate was not usable for the baseline because the current models already contained the new columns, so that revision had to be written by hand.