cli icon indicating copy to clipboard operation
cli copied to clipboard

Improve db/migrations misconfigurations

Open cllns opened this issue 1 year ago • 0 comments

Came to fix one thing and found a few more :)

  1. Fix the docker-compose configuration: use correct port, provide the password, add a note to the readme about docker compose up (successor to docker-compose)

  2. Re-word the warning when the user is missing config/db/. I found this from upgrading to 2.2.0.beta1 and the message I got was WARNING: Database ./db/bookshelf_development.sqlite has no config/db/ directory which doesn't make a ton of sense. Now it'll say WARNING: Database ./db/bookshelf_development.sqlite expects the folder config/db/ to exist but it does not.

  3. Add a specific warning when the user is missing config/db/migrate/ (but has config/db)

  4. Add a specific warning when the user has config/db/migrate/ but it's empty (they might have this folder but then have their migrations in a different folder, e.g. with the name 'migrations' which is incorrect)

I also added the line "No database migrations can be run for this database." to the last two, just to be really explicit. I'm not 100% sure it's true, though, if they have migrations in a slice instead of the main app. Happy to get rid of it, or re-word it so that it's always accurate.

After these changes, if they're missing config/db/ this is what they see when they run hanami db prepare

WARNING: Database ./db/bookshelf_development.sqlite expects the folder config/db/ to exist but it does not.

WARNING: Database ./db/bookshelf_development.sqlite expects migrations to be located within config/db/migrate/ but that folder does not exist.

No database migrations can be run for this database.
sh: ~/hanami/bookshelf/config/db/structure.sql: No such file or directory
!!! => "./db/bookshelf_development.sqlite structure dumped to config/db/structure.sql" FAILED

Which is pretty redundant but I'd rather give more info than too little. We can make it more concise later, and also skip attempting to dump the structure if we can know it'll fail beforehand.

cllns avatar Jul 19 '24 18:07 cllns