diff options
| author | Abhilash Raj | 2014-09-25 15:28:46 +0530 |
|---|---|---|
| committer | Abhilash Raj | 2014-09-25 15:28:46 +0530 |
| commit | f2c619de76bd1614a6609f1a61e34ecf8a4344fc (patch) | |
| tree | 112e4ad6c50e11e7a33dae4a12b02aa99cec19fd /src/mailman/database | |
| parent | 03647b16eb75cc841bb15c3c48ac5f18f77118b8 (diff) | |
| download | mailman-f2c619de76bd1614a6609f1a61e34ecf8a4344fc.tar.gz mailman-f2c619de76bd1614a6609f1a61e34ecf8a4344fc.tar.zst mailman-f2c619de76bd1614a6609f1a61e34ecf8a4344fc.zip | |
* fixed a bug where alemnic could not find its migrations directory
* add a new method in base database to stamp with latest alembic version
Diffstat (limited to 'src/mailman/database')
| -rw-r--r-- | src/mailman/database/alembic/env.py | 1 | ||||
| -rw-r--r-- | src/mailman/database/base.py | 14 | ||||
| -rw-r--r-- | src/mailman/database/factory.py | 7 |
3 files changed, 16 insertions, 6 deletions
diff --git a/src/mailman/database/alembic/env.py b/src/mailman/database/alembic/env.py index 11ea8f6da..2d9d48fd7 100644 --- a/src/mailman/database/alembic/env.py +++ b/src/mailman/database/alembic/env.py @@ -57,6 +57,7 @@ def run_migrations_online(): alembic_cfg= Config() alembic_cfg.set_main_option( "script_location", config.alembic['script_location']) + alembic_cfg.set_section_option('logger_alembic' ,'level' , 'ERROR') url = expand(config.database.url, config.paths) engine = create_engine(url) diff --git a/src/mailman/database/base.py b/src/mailman/database/base.py index e360dcedf..0afdad204 100644 --- a/src/mailman/database/base.py +++ b/src/mailman/database/base.py @@ -25,6 +25,8 @@ __all__ = [ import logging +from alembic import command +from alembic.config import Config from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from zope.interface import implementer @@ -89,6 +91,18 @@ class SABaseDatabase: """ pass + def stamp(self, debug=False): + """Stamp the database with the latest alembic version. + """ + # Newly created database don't need to migrations from alembic, since + # `create_all`` ceates the latest schema. SO patch the database with + # the latest alembic version to add a entry in alembic_version table. + alembic_cfg = Config() + alembic_cfg.set_main_option( + "script_location", config.alembic['script_location']) + command.stamp(alembic_cfg, "head") + + def initialize(self, debug=None): """See `IDatabase`.""" # Calculate the engine url. diff --git a/src/mailman/database/factory.py b/src/mailman/database/factory.py index d4857866a..0a295331a 100644 --- a/src/mailman/database/factory.py +++ b/src/mailman/database/factory.py @@ -29,9 +29,6 @@ __all__ = [ import os import types -from alembic.config import Config -from alembic import command - from flufl.lock import Lock from zope.interface import implementer from zope.interface.verify import verifyObject @@ -42,8 +39,6 @@ from mailman.interfaces.database import IDatabase, IDatabaseFactory from mailman.utilities.modules import call_name -alembic_cfg = Config("./alembic.ini") - @implementer(IDatabaseFactory) class DatabaseFactory: @@ -58,7 +53,7 @@ class DatabaseFactory: verifyObject(IDatabase, database) database.initialize() Model.metadata.create_all(database.engine) - command.stamp(alembic_cfg, "head") + database.stamp() database.commit() return database |
