summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mailman/commands/cli_migrate.py62
-rw-r--r--src/mailman/commands/docs/conf.rst2
-rw-r--r--src/mailman/config/alembic.cfg21
-rw-r--r--src/mailman/config/schema.cfg5
-rw-r--r--src/mailman/database/alembic/__init__.py2
-rw-r--r--src/mailman/database/alembic/env.py4
-rw-r--r--src/mailman/database/alembic/versions/429e08420177_initial.py29
-rw-r--r--src/mailman/database/alembic/versions/51b7f92bd06c_initial.py32
-rw-r--r--src/mailman/model/address.py4
-rw-r--r--src/mailman/model/autorespond.py6
-rw-r--r--src/mailman/model/language.py4
-rw-r--r--src/mailman/model/mailinglist.py12
-rw-r--r--src/mailman/model/mime.py2
-rw-r--r--src/mailman/model/pending.py2
-rw-r--r--src/mailman/model/requests.py4
-rw-r--r--src/mailman/model/uid.py2
-rw-r--r--src/mailman/model/user.py9
-rw-r--r--src/mailman/testing/testing.cfg6
18 files changed, 70 insertions, 138 deletions
diff --git a/src/mailman/commands/cli_migrate.py b/src/mailman/commands/cli_migrate.py
deleted file mode 100644
index 82bf4a708..000000000
--- a/src/mailman/commands/cli_migrate.py
+++ /dev/null
@@ -1,62 +0,0 @@
-# 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 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
-
-
-
-@implementer(ICLISubCommand)
-class Migrate:
- """Migrate the Mailman database to the latest schema."""
-
- name = 'migrate'
-
- def add(self, parser, command_parser):
- """See `ICLISubCommand`."""
- command_parser.add_argument(
- '-a', '--autogenerate',
- action='store_true', help=_("""\
- Autogenerate the migration script using Alembic."""))
- command_parser.add_argument(
- '-q', '--quiet',
- action='store_true', default=False,
- help=('Produce less output.'))
-
- def process(self, args):
- if args.autogenerate:
- command.revision(alembic_cfg, autogenerate=True)
- else:
- command.upgrade(alembic_cfg, 'head')
- if not args.quiet:
- print('Updated the database schema.')
diff --git a/src/mailman/commands/docs/conf.rst b/src/mailman/commands/docs/conf.rst
index b3fef9db7..fb4c3eeed 100644
--- a/src/mailman/commands/docs/conf.rst
+++ b/src/mailman/commands/docs/conf.rst
@@ -22,7 +22,7 @@ To get a list of all key-value pairs of any section, you need to call the
command without any options.
>>> command.process(FakeArgs)
- [logging.dbmigration] path: mailman.log
+ [alembic] script_location: mailman.database:alembic
...
[passwords] password_length: 8
...
diff --git a/src/mailman/config/alembic.cfg b/src/mailman/config/alembic.cfg
deleted file mode 100644
index 78c047379..000000000
--- a/src/mailman/config/alembic.cfg
+++ /dev/null
@@ -1,21 +0,0 @@
-# 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
diff --git a/src/mailman/config/schema.cfg b/src/mailman/config/schema.cfg
index 139963788..3e628fa47 100644
--- a/src/mailman/config/schema.cfg
+++ b/src/mailman/config/schema.cfg
@@ -204,7 +204,6 @@ class: mailman.database.sqlite.SQLiteDatabase
url: sqlite:///$DATA_DIR/mailman.db
debug: no
-
[logging.template]
# This defines various log settings. The options available are:
#
@@ -646,3 +645,7 @@ rewrite_duplicate_headers:
CC X-Original-CC
Content-Transfer-Encoding X-Original-Content-Transfer-Encoding
MIME-Version X-MIME-Version
+
+[alembic]
+# path to migration scripts
+script_location = mailman.database:alembic
diff --git a/src/mailman/database/alembic/__init__.py b/src/mailman/database/alembic/__init__.py
index 73f30832e..a2f7418ba 100644
--- a/src/mailman/database/alembic/__init__.py
+++ b/src/mailman/database/alembic/__init__.py
@@ -29,4 +29,4 @@ 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.schema"))
diff --git a/src/mailman/database/alembic/env.py b/src/mailman/database/alembic/env.py
index ffab0fed8..d1a1c557c 100644
--- a/src/mailman/database/alembic/env.py
+++ b/src/mailman/database/alembic/env.py
@@ -34,9 +34,11 @@ 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
+if not config.initialized:
+ initialize.initialize_1(context.config.config_file_name)
+
def run_migrations_offline():
diff --git a/src/mailman/database/alembic/versions/429e08420177_initial.py b/src/mailman/database/alembic/versions/429e08420177_initial.py
deleted file mode 100644
index e8d612676..000000000
--- a/src/mailman/database/alembic/versions/429e08420177_initial.py
+++ /dev/null
@@ -1,29 +0,0 @@
-"""Initial migration
-
-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.
-
-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.
-revision = '429e08420177'
-down_revision = None
-
-from alembic import op
-import sqlalchemy as sa
-
-
-def upgrade():
- op.drop_table('version')
-
-
-def downgrade():
- pass
diff --git a/src/mailman/database/alembic/versions/51b7f92bd06c_initial.py b/src/mailman/database/alembic/versions/51b7f92bd06c_initial.py
new file mode 100644
index 000000000..c5b3e01c5
--- /dev/null
+++ b/src/mailman/database/alembic/versions/51b7f92bd06c_initial.py
@@ -0,0 +1,32 @@
+"""initial
+
+Revision ID: 51b7f92bd06c
+Revises: None
+Create Date: 2014-10-10 09:53:35.624472
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '51b7f92bd06c'
+down_revision = None
+
+from alembic import op
+import sqlalchemy as sa
+
+
+def upgrade():
+ ### commands auto generated by Alembic - please adjust! ###
+ op.drop_table('version')
+ op.drop_column('mailinglist', 'acceptable_aliases_id')
+ op.create_index(op.f('ix_user__user_id'), 'user', ['_user_id'], unique=False)
+ op.drop_index('ix_user_user_id', table_name='user')
+ ### end Alembic commands ###
+
+
+def downgrade():
+ ### commands auto generated by Alembic - please adjust! ###
+ op.create_table('version')
+ op.create_index('ix_user_user_id', 'user', ['_user_id'], unique=False)
+ op.drop_index(op.f('ix_user__user_id'), table_name='user')
+ op.add_column('mailinglist', sa.Column('acceptable_aliases_id', sa.INTEGER(), nullable=True))
+ ### end Alembic commands ###
diff --git a/src/mailman/model/address.py b/src/mailman/model/address.py
index 20bd631f5..cc4ab6fd0 100644
--- a/src/mailman/model/address.py
+++ b/src/mailman/model/address.py
@@ -53,9 +53,9 @@ class Address(Model):
_verified_on = Column('verified_on', DateTime)
registered_on = Column(DateTime)
- user_id = Column(Integer, ForeignKey('user.id'))
+ user_id = Column(Integer, ForeignKey('user.id'), index=True)
- preferences_id = Column(Integer, ForeignKey('preferences.id'))
+ preferences_id = Column(Integer, ForeignKey('preferences.id'), index=True)
preferences = relationship(
'Preferences', backref=backref('address', uselist=False))
diff --git a/src/mailman/model/autorespond.py b/src/mailman/model/autorespond.py
index c74434f7b..2293f5dcd 100644
--- a/src/mailman/model/autorespond.py
+++ b/src/mailman/model/autorespond.py
@@ -44,14 +44,14 @@ from mailman.utilities.datetime import today
class AutoResponseRecord(Model):
"""See `IAutoResponseRecord`."""
- __tablename__ = 'autorespondrecord'
+ __tablename__ = 'autoresponserecord'
id = Column(Integer, primary_key=True)
- address_id = Column(Integer, ForeignKey('address.id'))
+ address_id = Column(Integer, ForeignKey('address.id'), index=True)
address = relationship('Address')
- mailing_list_id = Column(Integer, ForeignKey('mailinglist.id'))
+ mailing_list_id = Column(Integer, ForeignKey('mailinglist.id'), index=True)
mailing_list = relationship('MailingList')
response_type = Column(Enum(Response))
diff --git a/src/mailman/model/language.py b/src/mailman/model/language.py
index 15450c936..f4d48fc97 100644
--- a/src/mailman/model/language.py
+++ b/src/mailman/model/language.py
@@ -28,8 +28,8 @@ __all__ = [
from sqlalchemy import Column, Integer, Unicode
from zope.interface import implementer
-from mailman.database import Model
-from mailman.interfaces import ILanguage
+from mailman.database.model import Model
+from mailman.interfaces.languages import ILanguage
diff --git a/src/mailman/model/mailinglist.py b/src/mailman/model/mailinglist.py
index d00cf3d31..fe84ff5b5 100644
--- a/src/mailman/model/mailinglist.py
+++ b/src/mailman/model/mailinglist.py
@@ -504,9 +504,12 @@ class AcceptableAlias(Model):
id = Column(Integer, primary_key=True)
- mailing_list_id = Column(Integer, ForeignKey('mailinglist.id'))
+ mailing_list_id = Column(Integer,
+ ForeignKey('mailinglist.id'),
+ index=True,
+ nullable=False)
mailing_list = relationship('MailingList', backref='acceptable_alias')
- alias = Column(Unicode)
+ alias = Column(Unicode, index=True, nullable=False)
def __init__(self, mailing_list, alias):
self.mailing_list = mailing_list
@@ -558,9 +561,10 @@ class ListArchiver(Model):
id = Column(Integer, primary_key=True)
- mailing_list_id = Column(Integer, ForeignKey('mailinglist.id'))
+ mailing_list_id = Column(Integer, ForeignKey('mailinglist.id'),
+ index=True, nullable=False)
mailing_list = relationship('MailingList')
- name = Column(Unicode)
+ name = Column(Unicode, nullable=False)
_is_enabled = Column(Boolean)
def __init__(self, mailing_list, archiver_name, system_archiver):
diff --git a/src/mailman/model/mime.py b/src/mailman/model/mime.py
index 906af91ea..dc6a54437 100644
--- a/src/mailman/model/mime.py
+++ b/src/mailman/model/mime.py
@@ -43,7 +43,7 @@ class ContentFilter(Model):
id = Column(Integer, primary_key=True)
- mailing_list_id = Column(Integer, ForeignKey('mailinglist.id'))
+ mailing_list_id = Column(Integer, ForeignKey('mailinglist.id'), index=True)
mailing_list = relationship('MailingList')
filter_type = Column(Enum(FilterType))
diff --git a/src/mailman/model/pending.py b/src/mailman/model/pending.py
index 691e94fd9..49b12c16a 100644
--- a/src/mailman/model/pending.py
+++ b/src/mailman/model/pending.py
@@ -56,7 +56,7 @@ class PendedKeyValue(Model):
id = Column(Integer, primary_key=True)
key = Column(Unicode)
value = Column(Unicode)
- pended_id = Column(Integer, ForeignKey('pended.id'))
+ pended_id = Column(Integer, ForeignKey('pended.id'), index=True)
def __init__(self, key, value):
self.key = key
diff --git a/src/mailman/model/requests.py b/src/mailman/model/requests.py
index 7f996dded..6b130196d 100644
--- a/src/mailman/model/requests.py
+++ b/src/mailman/model/requests.py
@@ -149,14 +149,14 @@ class ListRequests:
class _Request(Model):
"""Table for mailing list hold requests."""
- __tablename__ = 'request'
+ __tablename__ = '_request'
id = Column(Integer, primary_key=True)
key = Column(Unicode)
request_type = Column(Enum(RequestType))
data_hash = Column(LargeBinary)
- mailing_list_id = Column(Integer, ForeignKey('mailinglist.id'))
+ mailing_list_id = Column(Integer, ForeignKey('mailinglist.id'), index=True)
mailing_list = relationship('MailingList')
def __init__(self, key, request_type, mailing_list, data_hash):
diff --git a/src/mailman/model/uid.py b/src/mailman/model/uid.py
index 29d8e7021..72ddd7b5a 100644
--- a/src/mailman/model/uid.py
+++ b/src/mailman/model/uid.py
@@ -50,7 +50,7 @@ class UID(Model):
__tablename__ = 'uid'
id = Column(Integer, primary_key=True)
- uid = Column(UUID)
+ uid = Column(UUID, index=True)
@dbconnection
def __init__(self, store, uid):
diff --git a/src/mailman/model/user.py b/src/mailman/model/user.py
index 576015dbe..5fe61ddd4 100644
--- a/src/mailman/model/user.py
+++ b/src/mailman/model/user.py
@@ -57,7 +57,7 @@ class User(Model):
id = Column(Integer, primary_key=True)
display_name = Column(Unicode)
_password = Column('password', LargeBinary) # TODO : was RawStr()
- _user_id = Column(UUID)
+ _user_id = Column(UUID, index=True)
_created_on = Column(DateTime)
addresses = relationship(
@@ -66,12 +66,15 @@ class User(Model):
_preferred_address_id = Column(
Integer,
- ForeignKey('address.id', use_alter=True, name='_preferred_address'))
+ ForeignKey('address.id', use_alter=True,
+ name='_preferred_address',
+ ondelete="SET NULL"))
+
_preferred_address = relationship(
'Address', primaryjoin=(_preferred_address_id==Address.id),
post_update=True)
- preferences_id = Column(Integer, ForeignKey('preferences.id'))
+ preferences_id = Column(Integer, ForeignKey('preferences.id'), index=True)
preferences = relationship(
'Preferences', backref=backref('user', uselist=False))
diff --git a/src/mailman/testing/testing.cfg b/src/mailman/testing/testing.cfg
index eb9de5513..ea2df6988 100644
--- a/src/mailman/testing/testing.cfg
+++ b/src/mailman/testing/testing.cfg
@@ -18,9 +18,9 @@
# A testing configuration.
# For testing against PostgreSQL.
-[database]
-class: mailman.database.postgresql.PostgreSQLDatabase
-url: postgresql://maxking:maxking@localhost/mailman_test
+# [database]
+# class: mailman.database.postgresql.PostgreSQLDatabase
+# url: postgresql://maxking:maxking@localhost/mailman_test
[mailman]
site_owner: noreply@example.com