Fix Enum Migration to properly deal with constraint changes
Since we're using non-native enums for our model, alembic has some issues knowing what the previous "type" actually was, and not specifying it correctly causes a bad constraint.
This commit is contained in:
@@ -29,11 +29,13 @@ parent_dir = Path(__file__).parent.parent
|
||||
sys.path.append(parent_dir)
|
||||
|
||||
from atst.app import make_config
|
||||
|
||||
app_config = make_config()
|
||||
config.set_main_option('sqlalchemy.url', app_config['DATABASE_URI'])
|
||||
config.set_main_option("sqlalchemy.url", app_config["DATABASE_URI"])
|
||||
|
||||
from atst.database import db
|
||||
from atst.models import *
|
||||
|
||||
target_metadata = Base.metadata
|
||||
|
||||
|
||||
@@ -51,8 +53,7 @@ def run_migrations_offline():
|
||||
"""
|
||||
url = config.get_main_option("sqlalchemy.url")
|
||||
context.configure(
|
||||
url=url, target_metadata=target_metadata, literal_binds=True,
|
||||
compare_type=True
|
||||
url=url, target_metadata=target_metadata, literal_binds=True, compare_type=True
|
||||
)
|
||||
|
||||
with context.begin_transaction():
|
||||
@@ -68,19 +69,19 @@ def run_migrations_online():
|
||||
"""
|
||||
connectable = engine_from_config(
|
||||
config.get_section(config.config_ini_section),
|
||||
prefix='sqlalchemy.',
|
||||
poolclass=pool.NullPool)
|
||||
prefix="sqlalchemy.",
|
||||
poolclass=pool.NullPool,
|
||||
)
|
||||
|
||||
with connectable.connect() as connection:
|
||||
context.configure(
|
||||
connection=connection,
|
||||
target_metadata=target_metadata,
|
||||
compare_type=True
|
||||
connection=connection, target_metadata=target_metadata, compare_type=True
|
||||
)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
if context.is_offline_mode():
|
||||
run_migrations_offline()
|
||||
else:
|
||||
|
Reference in New Issue
Block a user