diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/commands/cli_migrate.py | 51 | ||||
| -rw-r--r-- | src/mailman/config/schema.cfg | 3 | ||||
| -rw-r--r-- | src/mailman/database/alembic/__init__.py | 0 | ||||
| -rw-r--r-- | src/mailman/database/alembic/env.py | 25 |
4 files changed, 61 insertions, 18 deletions
diff --git a/src/mailman/commands/cli_migrate.py b/src/mailman/commands/cli_migrate.py new file mode 100644 index 000000000..6593ea832 --- /dev/null +++ b/src/mailman/commands/cli_migrate.py @@ -0,0 +1,51 @@ +# Copyright (C) 2010-2014 by the Free Software Foundation, Inc. +# +# This file is part of GNU Mailman. +# +# GNU Mailman is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. + +"""bin/mailman migrate.""" + +from __future__ import absolute_import, print_function, unicode_literals + +__metaclass__ = type +__all__ = [ + 'Migrate', +] + +from alembic import command +from alembic.config import Config +from zope.interface import implementer + +from mailman.config import config +from mailman.core.i18n import _ +from mailman.interfaces.command import ICLISubCommand + + +@implementer(ICLISubCommand) +class Migrate: + """Migrate the mailman database to the schema.""" + + name = 'migrate' + + def add(self, parser, comman_parser): + """See `ICLISubCommand`.""" + pass + + def process(self, args): + alembic_cfg= Config() + alembic_cfg.set_main_option( + "script_location", config.alembic['script_location']) + command.upgrade(alembic_cfg, "head") + print("Updated the database schema.") diff --git a/src/mailman/config/schema.cfg b/src/mailman/config/schema.cfg index d7508a533..23382721c 100644 --- a/src/mailman/config/schema.cfg +++ b/src/mailman/config/schema.cfg @@ -640,3 +640,6 @@ rewrite_duplicate_headers: CC X-Original-CC Content-Transfer-Encoding X-Original-Content-Transfer-Encoding MIME-Version X-MIME-Version + +[alembic] +script_location: src/mailman/database/alembic diff --git a/src/mailman/database/alembic/__init__.py b/src/mailman/database/alembic/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/src/mailman/database/alembic/__init__.py diff --git a/src/mailman/database/alembic/env.py b/src/mailman/database/alembic/env.py index 68d967b7e..002b11aa1 100644 --- a/src/mailman/database/alembic/env.py +++ b/src/mailman/database/alembic/env.py @@ -18,30 +18,15 @@ from __future__ import with_statement from alembic import context +from alembic.config import Config from sqlalchemy import create_engine, pool from logging.config import fileConfig from mailman.config import config from mailman.utilities.string import expand +from mailman.database.model import Model -# this is the Alembic Config object, which provides -# access to the values within the .ini file in use. -alembic_config = context.config - -# Interpret the config file for Python logging. -# This line sets up loggers basically. -fileConfig(alembic_config.config_file_name) - -# add your model's MetaData object here -# for 'autogenerate' support -# from myapp import mymodel -# target_metadata = mymodel.Base.metadata -target_metadata = None - -# other values from the config, defined by the needs of env.py, -# can be acquired: -# my_important_option = config.get_main_option("my_important_option") -# ... etc. +target_metadata = Model.metadata def run_migrations_offline(): @@ -70,6 +55,10 @@ def run_migrations_online(): and associate a connection with the context. """ + alembic_cfg= Config() + alembic_cfg.set_main_option( + "script_location", config.alembic['script_location']) + url = expand(config.database.url, config.paths) engine = create_engine(url) connection = engine.connect() |
