[Mailman-Developers] Using alembic autogenerate
Adam Clark
adam at iris.washington.edu
Sat Dec 6 04:02:29 CET 2014
Is there a procedure for autogenerating a database update using alembic? I haven't used alembic before, but through trial and error I arrived at this:
> alembic -c mailman/config/alembic.cfg revision --autogenerate
This fails with
File "/workspace/test/mailman/libs/mailman/src/mailman/config/config.py", line 98, in __getattr__
return getattr(self._config, name)
AttributeError: 'NoneType' object has no attribute 'database'
So apparently mailman config wasn't being loaded. I added it to mailman/database/alembic/env.py:
def run_migrations_online():
config.load() # Added
url = expand(config.database.url, config.paths)
...
This succeeded in producing a version file, but that version would delete everything:
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_table('message')
op.drop_table('address')
op.drop_table('autoresponserecord')
op.drop_table('member')
op.drop_table('ban')
...
The root cause appeared to be that Model.metadata.sorted_tables returned an empty list. Manually triggering model reflection seemed to improve things; again in env.py:
def run_migrations_online():
config.load() # Added
url = expand(config.database.url, config.paths)
engine = create_engine(url)
Model.metadata.reflect(bind=engine) # Added
connection = engine.connect()
...
This now produces a correctly empty update against the existing code; the problem is if I change the code (and I verified that Model.metadata.sorted_tables reflects the changed model information) this *still* produces an empty update.
I suspect that I have this all backwards, that this whole process is actually intended to run from within mailman rather than via the alembic command line, but I can't find where this would be.
Thanks,
Adam
More information about the Mailman-Developers
mailing list