Skip to content

Commit

Permalink
Direct Alembic to ignore the sqlite_sequence table (#586)
Browse files Browse the repository at this point in the history
* Direct Alembic to ignore the sqlite_sequence table

* Direct Alembic to ignore the sqlite_sequence table

* Fix "Skipping unsupported ALTER" warning on database migration
  • Loading branch information
Andrew-Dickinson authored Apr 26, 2020
1 parent 27cac86 commit 2c32c61
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
9 changes: 8 additions & 1 deletion ihatemoney/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def run_migrations_offline():
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(url=url)
context.configure(url=url, include_object=include_object)

with context.begin_transaction():
context.run_migrations()
Expand Down Expand Up @@ -75,6 +75,7 @@ def process_revision_directives(context, revision, directives):
context.configure(
connection=connection,
target_metadata=target_metadata,
include_object=include_object,
process_revision_directives=process_revision_directives,
**current_app.extensions["migrate"].configure_args
)
Expand All @@ -86,6 +87,12 @@ def process_revision_directives(context, revision, directives):
connection.close()


def include_object(object, name, type_, reflected, compare_to):
if name == "sqlite_sequence":
return False
return True


if context.is_offline_mode():
run_migrations_offline()
else:
Expand Down
38 changes: 28 additions & 10 deletions ihatemoney/migrations/versions/2dcb0c0048dc_autologger.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,39 @@ def upgrade():
sa.Column("remote_addr", sa.String(length=50), nullable=True),
sa.PrimaryKeyConstraint("id"),
)
op.add_column(
"project",
sa.Column(
"logging_preference",
sa.Enum("DISABLED", "ENABLED", "RECORD_IP", name="loggingmode"),
server_default="ENABLED",
nullable=False,
),
)
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(
"project",
sa.Column(
"logging_preference",
sa.Enum("DISABLED", "ENABLED", "RECORD_IP", name="loggingmode"),
server_default="ENABLED",
nullable=False,
),
)
# ### end Alembic commands ###


def downgrade():
# ### 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_index(
op.f("ix_project_version_transaction_id"), table_name="project_version"
Expand Down

0 comments on commit 2c32c61

Please sign in to comment.