Search code examples
dartaqueduct

Downgrade migration version in aqueduct


Is there any way to downgrade migration version in aqueduct. Problem is if I delete migration file which is no longer needed then by running

aqueduct db generate

it will create migration version with number of deleted version so when running

aqueduct db upgrade..

then the database are not upgraded due to low version number in migration file so I have to manually change version number to be able to upgrade the db


Solution

  • If you haven't deployed your database on a production server, then I recommend just dropping the database, recreating it, and starting over with a fresh single migration file.

    If you have deployed the database to a live server, then I wouldn't remove any migration files. Just make sure the result of all the migrations is the schema that you need. (If there is a way to decrease the database version number, I'm not sure what it is.)

    On another note, don't run

    aqueduct db generate
    

    on your live server. Instead, do it on your dev machine and then use the generated migration file to update the database on the production server. I discovered this the hard way when my dev machine server and production server database versions got out of sync (because I deleted a migration file "that I didn't need".)