From 8ac1f1e9010bb1a3c4b1a0890824b9efa3ab737b Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Thu, 2 Oct 2014 00:15:36 -0400 Subject: Fix the test suite. * Fix a couple of typos. * Make the script_location and alembic_scripts a resource paths. --- src/mailman/commands/cli_migrate.py | 2 +- src/mailman/config/alembic.cfg | 57 +++++++++++++++++++++++++++++++++++++ src/mailman/config/alembic.ini | 57 ------------------------------------- src/mailman/config/schema.cfg | 2 +- src/mailman/database/base.py | 2 +- 5 files changed, 60 insertions(+), 60 deletions(-) create mode 100644 src/mailman/config/alembic.cfg delete mode 100644 src/mailman/config/alembic.ini diff --git a/src/mailman/commands/cli_migrate.py b/src/mailman/commands/cli_migrate.py index 8783b5c46..ca9d5e9d4 100644 --- a/src/mailman/commands/cli_migrate.py +++ b/src/mailman/commands/cli_migrate.py @@ -48,7 +48,7 @@ class Migrate: '-a', '--autogenerate', action='store_true', help=_("""\ Autogenerate the migration script using Alembic.""")) - command.parser_add_argument( + command_parser.add_argument( '-q', '--quiet', action='store_true', default=False, help=('Produce less output.')) diff --git a/src/mailman/config/alembic.cfg b/src/mailman/config/alembic.cfg new file mode 100644 index 000000000..46ac90b61 --- /dev/null +++ b/src/mailman/config/alembic.cfg @@ -0,0 +1,57 @@ +# A generic, single database configuration. + +[alembic] +# path to migration scripts +script_location = mailman.database:alembic + +# template used to generate migration files +# file_template = %%(rev)s_%%(slug)s + +# max length of characters to apply to the +# "slug" field +#truncate_slug_length = 40 + +# set to 'true' to run the environment during +# the 'revision' command, regardless of autogenerate +# revision_environment = false + +# set to 'true' to allow .pyc and .pyo files without +# a source .py file to be detected as revisions in the +# versions/ directory +# sourceless = false + + +# Logging configuration +[loggers] +keys = root,sqlalchemy,alembic + +[handlers] +keys = console + +[formatters] +keys = generic + +[logger_root] +level = WARN +handlers = console +qualname = + +[logger_sqlalchemy] +level = WARN +handlers = +qualname = sqlalchemy.engine + +[logger_alembic] +level = INFO +handlers = +qualname = alembic + +[handler_console] +class = StreamHandler +args = (sys.stderr,) +level = NOTSET +formatter = generic + +[formatter_generic] +format = %(levelname)-5.5s [%(name)s] %(message)s +datefmt = %H:%M:%S diff --git a/src/mailman/config/alembic.ini b/src/mailman/config/alembic.ini deleted file mode 100644 index a7247743c..000000000 --- a/src/mailman/config/alembic.ini +++ /dev/null @@ -1,57 +0,0 @@ -# A generic, single database configuration. - -[alembic] -# path to migration scripts -script_location = src/mailman/database/alembic - -# template used to generate migration files -# file_template = %%(rev)s_%%(slug)s - -# max length of characters to apply to the -# "slug" field -#truncate_slug_length = 40 - -# set to 'true' to run the environment during -# the 'revision' command, regardless of autogenerate -# revision_environment = false - -# set to 'true' to allow .pyc and .pyo files without -# a source .py file to be detected as revisions in the -# versions/ directory -# sourceless = false - - -# Logging configuration -[loggers] -keys = root,sqlalchemy,alembic - -[handlers] -keys = console - -[formatters] -keys = generic - -[logger_root] -level = WARN -handlers = console -qualname = - -[logger_sqlalchemy] -level = WARN -handlers = -qualname = sqlalchemy.engine - -[logger_alembic] -level = INFO -handlers = -qualname = alembic - -[handler_console] -class = StreamHandler -args = (sys.stderr,) -level = NOTSET -formatter = generic - -[formatter_generic] -format = %(levelname)-5.5s [%(name)s] %(message)s -datefmt = %H:%M:%S diff --git a/src/mailman/config/schema.cfg b/src/mailman/config/schema.cfg index f66c0b5b5..e8f89ab41 100644 --- a/src/mailman/config/schema.cfg +++ b/src/mailman/config/schema.cfg @@ -206,7 +206,7 @@ debug: no # Where can we find the Alembic migration scripts? The `python:` schema means # that this is a module path relative to the Mailman 3 source installation. -alembic_scripts: python:mailman.database.alembic +alembic_scripts: mailman.database:alembic [logging.template] diff --git a/src/mailman/database/base.py b/src/mailman/database/base.py index e49d512c0..4c418c289 100644 --- a/src/mailman/database/base.py +++ b/src/mailman/database/base.py @@ -100,7 +100,7 @@ class SABaseDatabase: # alembic_version table. alembic_cfg = Config() alembic_cfg.set_main_option( - 'script_location', expand_path(config.database['alembic_scripts'])) + 'script_location', config.database['alembic_scripts']) command.stamp(alembic_cfg, 'head') -- cgit v1.2.3-70-g09d2 From 5166ae93e5c51285661f4ac251c0d4b9390fe785 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Thu, 2 Oct 2014 00:22:39 -0400 Subject: Remove an unused import. --- src/mailman/database/base.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mailman/database/base.py b/src/mailman/database/base.py index 4c418c289..26b6ddbbb 100644 --- a/src/mailman/database/base.py +++ b/src/mailman/database/base.py @@ -34,7 +34,6 @@ from zope.interface import implementer from mailman.config import config from mailman.interfaces.database import IDatabase from mailman.utilities.string import expand -from mailman.utilities.modules import expand_path log = logging.getLogger('mailman.config') -- cgit v1.2.3-70-g09d2 From 061799ef5031977bd343bbe54a6ad809138bdb45 Mon Sep 17 00:00:00 2001 From: Abhilash Raj Date: Fri, 3 Oct 2014 21:56:50 +0530 Subject: add central alembic config --- src/mailman/commands/cli_migrate.py | 5 +---- src/mailman/config/alembic.cfg | 8 ++++---- src/mailman/database/alembic/__init__.py | 32 ++++++++++++++++++++++++++++++++ src/mailman/database/alembic/env.py | 17 ++++------------- src/mailman/database/base.py | 5 +---- src/mailman/database/factory.py | 8 +++----- src/mailman/testing/testing.cfg | 2 +- 7 files changed, 46 insertions(+), 31 deletions(-) diff --git a/src/mailman/commands/cli_migrate.py b/src/mailman/commands/cli_migrate.py index ca9d5e9d4..82bf4a708 100644 --- a/src/mailman/commands/cli_migrate.py +++ b/src/mailman/commands/cli_migrate.py @@ -26,11 +26,11 @@ __all__ = [ 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.database.alembic import alembic_cfg from mailman.interfaces.command import ICLISubCommand from mailman.utilities.modules import expand_path @@ -54,9 +54,6 @@ class Migrate: help=('Produce less output.')) def process(self, args): - alembic_cfg = Config() - alembic_cfg.set_main_option( - 'script_location', expand_path(config.database['alembic_scripts'])) if args.autogenerate: command.revision(alembic_cfg, autogenerate=True) else: diff --git a/src/mailman/config/alembic.cfg b/src/mailman/config/alembic.cfg index 46ac90b61..b1f53a3d2 100644 --- a/src/mailman/config/alembic.cfg +++ b/src/mailman/config/alembic.cfg @@ -38,18 +38,18 @@ qualname = [logger_sqlalchemy] level = WARN -handlers = +handlers = console qualname = sqlalchemy.engine [logger_alembic] -level = INFO -handlers = +level = WARN +handlers = console qualname = alembic [handler_console] class = StreamHandler args = (sys.stderr,) -level = NOTSET +level = WARN formatter = generic [formatter_generic] diff --git a/src/mailman/database/alembic/__init__.py b/src/mailman/database/alembic/__init__.py index e69de29bb..73f30832e 100644 --- a/src/mailman/database/alembic/__init__.py +++ b/src/mailman/database/alembic/__init__.py @@ -0,0 +1,32 @@ +# 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 . + +"Alembic config init." + +from __future__ import absolute_import, print_function, unicode_literals + +__metaclass__ = type +__all__ = [ + 'alembic_cfg' +] + + +from alembic.config import Config +from mailman.utilities.modules import expand_path + + +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 5e4f6bfdb..d1caec58d 100644 --- a/src/mailman/database/alembic/env.py +++ b/src/mailman/database/alembic/env.py @@ -27,17 +27,20 @@ __all__ = [ from alembic import context -from alembic.config import Config 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. @@ -49,11 +52,6 @@ def run_migrations_offline(): Calls to context.execute() here emit the given string to the script output. """ - if not config.initialized: - initialize.initialize_1(context.config.config_file_name) - alembic_cfg= Config() - alembic_cfg.set_main_option( - "script_location", config.alembic['script_location']) url = expand(config.database.url, config.paths) context.configure(url=url, target_metadata=Model.metadata) with context.begin_transaction(): @@ -66,13 +64,6 @@ def run_migrations_online(): In this scenario we need to create an Engine and associate a connection with the context. """ - - if not config.initialized: - initialize.initialize_1(context.config.config_file_name) - alembic_cfg = Config() - alembic_cfg.set_main_option( - 'script_location', expand_path(config.database['alembic_scripts'])) - 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 26b6ddbbb..dcaedade0 100644 --- a/src/mailman/database/base.py +++ b/src/mailman/database/base.py @@ -26,12 +26,12 @@ __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 from mailman.config import config +from mailman.database.alembic import alembic_cfg from mailman.interfaces.database import IDatabase from mailman.utilities.string import expand @@ -97,9 +97,6 @@ class SABaseDatabase: # create_all() ceates the latest schema. This patches the database # with the latest Alembic version to add an entry in the # alembic_version table. - alembic_cfg = Config() - alembic_cfg.set_main_option( - 'script_location', config.database['alembic_scripts']) command.stamp(alembic_cfg, 'head') diff --git a/src/mailman/database/factory.py b/src/mailman/database/factory.py index 6111be8c5..469ed5d18 100644 --- a/src/mailman/database/factory.py +++ b/src/mailman/database/factory.py @@ -30,7 +30,6 @@ import os import types from alembic import command -from alembic.config import Config as AlembicConfig from alembic.migration import MigrationContext from alembic.script import ScriptDirectory from flufl.lock import Lock @@ -40,8 +39,9 @@ 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 +from mailman.utilities.modules import call_name, expand_path @@ -70,9 +70,7 @@ class SchemaManager: def __init__(self, database): self.database = database - self.alembic_cfg = AlembicConfig() - self.alembic_cfg.set_main_option( - "script_location", config.alembic['script_location']) + self.alembic_cfg = alembic_cfg self.script = ScriptDirectory.from_config(self.alembic_cfg) def get_storm_schema_version(self): diff --git a/src/mailman/testing/testing.cfg b/src/mailman/testing/testing.cfg index fc76aa361..39d1d922a 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://barry:barry@localhost/mailman +# url: postgres://maxking:maxking@localhost/mailman_test [mailman] site_owner: noreply@example.com -- cgit v1.2.3-70-g09d2