-
-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add migration:refresh
, migration:reset
, migration:fresh
and db:wipe
commands
#764
Add migration:refresh
, migration:reset
, migration:fresh
and db:wipe
commands
#764
Conversation
…/JuliensForks/lucid into feat/reset-wipe-refresh-commands
migration:refresh
and migration:reset
78942fa
to
8f1d902
Compare
Thanks for creating this PR. I know many have asked for it several times :)
We have methods for dropping all the tables here https://github.com/adonisjs/lucid/blob/develop/src/Dialects/Pg.ts#L58-L61. Will this help? |
Exactly what I needed, I hadn't seen these functions! Thank you ! Edit : I guess it's just an oversight, but any reason for dropAllTables not being defined here? https://github.com/adonisjs/lucid/blob/develop/src/QueryClient/index.ts |
I added dropAllTables to the QueryClient, and fixed a minor bug: an exception was thrown when dropAllTables was called with empty database on Postgres/Redshift Related docs PR : adonisjs/v5-docs#115 |
migration:refresh
and migration:reset
migration:refresh
, migration:reset
, migration:fresh
and db:wipe
commands
Added |
Looks good to me at a first glance. Let's merge it and give it a test run |
Thanks @Julien-R44 for spending time on this. Also, I was looking at Laravel and found that they also drop all the Do you think it is worth dropping them? |
Great, thanks you ! |
Make sense! |
Proposed changes
Hey ! 👋
This PR add the following commands :
node ace migration:reset
is basically an alias for node ace migration:rollback --batch 0.node ace migration:refresh
calls migration:reset, migration:run, and db:seed ( if asked ).node ace migration:refresh
is a command that is absolutely missing in Adonis. I often find myself going into TablePlus, deleting my DB, and restarting my migrations + seeders.node ace migration:refresh --seed
is a real time-saver in my opinion.Also these two commands are very often used by Laravel developers, and they make up a big part of our community !
In a near future I will propose two new commands
db:wipe
andmigration:fresh
which will also have the same behavior as on Laravel : completely remove the DB (truncate, no rollback of migrations). That said it's a bit more complicated because I had a quick look and Knex doesn't seem to offer an abstraction for truncating, so we'll have to write our own abstraction or find a small plugin. ( If you have any recommendations please let me know )Types of changes
Checklist
Further comments
I don't expect this PR to be merged right away, I'm willing to work on it again because one point seems quite problematic to me:
I would have liked to use
kernel.exec
to execute the commands, it would have been much cleaner, but the problem is that the MigrationBase class closes the connection to the database at the end of each command.So I had to add a
shouldCloseConnectionAfterMigrations
property, which I set to false when I need to run several commands in the same process.I'm really not sure if this is the best solution. If you have something better to suggest, don't hesitate and I'll make the necessary changes!