def upgrade():
    if not has_table("runs"):
        return

    if not has_table("snapshots"):
        op.create_table(
            "snapshots",
            sa.Column("id",
                      sa.Integer,
                      primary_key=True,
                      autoincrement=True,
                      nullable=False),
            sa.Column("snapshot_id",
                      sa.String(255),
                      unique=True,
                      nullable=False),
            sa.Column("snapshot_body", sa.LargeBinary, nullable=False),
            sa.Column("snapshot_type", sa.String(63), nullable=False),
        )

    if not has_column("runs", "snapshot_id"):
        op.add_column(
            "runs",
            sa.Column("snapshot_id", sa.String(255),
                      sa.ForeignKey("snapshots.snapshot_id")),
        )
def downgrade():
    if has_column("runs", "snapshot_id"):
        with op.batch_alter_table("runs") as batch_op:
            batch_op.drop_column("snapshot_id")

    if has_table("snapshots"):
        op.drop_table("snapshots")
def upgrade():
    if not has_table("snapshots"):
        op.create_table(
            "snapshots",
            sa.Column("id",
                      sa.Integer,
                      primary_key=True,
                      autoincrement=True,
                      nullable=False),
            sa.Column("snapshot_id",
                      sa.String(255),
                      unique=True,
                      nullable=False),
            sa.Column("snapshot_body", sa.LargeBinary, nullable=False),
            sa.Column("snapshot_type", sa.String(63), nullable=False),
        )

    if not has_column("runs", "snapshot_id"):
        # Sqlite does not support adding foreign keys to existing
        # tables, so we are forced to fallback on this witchcraft.
        # See https://alembic.sqlalchemy.org/en/latest/batch.html#dealing-with-referencing-foreign-keys
        # for additional context
        with op.batch_alter_table("runs") as batch_op:
            batch_op.execute("PRAGMA foreign_keys = OFF;")
            batch_op.add_column(
                sa.Column(
                    "snapshot_id",
                    sa.String(255),
                    sa.ForeignKey(
                        "snapshots.snapshot_id",
                        name="fk_runs_snapshot_id_snapshots_snapshot_id"),
                ), )
        op.execute("PRAGMA foreign_keys = ON;")
예제 #4
0
def downgrade():
    if has_column('runs', 'snapshot_id'):
        with op.batch_alter_table('runs') as batch_op:
            batch_op.drop_column('snapshot_id')

    if has_table('snapshots'):
        op.drop_table('snapshots')
def downgrade():
    if has_table("snapshots"):
        op.drop_table("snapshots")

    if not has_table("runs"):
        return

    if has_column("runs", "snapshot_id"):
        op.drop_column("runs", "snapshot_id")
예제 #6
0
def upgrade():
    if not has_table('snapshots'):
        op.create_table(
            'snapshots',
            sa.Column('id',
                      sa.Integer,
                      primary_key=True,
                      autoincrement=True,
                      nullable=False),
            sa.Column('snapshot_id',
                      sa.String(255),
                      unique=True,
                      nullable=False),
            sa.Column('snapshot_body', sa.LargeBinary, nullable=False),
            sa.Column('snapshot_type', sa.String(63), nullable=False),
        )

    if not has_column('runs', 'snapshot_id'):
        op.add_column(
            'runs',
            sa.Column('snapshot_id', sa.String(255),
                      sa.ForeignKey('snapshots.snapshot_id')),
        )
예제 #7
0
def downgrade():
    if has_column('runs', 'snapshot_id'):
        op.drop_column('runs', 'snapshot_id')

    if has_table('snapshots'):
        op.drop_table('snapshots')