mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-04-29 01:42:37 +02:00
Direct Alembic to ignore the sqlite_sequence table (#586)
* Direct Alembic to ignore the sqlite_sequence table * Direct Alembic to ignore the sqlite_sequence table * Fix "Skipping unsupported ALTER" warning on database migration
This commit is contained in:
parent
27cac869d3
commit
2c32c6190c
2 changed files with 36 additions and 11 deletions
|
@ -41,7 +41,7 @@ def run_migrations_offline():
|
||||||
|
|
||||||
"""
|
"""
|
||||||
url = config.get_main_option("sqlalchemy.url")
|
url = config.get_main_option("sqlalchemy.url")
|
||||||
context.configure(url=url)
|
context.configure(url=url, include_object=include_object)
|
||||||
|
|
||||||
with context.begin_transaction():
|
with context.begin_transaction():
|
||||||
context.run_migrations()
|
context.run_migrations()
|
||||||
|
@ -75,6 +75,7 @@ def run_migrations_online():
|
||||||
context.configure(
|
context.configure(
|
||||||
connection=connection,
|
connection=connection,
|
||||||
target_metadata=target_metadata,
|
target_metadata=target_metadata,
|
||||||
|
include_object=include_object,
|
||||||
process_revision_directives=process_revision_directives,
|
process_revision_directives=process_revision_directives,
|
||||||
**current_app.extensions["migrate"].configure_args
|
**current_app.extensions["migrate"].configure_args
|
||||||
)
|
)
|
||||||
|
@ -86,6 +87,12 @@ def run_migrations_online():
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
|
|
||||||
|
def include_object(object, name, type_, reflected, compare_to):
|
||||||
|
if name == "sqlite_sequence":
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
if context.is_offline_mode():
|
if context.is_offline_mode():
|
||||||
run_migrations_offline()
|
run_migrations_offline()
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -165,6 +165,18 @@ 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"),
|
||||||
)
|
)
|
||||||
|
bind = op.get_bind()
|
||||||
|
if bind.engine.name == "sqlite":
|
||||||
|
with op.batch_alter_table("project", recreate="always") as batch_op:
|
||||||
|
batch_op.add_column(
|
||||||
|
sa.Column(
|
||||||
|
"logging_preference",
|
||||||
|
sa.Enum("DISABLED", "ENABLED", "RECORD_IP", name="loggingmode"),
|
||||||
|
server_default="ENABLED",
|
||||||
|
nullable=False,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
else:
|
||||||
op.add_column(
|
op.add_column(
|
||||||
"project",
|
"project",
|
||||||
sa.Column(
|
sa.Column(
|
||||||
|
@ -179,6 +191,12 @@ def upgrade():
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
|
||||||
|
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_column("project", "logging_preference")
|
||||||
op.drop_table("transaction")
|
op.drop_table("transaction")
|
||||||
op.drop_index(
|
op.drop_index(
|
||||||
|
|
Loading…
Reference in a new issue