Skip to content

Commit

Permalink
Add "*" to indicate repeated migrations in "list"
Browse files Browse the repository at this point in the history
There is no way to show migrations as "repeated" when listing them.  It
is useful to know which migrations might run when running "migrate".
  • Loading branch information
karenc committed Aug 24, 2017
1 parent 1c6b8ed commit 32ddb9e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
11 changes: 7 additions & 4 deletions README.rst
Expand Up @@ -112,17 +112,20 @@ 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``::

$ dbmigrator --config=development.ini list --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
Expand Down
2 changes: 2 additions & 0 deletions dbmigrator/commands/list.py
Expand Up @@ -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 ''))
Expand Down
10 changes: 8 additions & 2 deletions dbmigrator/tests/test_cli.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 32ddb9e

Please sign in to comment.