Skip to content

Commit

Permalink
Raise SystemExit when mark migration not found
Browse files Browse the repository at this point in the history
If migration is not found, "mark" was displaying an error message but
exiting normally.

The error message is still printed and dbmigrator will now exits with
code 1.
  • Loading branch information
karenc committed Aug 24, 2017
1 parent a96bd1c commit 1c6b8ed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
3 changes: 1 addition & 2 deletions dbmigrator/commands/mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ def cli_command(cursor, migrations_directory='', migration_timestamp='',
migrations_directory, import_modules=True)}
migration = migrations.get(migration_timestamp)
if migration is None:
logger.error(
raise SystemExit(
'Migration {} not found'.format(migration_timestamp))
return

utils.mark_migration(cursor, migration_timestamp, completed)
if not completed:
Expand Down
13 changes: 7 additions & 6 deletions dbmigrator/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,19 @@ def test_mark_as_true_already_true(self):
self.assertIn('20160228202637 add_table True', stdout)
self.assertIn('20160228212456 cool_stuff True', stdout)

@mock.patch('dbmigrator.logger.error')
def test_migration_not_found(self, error):
def test_migration_not_found(self):
testing.install_test_packages()
cmd = ['--db-connection-string', testing.db_connection_string]

self.target(cmd + ['--context', 'package-a', 'init', '--version', '0'])

self.target(cmd + ['mark', '-t', '012345'])
error.assert_called_with('Migration 012345 not found')
with self.assertRaises(SystemExit) as cm:
self.target(cmd + ['mark', '-t', '012345'])
self.assertEqual('Migration 012345 not found', str(cm.exception))

self.target(cmd + ['mark', '-f', '012345'])
error.assert_called_with('Migration 012345 not found')
with self.assertRaises(SystemExit) as cm:
self.target(cmd + ['mark', '-f', '012345'])
self.assertEqual('Migration 012345 not found', str(cm.exception))

def test_mark_as_false(self):
testing.install_test_packages()
Expand Down

0 comments on commit 1c6b8ed

Please sign in to comment.