summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAbhilash Raj2014-10-03 21:56:50 +0530
committerAbhilash Raj2014-10-03 21:56:50 +0530
commit061799ef5031977bd343bbe54a6ad809138bdb45 (patch)
tree81c77ecf3e3acbdbac99a01c31342256c25e5bf9 /src
parent6d4af22c8ee51e1b097ec0370cadd3f5a6b95c08 (diff)
downloadmailman-061799ef5031977bd343bbe54a6ad809138bdb45.tar.gz
mailman-061799ef5031977bd343bbe54a6ad809138bdb45.tar.zst
mailman-061799ef5031977bd343bbe54a6ad809138bdb45.zip
Diffstat (limited to 'src')
-rw-r--r--src/mailman/commands/cli_migrate.py5
-rw-r--r--src/mailman/config/alembic.cfg8
-rw-r--r--src/mailman/database/alembic/__init__.py32
-rw-r--r--src/mailman/database/alembic/env.py17
-rw-r--r--src/mailman/database/base.py5
-rw-r--r--src/mailman/database/factory.py8
-rw-r--r--src/mailman/testing/testing.cfg2
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 <http://www.gnu.org/licenses/>.
+
+"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