[PATCH] Add -o flag to force post-migrations to be run
Export this patch
# HG changeset patch
# User Josha Inglis <josha.inglis@packetfabric.com>
# Date 1608758195 -39600
# Thu Dec 24 08:16:35 2020 +1100
# Node ID 53138827a7d7cbeb811e404a0a169edee486b9e6
# Parent d8495101e8c79ed93e153c948deeaedfc3fda580
Add -o flag to force post-migrations to be run
diff --git a/yoyo/backends.py b/yoyo/backends.py
--- a/yoyo/backends.py
+++ b/yoyo/backends.py
@@ -430,9 +430,10 @@ class DatabaseBackend(object):
reversed(list(topological_sort(ms))), migrations.post_apply
)
- def apply_migrations(self, migrations, force=False):
+ def apply_migrations(self, migrations, force=False, force_post_migrations=False):
if migrations:
self.apply_migrations_only(migrations, force=force)
+ if migrations or force_post_migrations:
self.run_post_apply(migrations, force=force)
def apply_migrations_only(self, migrations, force=False):
diff --git a/yoyo/scripts/migrate.py b/yoyo/scripts/migrate.py
--- a/yoyo/scripts/migrate.py
+++ b/yoyo/scripts/migrate.py
@@ -87,6 +87,14 @@ def install_argparsers(global_parser, su
"they have been previously applied",
)
apply_parser.add_argument(
+ "-o",
+ "--force-post-migrations",
+ dest="force_post_migrations",
+ action="store_true",
+ help="Run post-migrations, regardless of whether "
+ "any new migrations are also applied",
+ )
+ apply_parser.add_argument(
"-f",
"--force",
dest="force",
@@ -249,7 +257,7 @@ def apply(args, config):
backend = get_backend(args, config)
with backend.lock():
migrations = get_migrations(args, backend)
- backend.apply_migrations(migrations, args.force)
+ backend.apply_migrations(migrations, args.force, args.force_post_migrations)
def reapply(args, config):
This looks good, thanks!
I'm wondering about making this a long option only
(--force-post-migrations). "-o" doesn't feel like it has a natural
connection to the long option name and I wonder if we really need a
short option for this feature.
How do you see using this?
Is this a flag that you'd use only occasionally? Or consistently? (in
which case it could be set in the config file). Or would you want to
regularly turn it on and off per invocation?
If the latter then there's a stronger case for a short option.
It would be good to have some tests too :)
Olly