@click.command()<EOL>@click.argument('<STR_LIT:name>')<EOL>@click.option('<STR_LIT>', is_flag=True, default=False, help='<STR_LIT>')<EOL>@click.pass_context<EOL>def revert(ctx, name, verbose):
try:<EOL><INDENT>app_name, target_migration = name.split('<STR_LIT:/>', <NUM_LIT:2>)<EOL><DEDENT>except ValueError:<EOL><INDENT>raise click.ClickException('<STR_LIT>')<EOL><DEDENT>apps = ctx.obj['<STR_LIT>']['<STR_LIT>']<EOL>if app_name not in apps.keys():<EOL><INDENT>raise click.ClickException('<STR_LIT>'.format(app_name))<EOL><DEDENT>app = apps[app_name]<EOL>migrations = app['<STR_LIT>']<EOL>if target_migration not in migrations:<EOL><INDENT>raise click.ClickException('<STR_LIT>'.format(name))<EOL><DEDENT>mig_idx = migrations.index(target_migration)<EOL>migrations = migrations[-len(migrations) + mig_idx:]  <EOL>migrations = migrations[::-<NUM_LIT:1>]  <EOL>for migration in migrations:<EOL><INDENT>click.echo(<EOL>click.style('<STR_LIT>'.format(click.style(app_name + '<STR_LIT:/>' + migration, bold=True)), fg='<STR_LIT>'))<EOL>if not ctx.obj['<STR_LIT>'].is_migration_applied(app_name, migration):<EOL><INDENT>click.echo(click.style('<STR_LIT>', fg='<STR_LIT>'))<EOL>continue<EOL><DEDENT>try:<EOL><INDENT>snaql_factory = Snaql(app['<STR_LIT:path>'], '<STR_LIT>')<EOL>queries = snaql_factory.load_queries(migration + '<STR_LIT>').ordered_blocks<EOL>for query in queries:<EOL><INDENT>if verbose:<EOL><INDENT>click.echo('<STR_LIT:U+0020>' + query())<EOL><DEDENT>ctx.obj['<STR_LIT>'].query(query())<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>click.echo(click.style('<STR_LIT>', fg='<STR_LIT>'))<EOL>ctx.obj['<STR_LIT>'].rollback()<EOL>raise click.ClickException('<STR_LIT>'.format(e))<EOL><DEDENT>click.echo(click.style('<STR_LIT>', fg='<STR_LIT>'))<EOL>ctx.obj['<STR_LIT>'].commit()<EOL>ctx.obj['<STR_LIT>'].revert_migration(app_name, migration)<EOL><DEDENT>
Revert migration