Fix sqlite only migration.

This commit is contained in:
Rémy HUBSCHER 2020-04-25 11:18:55 +02:00
parent 10c35e41ce
commit 0160bbe7d6
No known key found for this signature in database
GPG key ID: A500E24B95405094
4 changed files with 41 additions and 31 deletions

2
.gitignore vendored
View file

@ -11,4 +11,4 @@ build
.vscode .vscode
.env .env
.pytest_cache .pytest_cache
ihatemoney/budget.db

View file

View file

@ -15,36 +15,46 @@ import sqlalchemy as sa
def upgrade(): def upgrade():
alter_table_batches = [ bind = op.get_bind()
op.batch_alter_table( if bind.engine.name == "sqlite":
"person", recreate="always", table_kwargs={"sqlite_autoincrement": True} alter_table_batches = [
), op.batch_alter_table(
op.batch_alter_table( "person", recreate="always", table_kwargs={"sqlite_autoincrement": True}
"bill", recreate="always", table_kwargs={"sqlite_autoincrement": True} ),
), op.batch_alter_table(
op.batch_alter_table( "bill", recreate="always", table_kwargs={"sqlite_autoincrement": True}
"billowers", recreate="always", table_kwargs={"sqlite_autoincrement": True} ),
), op.batch_alter_table(
] "billowers",
recreate="always",
table_kwargs={"sqlite_autoincrement": True},
),
]
for batch_op in alter_table_batches: for batch_op in alter_table_batches:
with batch_op: with batch_op:
pass pass
def downgrade(): def downgrade():
alter_table_batches = [ bind = op.get_bind()
op.batch_alter_table( if bind.engine.name == "sqlite":
"person", recreate="always", table_kwargs={"sqlite_autoincrement": False} alter_table_batches = [
), op.batch_alter_table(
op.batch_alter_table( "person",
"bill", recreate="always", table_kwargs={"sqlite_autoincrement": False} recreate="always",
), table_kwargs={"sqlite_autoincrement": False},
op.batch_alter_table( ),
"billowers", recreate="always", table_kwargs={"sqlite_autoincrement": False} op.batch_alter_table(
), "bill", recreate="always", table_kwargs={"sqlite_autoincrement": False}
] ),
op.batch_alter_table(
"billowers",
recreate="always",
table_kwargs={"sqlite_autoincrement": False},
),
]
for batch_op in alter_table_batches: for batch_op in alter_table_batches:
with batch_op: with batch_op:
pass pass