diff options
Diffstat (limited to 'ihatemoney/migrations')
| -rw-r--r-- | ihatemoney/migrations/versions/cb038f79982e_sqlite_autoincrement.py | 70 |
1 files changed, 40 insertions, 30 deletions
diff --git a/ihatemoney/migrations/versions/cb038f79982e_sqlite_autoincrement.py b/ihatemoney/migrations/versions/cb038f79982e_sqlite_autoincrement.py index ae5ab32..718aa75 100644 --- a/ihatemoney/migrations/versions/cb038f79982e_sqlite_autoincrement.py +++ b/ihatemoney/migrations/versions/cb038f79982e_sqlite_autoincrement.py @@ -15,36 +15,46 @@ import sqlalchemy as sa def upgrade(): - alter_table_batches = [ - op.batch_alter_table( - "person", recreate="always", table_kwargs={"sqlite_autoincrement": True} - ), - op.batch_alter_table( - "bill", 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: - with batch_op: - pass + bind = op.get_bind() + if bind.engine.name == "sqlite": + alter_table_batches = [ + op.batch_alter_table( + "person", recreate="always", table_kwargs={"sqlite_autoincrement": True} + ), + op.batch_alter_table( + "bill", 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: + with batch_op: + pass def downgrade(): - alter_table_batches = [ - op.batch_alter_table( - "person", 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: - with batch_op: - pass + bind = op.get_bind() + if bind.engine.name == "sqlite": + alter_table_batches = [ + op.batch_alter_table( + "person", + 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: + with batch_op: + pass |
