From 32ddb9e180550b68af789d3025a78ce0a73debce Mon Sep 17 00:00:00 2001 From: karen chan Date: Tue, 22 Aug 2017 01:51:49 -0700 Subject: [PATCH] Add "*" to indicate repeated migrations in "list" There is no way to show migrations as "repeated" when listing them. It is useful to know which migrations might run when running "migrate". --- README.rst | 11 +++++++---- dbmigrator/commands/list.py | 2 ++ dbmigrator/tests/test_cli.py | 10 ++++++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index bfab02c..c4f2270 100644 --- a/README.rst +++ b/README.rst @@ -112,8 +112,11 @@ Example usage:: version | name | is applied | date applied ---------------------------------------------------------------------- 20151217170514 add_id_to_users True 2016-01-31 00:15:01.692570+01:00 - 20151218145832 add_karen_to_us False - 20160107200351 blah False + 20151218145832 add_karen_to_us False* + 20160107200351 blah deferred + +A `*` in the "is applied" column means that the migration is a repeated +migration. To see the full migration name, use ``--wide``:: @@ -121,8 +124,8 @@ To see the full migration name, use ``--wide``:: version | name | is applied | date applied ---------------------------------------------------------------------- 20151217170514 add_id_to_users True 2016-01-31 00:15:01.692570+01:00 - 20151218145832 add_karen_to_users False - 20160107200351 blah False + 20151218145832 add_karen_to_users False* + 20160107200351 blah deferred migrate diff --git a/dbmigrator/commands/list.py b/dbmigrator/commands/list.py index 272d2a5..0e0a623 100644 --- a/dbmigrator/commands/list.py +++ b/dbmigrator/commands/list.py @@ -42,6 +42,8 @@ def cli_command(cursor, migrations_directory='', db_connection_string='', version, migration, migrated_versions) is_applied = deferred and 'deferred' or \ bool(migrated_versions.get(version)) + if hasattr(migration, 'should_run'): + is_applied = '{}*'.format(is_applied) print('{} {} {!s: <10} {}'.format( version, name_format.format(migration_name[:name_width]), is_applied, migrated_versions.get(version) or '')) diff --git a/dbmigrator/tests/test_cli.py b/dbmigrator/tests/test_cli.py index 98433a1..d21a8e7 100644 --- a/dbmigrator/tests/test_cli.py +++ b/dbmigrator/tests/test_cli.py @@ -353,7 +353,7 @@ def test_deferred(self): self.target(cmd + ['list']) stdout = out.getvalue() - self.assertIn('20170810124056 empty deferred 20', + self.assertIn('20170810124056 empty deferred* 20', stdout) # mark a deferred migration as not not been run @@ -679,7 +679,13 @@ def cleanup(): with testing.captured_output() as (out, err): self.target(cmd + ['migrate']) - self.target(cmd + ['list']) + with testing.captured_output() as (out, err): + self.target(cmd + ['list']) + + stdout = out.getvalue() + self.assertIn('20170810093842 create_a_table True ', stdout) + self.assertIn('20170810093943 repeat_insert_d True*', stdout) + self.assertIn('20170810124056 empty deferred*', stdout) # Version wise, the empty migration is more recent, but the repeat # migration is the last migration applied, so rollback should rollback