diff options
| author | Barry Warsaw | 2014-10-11 22:43:07 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2014-10-11 22:43:07 -0400 |
| commit | 24e0cf6a5971454c21145d7af319fe5e15de7839 (patch) | |
| tree | 7ae85b79078d0c2255f3c3c43e6f5a0e29135237 | |
| parent | 061799ef5031977bd343bbe54a6ad809138bdb45 (diff) | |
| download | mailman-24e0cf6a5971454c21145d7af319fe5e15de7839.tar.gz mailman-24e0cf6a5971454c21145d7af319fe5e15de7839.tar.zst mailman-24e0cf6a5971454c21145d7af319fe5e15de7839.zip | |
| -rw-r--r-- | MANIFEST.in | 5 | ||||
| -rw-r--r-- | src/mailman/commands/cli_migrate.py | 2 | ||||
| -rw-r--r-- | src/mailman/config/config.py | 4 | ||||
| -rw-r--r-- | src/mailman/database/alembic/__init__.py | 8 | ||||
| -rw-r--r-- | src/mailman/database/alembic/env.py | 3 | ||||
| -rw-r--r-- | src/mailman/database/alembic/versions/429e08420177_initial.py | 37 | ||||
| -rw-r--r-- | src/mailman/database/base.py | 1 | ||||
| -rw-r--r-- | src/mailman/database/factory.py | 77 | ||||
| -rw-r--r-- | src/mailman/testing/testing.cfg | 2 |
9 files changed, 77 insertions, 62 deletions
diff --git a/MANIFEST.in b/MANIFEST.in index c119f141e..75488eb77 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ -include *.py *.rc +include *.py *.rc *.mako include COPYING recursive-include .buildout * recursive-include contrib * @@ -6,12 +6,9 @@ recursive-include cron * recursive-include data * global-include *.txt *.rst *.po *.mo *.cfg *.sql *.zcml *.html global-exclude *.egg-info -exclude MANIFEST.in prune src/attic prune src/web prune eggs prune parts include MANIFEST.in include src/mailman/testing/config.pck -include src/mailman/databases/alembic/scripts.py.mako -include src/mailman/databases/alembic/versions/*.py diff --git a/src/mailman/commands/cli_migrate.py b/src/mailman/commands/cli_migrate.py index 82bf4a708..d51aaa209 100644 --- a/src/mailman/commands/cli_migrate.py +++ b/src/mailman/commands/cli_migrate.py @@ -28,11 +28,9 @@ __all__ = [ from alembic import command from zope.interface import implementer -from mailman.config import config from mailman.core.i18n import _ from mailman.database.alembic import alembic_cfg from mailman.interfaces.command import ICLISubCommand -from mailman.utilities.modules import expand_path diff --git a/src/mailman/config/config.py b/src/mailman/config/config.py index 0ba88e089..d8b844f65 100644 --- a/src/mailman/config/config.py +++ b/src/mailman/config/config.py @@ -87,7 +87,7 @@ class Configuration: self.pipelines = {} self.commands = {} self.password_context = None - self.initialized = False + #self.initialized = False def _clear(self): """Clear the cached configuration variables.""" @@ -137,7 +137,7 @@ class Configuration: # Expand and set up all directories. self._expand_paths() self.ensure_directories_exist() - self.initialized = True + #self.initialized = True notify(ConfigurationUpdatedEvent(self)) def _expand_paths(self): diff --git a/src/mailman/database/alembic/__init__.py b/src/mailman/database/alembic/__init__.py index 73f30832e..ffd3af6df 100644 --- a/src/mailman/database/alembic/__init__.py +++ b/src/mailman/database/alembic/__init__.py @@ -15,18 +15,18 @@ # You should have received a copy of the GNU General Public License along with # GNU Mailman. If not, see <http://www.gnu.org/licenses/>. -"Alembic config init." +"""Alembic configuration initization.""" from __future__ import absolute_import, print_function, unicode_literals __metaclass__ = type __all__ = [ - 'alembic_cfg' -] + 'alembic_cfg', + ] from alembic.config import Config from mailman.utilities.modules import expand_path -alembic_cfg=Config(expand_path("python:mailman.config.alembic")) +alembic_cfg = Config(expand_path('python:mailman.config.alembic')) diff --git a/src/mailman/database/alembic/env.py b/src/mailman/database/alembic/env.py index d1caec58d..1f4722038 100644 --- a/src/mailman/database/alembic/env.py +++ b/src/mailman/database/alembic/env.py @@ -31,16 +31,15 @@ from contextlib import closing from logging.config import fileConfig from sqlalchemy import create_engine -from mailman.core import initialize from mailman.config import config from mailman.database.alembic import alembic_cfg from mailman.database.model import Model -from mailman.utilities.modules import expand_path from mailman.utilities.string import expand fileConfig(alembic_cfg.config_file_name) + def run_migrations_offline(): """Run migrations in 'offline' mode. diff --git a/src/mailman/database/alembic/versions/429e08420177_initial.py b/src/mailman/database/alembic/versions/429e08420177_initial.py index e8d612676..14f22079b 100644 --- a/src/mailman/database/alembic/versions/429e08420177_initial.py +++ b/src/mailman/database/alembic/versions/429e08420177_initial.py @@ -1,24 +1,45 @@ -"""Initial migration +# Copyright (C) 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/>. -This empty migration file makes sure there is always an alembic_version in the -database. As a consequence, if the DB version is reported as None, it means the -database needs to be created from scratch with SQLAlchemy itself. +"""Initial migration. -It also removes the "version" table left over from Storm (if it exists). +This empty migration file makes sure there is always an alembic_version +in the database. As a consequence, if the database version is reported +as None, it means the database needs to be created from scratch with +SQLAlchemy itself. +It also removes the `version` table left over from Storm (if it exists). Revision ID: 429e08420177 Revises: None Create Date: 2014-10-02 10:18:17.333354 - """ -# revision identifiers, used by Alembic. +from __future__ import absolute_import, print_function, unicode_literals + +__metaclass__ = type +__all__ = [ + ] + +# Revision identifiers, used by Alembic. revision = '429e08420177' down_revision = None from alembic import op -import sqlalchemy as sa def upgrade(): diff --git a/src/mailman/database/base.py b/src/mailman/database/base.py index dcaedade0..2f69ed6ad 100644 --- a/src/mailman/database/base.py +++ b/src/mailman/database/base.py @@ -99,7 +99,6 @@ class SABaseDatabase: # alembic_version table. 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 469ed5d18..9cbe1088f 100644 --- a/src/mailman/database/factory.py +++ b/src/mailman/database/factory.py @@ -38,10 +38,14 @@ from zope.interface import implementer from zope.interface.verify import verifyObject from mailman.config import config -from mailman.database.model import Model from mailman.database.alembic import alembic_cfg -from mailman.interfaces.database import IDatabase, IDatabaseFactory -from mailman.utilities.modules import call_name, expand_path +from mailman.database.model import Model +from mailman.interfaces.database import ( + DatabaseError, IDatabase, IDatabaseFactory) +from mailman.utilities.modules import call_name + + +LAST_STORM_SCHEMA_VERSION = '20130406000000' @@ -57,58 +61,55 @@ class DatabaseFactory: database = call_name(database_class) verifyObject(IDatabase, database) database.initialize() - schema_mgr = SchemaManager(database) - schema_mgr.setup_db() + SchemaManager(database).setup_database() database.commit() return database class SchemaManager: - - LAST_STORM_SCHEMA_VERSION = '20130406000000' + "Manage schema migrations.""" def __init__(self, database): - self.database = database - self.alembic_cfg = alembic_cfg - self.script = ScriptDirectory.from_config(self.alembic_cfg) + self._database = database + self._script = ScriptDirectory.from_config(alembic_cfg) - def get_storm_schema_version(self): - md = MetaData() - md.reflect(bind=self.database.engine) - if "version" not in md.tables: + def _get_storm_schema_version(self): + metadata = MetaData() + metadata.reflect(bind=self._database.engine) + if 'version' not in metadata.tables: + # There are no Storm artifacts left. return None - Version = md.tables["version"] - last_version = self.database.store.query(Version.c.version).filter( - Version.c.component == "schema" - ).order_by(Version.c.version.desc()).first() + Version = metadata.tables['version'] + last_version = self._database.store.query(Version.c.version).filter( + Version.c.component == 'schema' + ).order_by(Version.c.version.desc()).first() return last_version - def setup_db(self): - context = MigrationContext.configure(self.database.store.connection()) + def setup_database(self): + context = MigrationContext.configure(self._database.store.connection()) current_rev = context.get_current_revision() - head_rev = self.script.get_current_head() + head_rev = self._script.get_current_head() if current_rev == head_rev: - return head_rev # already at the latest revision, nothing to do - if current_rev == None: - # no alembic information - storm_version = self.get_storm_schema_version() + # We're already at the latest revision so there's nothing to do. + return head_rev + if current_rev is None: + # No Alembic information is available. + storm_version = self._get_storm_schema_version() if storm_version is None: - # initial DB creation - Model.metadata.create_all(self.database.engine) - command.stamp(self.alembic_cfg, "head") + # Initial database creation. + Model.metadata.create_all(self._database.engine) + command.stamp(alembic_cfg, 'head') else: - # DB from a previous version managed by Storm - if storm_version.version < self.LAST_STORM_SCHEMA_VERSION: - raise RuntimeError( - "Upgrading while skipping beta version is " - "unsupported, please install the previous " - "Mailman beta release") - # Run migrations to remove the Storm-specific table and - # upgrade to SQLAlchemy & Alembic - command.upgrade(self.alembic_cfg, "head") + # The database was previously managed by Storm. + if storm_version.version < LAST_STORM_SCHEMA_VERSION: + raise DatabaseError( + 'Upgrades skipping beta versions is not supported.') + # Run migrations to remove the Storm-specific table and upgrade + # to SQLAlchemy and Alembic. + command.upgrade(alembic_cfg, 'head') elif current_rev != head_rev: - command.upgrade(self.alembic_cfg, "head") + command.upgrade(alembic_cfg, 'head') return head_rev diff --git a/src/mailman/testing/testing.cfg b/src/mailman/testing/testing.cfg index 39d1d922a..eba10dd3b 100644 --- a/src/mailman/testing/testing.cfg +++ b/src/mailman/testing/testing.cfg @@ -20,7 +20,7 @@ # For testing against PostgreSQL. # [database] # class: mailman.database.postgresql.PostgreSQLDatabase -# url: postgres://maxking:maxking@localhost/mailman_test +# url: postgres://$USER:$USER@localhost/mailman_test [mailman] site_owner: noreply@example.com |
