Skip to content
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 Add flag to retrieve N most recent migrations #256

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cmpickle
Copy link

Resolves #254

This PR adds a flag that allows the user to retrieve the N most recent migrations. This is useful when you have many migrations that you have created and it takes a long time to print them all out and you just want to see the last few to either make sure they have all been applied or to make sure that the new migration timestamp you are working on will still be applied when another collaborator may have created and merged a migration before you.

usage example:
goose -n 10 mysql "[DB_String]" status
This would return the 10 most recent migrations

Copy link

@n8pickle n8pickle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mfridman
Copy link
Collaborator

.. to make sure that the new migration timestamp you are working on will still be applied when another collaborator may have created and merged a migration before you.

This is interesting. Is this a workaround to force goose to apply migrations that may be out-of-order when using timestamps and/or sequences?

If so, I'd much rather see a strict mode with the option to disable it as described in this thread #172 .. which would allow the behaviour mentioned here #172 (comment)

@cmpickle
Copy link
Author

cmpickle commented Jun 22, 2021

.. to make sure that the new migration timestamp you are working on will still be applied when another collaborator may have created and merged a migration before you.

This is interesting. Is this a workaround to force goose to apply migrations that may be out-of-order when using timestamps and/or sequences?

If so, I'd much rather see a strict mode with the option to disable it as described in this thread #172 .. which would allow the behaviour mentioned here #172 (comment)

No that is not the intention of this flag. This flag is intended to be able to quickly return the last N number of migrations for a database when running the status command.

There are 2 reasons that I find this helpful.

The first is when I am checking if an environment has had the latest migrations applied I don't want to see the full list of migrations just the last 5-10 to make sure that the migrations are applied not pending.

The second use case that I find it useful is because my team creates migrations for stories and this is all happening asynchronously and one story that is started first might take longer than another that finishes faster. Then at this point the timestamp of the migration that was created first would be out of sync and would not get applied if the date isn't updated.

With my current project we have hundreds of migrations and it takes quite a long time for goose to print out all the migrations when using that status command just to see if the order of the migration you are trying to add is correct. This second scenario could also be solved by just looking at the file names but it could be a lot easier to just run the status command if only the last few migrations are printed.

@mfridman
Copy link
Collaborator

mfridman commented Aug 3, 2021

My issue with this PR is that it modifies the resulting migrations list in CollectMigrations. And so this doesn't only affect status command, but all other commands.

If you'd like to print last-n migrations we can likely accomplish this with another implementation specific for status.

As mentioned in #256 (comment), I'd rather properly add opt-in disable strict mode to address things like this:

.. to make sure that the new migration timestamp you are working on will still be applied when another collaborator may have created and merged a migration before you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for last N migrations for the database
3 participants