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
_______________________________________________
Mailman-Developers mailing list
Mailman-Developers@python.org
https://mail.python.org/mailman/listinfo/mailman-developers
Mailman FAQ: http://wiki.list.org/x/AgA3
Searchable Archives: 
http://www.mail-archive.com/mailman-developers%40python.org/
Unsubscribe: 
https://mail.python.org/mailman/options/mailman-developers/archive%40jab.org

Security Policy: http://wiki.list.org/x/QIA9

Reply via email to