summaryrefslogtreecommitdiff
path: root/src/mailman/database/schema
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman/database/schema')
-rw-r--r--src/mailman/database/schema/mm_00000000000000_base.py22
-rw-r--r--src/mailman/database/schema/mm_20120407000000.py136
-rw-r--r--src/mailman/database/schema/postgres.sql3
-rw-r--r--src/mailman/database/schema/sqlite.sql3
-rw-r--r--src/mailman/database/schema/sqlite_20120407000000_01.sql248
5 files changed, 390 insertions, 22 deletions
diff --git a/src/mailman/database/schema/mm_00000000000000_base.py b/src/mailman/database/schema/mm_00000000000000_base.py
index d703088d6..0dcd28edd 100644
--- a/src/mailman/database/schema/mm_00000000000000_base.py
+++ b/src/mailman/database/schema/mm_00000000000000_base.py
@@ -22,34 +22,14 @@ from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
'upgrade',
- 'post_reset',
- 'pre_reset',
]
-_migration_path = None
VERSION = '00000000000000'
+_helper = None
def upgrade(database, store, version, module_path):
filename = '{0}.sql'.format(database.TAG)
database.load_schema(store, version, filename, module_path)
-
-
-def pre_reset(store):
- global _migration_path
- # Save the entry in the Version table for the test suite reset. This will
- # be restored below.
- from mailman.model.version import Version
- result = store.find(Version, component=VERSION).one()
- # Yes, we abuse this field.
- _migration_path = result.version
-
-
-def post_reset(store):
- from mailman.model.version import Version
- # We need to preserve the Version table entry for this migration, since
- # its existence defines the fact that the tables have been loaded.
- store.add(Version(component='schema', version=VERSION))
- store.add(Version(component=VERSION, version=_migration_path))
diff --git a/src/mailman/database/schema/mm_20120407000000.py b/src/mailman/database/schema/mm_20120407000000.py
new file mode 100644
index 000000000..df192b2ae
--- /dev/null
+++ b/src/mailman/database/schema/mm_20120407000000.py
@@ -0,0 +1,136 @@
+# Copyright (C) 2012 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/>.
+
+"""3.0b1 -> 3.0b2 schema migrations.
+
+All column changes are in the `mailinglist` table.
+
+* Renames:
+ - news_prefix_subject_too -> nntp_prefix_subject_too
+ - news_moderation -> newsgroup_moderation
+
+* Collapsing:
+ - archive, archive_private -> archive_policy
+
+* Remove:
+ - nntp_host
+
+See https://bugs.launchpad.net/mailman/+bug/971013 for details.
+"""
+
+from __future__ import absolute_import, print_function, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+ 'upgrade',
+ ]
+
+
+from mailman.interfaces.archiver import ArchivePolicy
+
+
+VERSION = '20120407000000'
+_helper = None
+
+
+
+def upgrade(database, store, version, module_path):
+ if database.TAG == 'sqlite':
+ upgrade_sqlite(database, store, version, module_path)
+ else:
+ upgrade_postgres(database, store, version, module_path)
+
+
+
+def archive_policy(archive, archive_private):
+ """Convert archive and archive_private to archive_policy."""
+ if archive == 0:
+ return int(ArchivePolicy.never)
+ elif archive_private == 1:
+ return int(ArchivePolicy.private)
+ else:
+ return int(ArchivePolicy.public)
+
+
+
+def upgrade_sqlite(database, store, version, module_path):
+ # Load the first part of the migration. This creates a temporary table to
+ # hold the new mailinglist table columns. The problem is that some of the
+ # changes must be performed in Python, so after the first part is loaded,
+ # we do the Python changes, drop the old mailing list table, and then
+ # rename the temporary table to its place.
+ database.load_schema(
+ store, version, 'sqlite_{0}_01.sql'.format(version), module_path)
+ results = store.execute(
+ 'SELECT id, include_list_post_header, '
+ 'news_prefix_subject_too, news_moderation, '
+ 'archive, archive_private FROM mailinglist;')
+ for value in results:
+ (id, list_post,
+ news_prefix, news_moderation,
+ archive, archive_private) = value
+ # Figure out what the new archive_policy column value should be.
+ store.execute(
+ 'UPDATE ml_backup SET '
+ ' allow_list_posts = {0}, '
+ ' newsgroup_moderation = {1}, '
+ ' nntp_prefix_subject_too = {2}, '
+ ' archive_policy = {3} '
+ 'WHERE id = {4};'.format(
+ list_post,
+ news_moderation,
+ news_prefix,
+ archive_policy(archive, archive_private),
+ id))
+ store.execute('DROP TABLE mailinglist;')
+ store.execute('ALTER TABLE ml_backup RENAME TO mailinglist;')
+
+
+
+def upgrade_postgres(database, store, version, module_path):
+ # Get the old values from the mailinglist table.
+ results = store.execute(
+ 'SELECT id, archive, archive_private FROM mailinglist;')
+ # Do the simple renames first.
+ store.execute(
+ 'ALTER TABLE mailinglist '
+ ' RENAME COLUMN news_prefix_subject_too TO nntp_prefix_subject_too;')
+ store.execute(
+ 'ALTER TABLE mailinglist '
+ ' RENAME COLUMN news_moderation TO newsgroup_moderation;')
+ store.execute(
+ 'ALTER TABLE mailinglist '
+ ' RENAME COLUMN include_list_post_header TO allow_list_posts;')
+ # Do the column drop next.
+ store.execute('ALTER TABLE mailinglist DROP COLUMN nntp_host;')
+ # Now do the trickier collapsing of values. Add the new columns.
+ store.execute('ALTER TABLE mailinglist ADD COLUMN archive_policy INTEGER;')
+ # Query the database for the old values of archive and archive_private in
+ # each column. Then loop through all the results and update the new
+ # archive_policy from the old values.
+ for value in results:
+ id, archive, archive_private = value
+ store.execute('UPDATE mailinglist SET '
+ ' archive_policy = {0} '
+ 'WHERE id = {1};'.format(
+ archive_policy(archive, archive_private),
+ id))
+ # Now drop the old columns.
+ store.execute('ALTER TABLE mailinglist DROP COLUMN archive;')
+ store.execute('ALTER TABLE mailinglist DROP COLUMN archive_private;')
+ # Record the migration in the version table.
+ database.load_schema(store, version, None, module_path)
diff --git a/src/mailman/database/schema/postgres.sql b/src/mailman/database/schema/postgres.sql
index 2e9ba249f..0e97a4332 100644
--- a/src/mailman/database/schema/postgres.sql
+++ b/src/mailman/database/schema/postgres.sql
@@ -110,7 +110,8 @@ CREATE TABLE mailinglist (
topics_enabled BOOLEAN,
unsubscribe_policy INTEGER,
welcome_message_uri TEXT,
- moderation_callback TEXT,
+ -- This was accidentally added by the PostgreSQL porter.
+ -- moderation_callback TEXT,
PRIMARY KEY (id)
);
diff --git a/src/mailman/database/schema/sqlite.sql b/src/mailman/database/schema/sqlite.sql
index e6211bf53..e2b2d3814 100644
--- a/src/mailman/database/schema/sqlite.sql
+++ b/src/mailman/database/schema/sqlite.sql
@@ -1,3 +1,6 @@
+-- THIS FILE HAS BEEN FROZEN AS OF 3.0b1
+-- SEE THE SCHEMA MIGRATIONS FOR DIFFERENCES.
+
PRAGMA foreign_keys = ON;
CREATE TABLE _request (
diff --git a/src/mailman/database/schema/sqlite_20120407000000_01.sql b/src/mailman/database/schema/sqlite_20120407000000_01.sql
new file mode 100644
index 000000000..e5d3a39ff
--- /dev/null
+++ b/src/mailman/database/schema/sqlite_20120407000000_01.sql
@@ -0,0 +1,248 @@
+-- THIS FILE CONTAINS THE SQLITE3 SCHEMA MIGRATION FROM
+-- 3.0b1 TO 3.0b2
+--
+-- AFTER 3.0b2 IS RELEASED YOU MAY NOT EDIT THIS FILE.
+
+-- For SQLite3 migration strategy, see
+-- http://sqlite.org/faq.html#q11
+
+-- This is the base mailinglist table but with these changes:
+-- REM archive
+-- REM archive_private
+-- REM archive_volume_frequency
+-- REM include_list_post_header
+-- REM news_moderation
+-- REM news_prefix_subject_too
+-- REM nntp_host
+--
+-- THESE COLUMNS ARE ADDED BY THE PYTHON MIGRATION LAYER:
+-- ADD allow_list_posts
+-- ADD archive_policy
+-- ADD newsgroup_moderation
+-- ADD nntp_prefix_subject_too
+
+-- LP: #971013
+-- LP: #967238
+
+CREATE TABLE ml_backup(
+ id INTEGER NOT NULL,
+ -- List identity
+ list_name TEXT,
+ mail_host TEXT,
+ allow_list_posts BOOLEAN,
+ include_rfc2369_headers BOOLEAN,
+ -- Attributes not directly modifiable via the web u/i
+ created_at TIMESTAMP,
+ admin_member_chunksize INTEGER,
+ next_request_id INTEGER,
+ next_digest_number INTEGER,
+ digest_last_sent_at TIMESTAMP,
+ volume INTEGER,
+ last_post_at TIMESTAMP,
+ accept_these_nonmembers BLOB,
+ acceptable_aliases_id INTEGER,
+ admin_immed_notify BOOLEAN,
+ admin_notify_mchanges BOOLEAN,
+ administrivia BOOLEAN,
+ advertised BOOLEAN,
+ anonymous_list BOOLEAN,
+ -- Automatic responses.
+ autorespond_owner INTEGER,
+ autoresponse_owner_text TEXT,
+ autorespond_postings INTEGER,
+ autoresponse_postings_text TEXT,
+ autorespond_requests INTEGER,
+ autoresponse_request_text TEXT,
+ autoresponse_grace_period TEXT,
+ -- Bounces.
+ forward_unrecognized_bounces_to INTEGER,
+ process_bounces BOOLEAN,
+ bounce_info_stale_after TEXT,
+ bounce_matching_headers TEXT,
+ bounce_notify_owner_on_disable BOOLEAN,
+ bounce_notify_owner_on_removal BOOLEAN,
+ bounce_score_threshold INTEGER,
+ bounce_you_are_disabled_warnings INTEGER,
+ bounce_you_are_disabled_warnings_interval TEXT,
+ -- Content filtering.
+ filter_action INTEGER,
+ filter_content BOOLEAN,
+ collapse_alternatives BOOLEAN,
+ convert_html_to_plaintext BOOLEAN,
+ default_member_action INTEGER,
+ default_nonmember_action INTEGER,
+ description TEXT,
+ digest_footer_uri TEXT,
+ digest_header_uri TEXT,
+ digest_is_default BOOLEAN,
+ digest_send_periodic BOOLEAN,
+ digest_size_threshold FLOAT,
+ digest_volume_frequency INTEGER,
+ digestable BOOLEAN,
+ discard_these_nonmembers BLOB,
+ emergency BOOLEAN,
+ encode_ascii_prefixes BOOLEAN,
+ first_strip_reply_to BOOLEAN,
+ footer_uri TEXT,
+ forward_auto_discards BOOLEAN,
+ gateway_to_mail BOOLEAN,
+ gateway_to_news BOOLEAN,
+ generic_nonmember_action INTEGER,
+ goodbye_message_uri TEXT,
+ header_matches BLOB,
+ header_uri TEXT,
+ hold_these_nonmembers BLOB,
+ info TEXT,
+ linked_newsgroup TEXT,
+ max_days_to_hold INTEGER,
+ max_message_size INTEGER,
+ max_num_recipients INTEGER,
+ member_moderation_notice TEXT,
+ mime_is_default_digest BOOLEAN,
+ moderator_password TEXT,
+ new_member_options INTEGER,
+ nondigestable BOOLEAN,
+ nonmember_rejection_notice TEXT,
+ obscure_addresses BOOLEAN,
+ owner_chain TEXT,
+ owner_pipeline TEXT,
+ personalize INTEGER,
+ post_id INTEGER,
+ posting_chain TEXT,
+ posting_pipeline TEXT,
+ preferred_language TEXT,
+ private_roster BOOLEAN,
+ display_name TEXT,
+ reject_these_nonmembers BLOB,
+ reply_goes_to_list INTEGER,
+ reply_to_address TEXT,
+ require_explicit_destination BOOLEAN,
+ respond_to_post_requests BOOLEAN,
+ scrub_nondigest BOOLEAN,
+ send_goodbye_message BOOLEAN,
+ send_reminders BOOLEAN,
+ send_welcome_message BOOLEAN,
+ subject_prefix TEXT,
+ subscribe_auto_approval BLOB,
+ subscribe_policy INTEGER,
+ topics BLOB,
+ topics_bodylines_limit INTEGER,
+ topics_enabled BOOLEAN,
+ unsubscribe_policy INTEGER,
+ welcome_message_uri TEXT,
+ PRIMARY KEY (id)
+ );
+
+
+INSERT INTO ml_backup SELECT
+ id,
+ -- List identity
+ list_name,
+ mail_host,
+ include_list_post_header,
+ include_rfc2369_headers,
+ -- Attributes not directly modifiable via the web u/i
+ created_at,
+ admin_member_chunksize,
+ next_request_id,
+ next_digest_number,
+ digest_last_sent_at,
+ volume,
+ last_post_at,
+ accept_these_nonmembers,
+ acceptable_aliases_id,
+ admin_immed_notify,
+ admin_notify_mchanges,
+ administrivia,
+ advertised,
+ anonymous_list,
+ -- Automatic responses.
+ autorespond_owner,
+ autoresponse_owner_text,
+ autorespond_postings,
+ autoresponse_postings_text,
+ autorespond_requests,
+ autoresponse_request_text,
+ autoresponse_grace_period,
+ -- Bounces.
+ forward_unrecognized_bounces_to,
+ process_bounces,
+ bounce_info_stale_after,
+ bounce_matching_headers,
+ bounce_notify_owner_on_disable,
+ bounce_notify_owner_on_removal,
+ bounce_score_threshold,
+ bounce_you_are_disabled_warnings,
+ bounce_you_are_disabled_warnings_interval,
+ -- Content filtering.
+ filter_action,
+ filter_content,
+ collapse_alternatives,
+ convert_html_to_plaintext,
+ default_member_action,
+ default_nonmember_action,
+ description,
+ digest_footer_uri,
+ digest_header_uri,
+ digest_is_default,
+ digest_send_periodic,
+ digest_size_threshold,
+ digest_volume_frequency,
+ digestable,
+ discard_these_nonmembers,
+ emergency,
+ encode_ascii_prefixes,
+ first_strip_reply_to,
+ footer_uri,
+ forward_auto_discards,
+ gateway_to_mail,
+ gateway_to_news,
+ generic_nonmember_action,
+ goodbye_message_uri,
+ header_matches,
+ header_uri,
+ hold_these_nonmembers,
+ info,
+ linked_newsgroup,
+ max_days_to_hold,
+ max_message_size,
+ max_num_recipients,
+ member_moderation_notice,
+ mime_is_default_digest,
+ moderator_password,
+ new_member_options,
+ nondigestable,
+ nonmember_rejection_notice,
+ obscure_addresses,
+ owner_chain,
+ owner_pipeline,
+ personalize,
+ post_id,
+ posting_chain,
+ posting_pipeline,
+ preferred_language,
+ private_roster,
+ display_name,
+ reject_these_nonmembers,
+ reply_goes_to_list,
+ reply_to_address,
+ require_explicit_destination,
+ respond_to_post_requests,
+ scrub_nondigest,
+ send_goodbye_message,
+ send_reminders,
+ send_welcome_message,
+ subject_prefix,
+ subscribe_auto_approval,
+ subscribe_policy,
+ topics,
+ topics_bodylines_limit,
+ topics_enabled,
+ unsubscribe_policy,
+ welcome_message_uri
+ FROM mailinglist;
+
+-- Add the new columns. They'll get inserted at the Python layer.
+ALTER TABLE ml_backup ADD COLUMN archive_policy INTEGER;
+ALTER TABLE ml_backup ADD COLUMN nntp_prefix_subject_too INTEGER;
+ALTER TABLE ml_backup ADD COLUMN newsgroup_moderation INTEGER;