I'm setting up alembic for our project, which is already really big, and has a lot of tables. The thing is that our project's DB has been managed via SQL for a long time, and our Alchemy models are almost all reflected like so (I obscured the name, but the rest is all directly from our code):
class SomeModel(Base, BaseModelMixin):
"""
Model docstring
"""
"""Reflect Table"""
__table__ = Table('some_models', metadata, autoload=True)
What's happening is that when I create an automatic migration, a lot of drop table (and a lot of create table) operations are created for some reason. I assumed it's because the model class doesn't explicitly define the tables, but I don't see why that would drop the tables as well.
I'm making sure all model definitions are processed before setting the target_metadata
variable in env.py
:
# this imports every model in our app
from shiphero_app.utils.sql_dependencies import import_dependencies
import_dependencies()
from shiphero_app.core.database import Base
target_metadata = Base.metadata
Any ideas of what might I be missing here?