sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

Consider documenting migration naming requirements

Open casey opened this issue 5 years ago • 4 comments

Unless I'm mistaken, it isn't documented that migration files must be named N_X.sql, where N is a number greater than 0, and X is the name of the migration.

casey avatar Dec 07 '20 07:12 casey

Hello!

I think it's defined here: https://github.com/launchbadge/sqlx/tree/master/sqlx-cli#create-and-run-migrations

But yes we can make it more explicit. Feels free to open a PR to add it to the documentation!

Freyskeyd avatar Dec 07 '20 09:12 Freyskeyd

Just to add on to this, I was using an older version of sqlx-cli to run my migrations, and was able to have a migration with version "0". I'm not a fan of the timestamp personally since I find them hard for humans to read, so I was using 000, 001, 002...

I updated my CLI recently and that became a large problem. Not a big deal, but I figure others might run into this as well.

kilpatty avatar Dec 08 '20 18:12 kilpatty

Any number should work as long they are incrementing. If it doesn't, that sounds like a bug. The timestamp is not required, only the default way the cli tool generates migration files.

mehcode avatar Dec 08 '20 18:12 mehcode

I just tried replicating, and I received the same error:

error: migration 0 was previously applied but is missing in the resolved migrations

If I switch my migration named 000_initial.sql to 001_initial.sql everything works as intended. I apologize that I can't recall which version I was using previously of sqlx-cli, but I can say for certain it was working at some point and with the latest release it is not. Not a huge burden for me personally, but if I find some time I'd be happy to dig around and see if I can figure out what changed.

kilpatty avatar Dec 08 '20 19:12 kilpatty