def test_unreachable_attr(self): migrations = [ mig('app01', '0001_initial'), mig('app01', '0002_two'), mig('app02', '0001_initial'), mig('app02', '0002_two', run_on_deploy=False), mig('app02', '0003_three'), ] with pytest.raises(RuntimeError): get_stop_points('appname', migrations, strict=True)
def test_unreachable(self): migrations = [ mig('app01', '0001_initial'), mig('app01', '0002_two'), mig('app02', '0001_initial'), mig('app02', '0002_two_NOT_ON_DEPLOY'), mig('app02', '0003_three'), ] with pytest.raises(RuntimeError): get_stop_points('appname', migrations, strict=True)
def handle(self, *args, **options): # Get the database we're operating from connection = connections[DEFAULT_DB_ALIAS] # Run through each app one-by-one to ensure every migration has its best # chance of being run. something_done = False for current_app in apps.get_app_configs(): apps_migrations = get_all_unapplied_migrations(connection, current_app.label) try: stop_points = get_stop_points(current_app.label, apps_migrations, strict=True) except RuntimeError as e: if current_app.label in e.migrations: raise CommandError(e.msg) for app_label, stop_point in stop_points.items(): # Do not apply any migrations for this app if stop_point is False: msg = 'Did not migrate {} because a migration was flagged NOT_ON_DEPLOY' print(msg.format(current_app.label)) continue # Apply all migrations for this app if stop_point is None: management.call_command('migrate', app_label, **options) something_done = True # Apply specific migration for this app else: management.call_command('migrate', app_label, stop_point, **options) msg = 'Migrated {}, but stopped before a migration flagged NOT_ON_DEPLOY' print(msg.format(current_app.label)) something_done = True if not something_done: print('Nothing to migrate.')
def test_normal(self): migrations = [ mig('app01', '0001_initial'), mig('app01', '0002_two'), mig('app02', '0001_initial'), ] output = get_stop_points('appname', migrations) assert output == {'app01': None, 'app02': None}
def test_no_stop_attr(self): migrations = [ mig('app01', '0001_initial'), mig('app01', '0002_two'), mig('app02', '0001_initial'), mig('app02', '0002_two', run_on_deploy=True), ] output = get_stop_points('appname', migrations) assert output == {'app01': None, 'app02': None}
def test_stop(self): migrations = [ mig('app01', '0001_initial'), mig('app01', '0002_two'), mig('app02', '0001_initial'), mig('app02', '0002_two_NOT_ON_DEPLOY'), ] output = get_stop_points('appname', migrations) assert output == {'app01': None, 'app02': '0001_initial'}
def test_unreachable_2(self): migrations = [ mig('app01', '0001_initial'), mig('app01', '0002_two'), mig('app02', '0001_initial'), mig('app02', '0002_two_NOT_ON_DEPLOY'), mig('app02', '0003_three'), ] output = get_stop_points('appname', migrations, strict=False) assert output == {'app01': None, 'app02': '0001_initial'}
def test_unreachable_attr_2(self): migrations = [ mig('app01', '0001_initial'), mig('app01', '0002_two'), mig('app02', '0001_initial'), mig('app02', '0002_two', run_on_deploy=False), mig('app02', '0003_three'), ] output = get_stop_points('appname', migrations, strict=False) assert output == {'app01': None, 'app02': '0001_initial'}
def test_only_stop(self): migrations = [ mig('app02', '0002_two_NOT_ON_DEPLOY'), ] output = get_stop_points('appname', migrations) assert output == {'app02': False}
def test_empty(self): output = get_stop_points('appname', []) assert output == {}