Skip to content
This repository was archived by the owner on Jan 23, 2019. It is now read-only.

Add a config option to run all missing migrations (even those possibly out of order)#27

Open
hjc wants to merge 4 commits intocam-stitt:masterfrom
hjc:master
Open

Add a config option to run all missing migrations (even those possibly out of order)#27
hjc wants to merge 4 commits intocam-stitt:masterfrom
hjc:master

Conversation

@hjc
Copy link
Copy Markdown

@hjc hjc commented Apr 1, 2016

This PR adds support for a new command line option to arnold up named --migrate-missing. --migrate-missing changes the behavior of arnold to run all migrations that have not been run, even those that might be out of order.

Consider this file structure:

.
├── 001_mig.py
├── 003_mig.py
└── 004_mig.py

4 migrations that have all been migrated up. Then a branch is merged in with a migration named: 002_mig.py. Creating:

.
├── 001_mig.py
├── 002_mig.py
├── 003_mig.py
└── 004_mig.py

With the current way arnold works, this new migration will not be picked up at all and will be skipped. This is because arnold always starts at the latest migration and migrates from there.

The --migrate-missing flag fixes this and runs the missing migrations. I know this can be dangerous, but it's part of my team's workflow and, if you name your migrations via date, keep them non-destructive and don't have them heavily depend on each other, it really isn't that dangerous (we've had zero issues in the 3 years we've done this).

Since it's dangerous, it's an opt-in command line flag.

It also adds full tests for it, some docs, and a requirements.txt to run the tests, plus a few .gitignore updates. Let me know if any of that is an issue!

Hayden Chudy added 4 commits March 31, 2016 21:41
Right now, test_migrate_missing and test_migrate_missing_prevents_down fail.

Added a test for arnold up 0 because I could.
This flag allows running migrations out of order. It operates by grabbing the
  set of available migrations, and the set of already run migrations and taking
  their complement. That set of migrations is then run.

This flag is only available on `up`, it makes no sense on `down`.

**WARNING:** If you key your migrations numerically, this could be dangerous
  as it could result in migrations with the same prefix being run in an
  unspecified order. If you key by date, you should be fine. Ideally, write
  migrations that are non-destructive and non-dependent and you'll bee 100%
  fine.

Also adds a few straggling tests. Such as ensuring migrations are run in the
  right order, with or without the new flag. New test to ensure latest
  migration is always based on name.

Docs for the new feature and a warning on the arg help.
@hjc
Copy link
Copy Markdown
Author

hjc commented Apr 1, 2016

Oh, I know I jumped the gun on this and didn't even open an issue, but this was brought to my attention today and I was able to get it solved in about 10m, figured I should clean it up and open a PR no matter what!

@hjc
Copy link
Copy Markdown
Author

hjc commented Apr 1, 2016

Woah... PyPy is failing like crazy. If this interests you, could you tell me how to replicate the PyPy environment so I can figure out what's going on?

@cam-stitt
Copy link
Copy Markdown
Owner

I'd like to look at this once we get #26 merged. I think there might be some work done there that could assist with this.

@hjc
Copy link
Copy Markdown
Author

hjc commented Apr 15, 2016

Yea, looks like they implemented some of the same stuff I did in here a week or so after I opened this. I'd be happy to take over wrapping that in a config option, because I know some people really don't like that behavior.

And regardless of whether my actual Terminator code is used, I believe the tests are still valid after a bit of tweaking, and I'm happy to work on better test coverage =).

I have a few more ideas I'd like to contribute, if you're interested. Such as:

@cam-stitt
Copy link
Copy Markdown
Owner

Feel free to throw any suggestions into the issues section. I'll review and discuss each one individually.

@hjc
Copy link
Copy Markdown
Author

hjc commented Apr 15, 2016

Awesome! Just opened three new issues with #30, #31, and #32. If you tell me they're things you're interested in and would be willing to merge, I'd be more than happy to tackle them myself once we get #26, #27, and, ideally, #29 resolved and cemented into place!

Love arnold btw, it's so super simple, but with a little more work it could be a great tool!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants