Can alembic run slightly different migration code based on database type? For example, run ALTER TABLE object AUTO_INCREMENT = 6000;
only on MySQL, but skip this for SQLite?
Some background: We're using alembic to run migrations. On many dev setups, we use sqlite, and on production we use mysql. On production, we want to start some Primary keys at a particular value, but on dev setups using sqlite, this is not possible and not needed, so we can skip this step.
It's possible to get the engine name from the bind. I added the following to my migration:
def upgrade():
# create table call
bind = op.get_bind()
if bind.engine.name == 'mysql':
op.execute("ALTER TABLE object AUTO_INCREMENT = 5000")
else:
print("Skipping setting initial ID value")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With