Skip to content

Commit

Permalink
I thought it best to wrap all that SQL in a transaction, since it was…
Browse files Browse the repository at this point in the history
… breaking and all... And that helped in fixing the SQL. ;)
  • Loading branch information
al-the-x committed Oct 19, 2011
1 parent 46d4ec4 commit 106e309
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions bin/migration-init
Expand Up @@ -15,25 +15,27 @@ CREATE TABLE "migrations"."history" (
"migrations"."history" ( "migration_id" )
);
CREATE INDEX ON "migrations"."history" ( "migration_id" DESC );
CREATE INDEX "history_migration_id_idx" ON "migrations"."history" ( "migration_id" DESC );
CREATE INDEX ON "migrations"."history" ( "next_migration_id" DESC NULLS FIRST );
CREATE INDEX "history_next_migration_id_idx" ON "migrations"."history" ( "next_migration_id" DESC NULLS FIRST );
CREATE INDEX ON "migrations"."history" ( "applied" WHERE false );
CREATE INDEX "history_applied_idx" ON "migrations"."history" ( "applied" );
""",
'DOWN' : 'DROP SCHEMA "migrations";'
'DOWN' : 'DROP SCHEMA "migrations" CASCADE;'
}

class MigrationInit(migrations.Command):
def main ( self, arguments=(), uninstall=False, **kwargs ):
command = ('psql',) + arguments + ('-c',) + (MIGRATION_SCHEMA['DOWN'] if uninstall else MIGRATION_SCHEMA['UP'],)
command = ('psql',) + arguments + ('-c',) + ('BEGIN TRANSACTION;\n%s\nCOMMIT TRANSACTION;' % (
MIGRATION_SCHEMA['DOWN'] if uninstall else MIGRATION_SCHEMA['UP']
),)

subprocess.call(command)


if __name__ == '__main__':
command = MigrationInit(
).add_argument('--uninstall', action='store_true', help='uninstall the migrations schema instead of installing it'
).add_argument('--uninstall', action='store_true', help='uninstall the migrations schema instead'
).add_argument('ARGUMENTS', nargs='*', help='additional arguments to pass to the "psql" command, i.e. DBUSER, DBNAME, etc.'
)

Expand Down

0 comments on commit 106e309

Please sign in to comment.