Fix "Skipping unsupported ALTER" warning on database migration

This commit is contained in:
Andrew Dickinson 2020-04-25 20:53:10 -04:00
parent e2cd3342d0
commit d5e6370bbe

View file

@ -165,21 +165,39 @@ def upgrade():
sa.Column("remote_addr", sa.String(length=50), nullable=True), sa.Column("remote_addr", sa.String(length=50), nullable=True),
sa.PrimaryKeyConstraint("id"), sa.PrimaryKeyConstraint("id"),
) )
op.add_column( bind = op.get_bind()
"project", if bind.engine.name == "sqlite":
sa.Column( with op.batch_alter_table("project", recreate="always") as batch_op:
"logging_preference", batch_op.add_column(
sa.Enum("DISABLED", "ENABLED", "RECORD_IP", name="loggingmode"), sa.Column(
server_default="ENABLED", "logging_preference",
nullable=False, sa.Enum("DISABLED", "ENABLED", "RECORD_IP", name="loggingmode"),
), server_default="ENABLED",
) nullable=False,
),
)
else:
op.add_column(
"project",
sa.Column(
"logging_preference",
sa.Enum("DISABLED", "ENABLED", "RECORD_IP", name="loggingmode"),
server_default="ENABLED",
nullable=False,
),
)
# ### end Alembic commands ### # ### end Alembic commands ###
def downgrade(): def downgrade():
# ### commands auto generated by Alembic - please adjust! ### # ### commands auto generated by Alembic - please adjust! ###
op.drop_column("project", "logging_preference")
bind = op.get_bind()
if bind.engine.name == "sqlite":
with op.batch_alter_table("project", recreate="always") as batch_op:
batch_op.drop_column("logging_preference")
else:
op.drop_column("project", "logging_preference")
op.drop_table("transaction") op.drop_table("transaction")
op.drop_index( op.drop_index(
op.f("ix_project_version_transaction_id"), table_name="project_version" op.f("ix_project_version_transaction_id"), table_name="project_version"