As simple as they come, we got some fields for tokens that are 128 char long, and all should be well. Unfortunately it turns out that the tokens should be 256 characters long. The change is as simple as it comes, just replace 128 with 256
And then run the alembic to auto generate the migration with the usual command
bash
1
alembic revision --autogenerate -m "Upsize the token fields"
Which generates your migration file… And when you open it, it is empty… Wait! What?
1c78e2f11814_upsize_the_token_fields.py
1
2
3
4
5
6
7
8
9
10
11
12
# ... omitted for brevitydefupgrade():
### commands auto generated by Alembic - please adjust! ###pass### end Alembic commands ###defdowngrade():
### commands auto generated by Alembic - please adjust! ###pass### end Alembic commands ###
That is certainly not what we wanted, what could possibly be wrong?
Turns out that by default, the types are not compared in alembic,
which makes sense as the type comparison has a varying accuracy depending on the
backend.
The solution is as simple and as elusive as it gets.
In your alembic env.py file, modify the run_migrations_* methods context.configure segments
by adding the compare_type=True (lines 15 and 37).
# ... omitted for brevitydefrun_migrations_offline():
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url, target_metadata=target_metadata, literal_binds=True, compare_type=True)
with context.begin_transaction():
context.run_migrations()
defrun_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
connectable = engine_from_config(
config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool)
with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=target_metadata,
compare_type=True
)
with context.begin_transaction():
context.run_migrations()
Delete the empty migration file (if you haven’t already) and rerun the migration auto generation
the output will be what you would expect