diff options
| author | Barry Warsaw | 2012-09-04 22:25:49 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2012-09-04 22:25:49 -0400 |
| commit | 952cd3770fe4db4786efcc7c90d72dfa9aa74e68 (patch) | |
| tree | 17e850760dcb5e1a4a685d9ecc903550771df605 /src | |
| parent | 5d42a53f1166ecaf98be69954894795c44a803a8 (diff) | |
| download | mailman-952cd3770fe4db4786efcc7c90d72dfa9aa74e68.tar.gz mailman-952cd3770fe4db4786efcc7c90d72dfa9aa74e68.tar.zst mailman-952cd3770fe4db4786efcc7c90d72dfa9aa74e68.zip | |
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/database/schema/mm_20120407000000.py | 10 | ||||
| -rw-r--r-- | src/mailman/database/schema/sqlite_20120407000000_01.sql | 38 | ||||
| -rw-r--r-- | src/mailman/database/tests/test_migrations.py | 21 | ||||
| -rw-r--r-- | src/mailman/docs/NEWS.rst | 16 | ||||
| -rw-r--r-- | src/mailman/model/member.py | 2 |
5 files changed, 76 insertions, 11 deletions
diff --git a/src/mailman/database/schema/mm_20120407000000.py b/src/mailman/database/schema/mm_20120407000000.py index f6dd60be5..f351d60ca 100644 --- a/src/mailman/database/schema/mm_20120407000000.py +++ b/src/mailman/database/schema/mm_20120407000000.py @@ -128,6 +128,16 @@ def upgrade_sqlite(database, store, version, module_path): store.execute( 'CREATE INDEX ix_mailinglist_fqdn_listname ' 'ON mailinglist (list_name, mail_host);') + # Now, do the member table. + results = store.execute('SELECT id, mailing_list FROM member;') + for id, mailing_list in results: + store.execute(""" + UPDATE mem_backup SET list_id = '{0}' + WHERE id = {1}; + """.format(list_id, id)) + # Pivot the backup table to the real thing. + store.execute('DROP TABLE member;') + store.execute('ALTER TABLE mem_backup RENAME TO member;') diff --git a/src/mailman/database/schema/sqlite_20120407000000_01.sql b/src/mailman/database/schema/sqlite_20120407000000_01.sql index c0e752d68..b93e214c4 100644 --- a/src/mailman/database/schema/sqlite_20120407000000_01.sql +++ b/src/mailman/database/schema/sqlite_20120407000000_01.sql @@ -6,7 +6,7 @@ -- For SQLite3 migration strategy, see -- http://sqlite.org/faq.html#q11 --- This is the base mailinglist table but with these changes: +-- REMOVALS from the mailinglist table. -- REM archive -- REM archive_private -- REM archive_volume_frequency @@ -15,7 +15,7 @@ -- REM news_prefix_subject_too -- REM nntp_host -- --- THESE COLUMNS ARE ADDED BY THE PYTHON MIGRATION LAYER: +-- ADDS to the mailing list table. -- ADD allow_list_posts -- ADD archive_policy -- ADD list_id @@ -25,6 +25,15 @@ -- LP: #971013 -- LP: #967238 +-- REMOVALS from the member table. +-- REM mailing_list + +-- ADDS to the member table. +-- ADD list_id + +-- LP: #1024509 + + CREATE TABLE ml_backup( id INTEGER NOT NULL, -- List identity @@ -133,7 +142,6 @@ CREATE TABLE ml_backup( PRIMARY KEY (id) ); - INSERT INTO ml_backup SELECT id, -- List identity @@ -241,8 +249,32 @@ INSERT INTO ml_backup SELECT welcome_message_uri FROM mailinglist; +CREATE TABLE mem_backup( + id INTEGER NOT NULL, + _member_id TEXT, + role INTEGER, + moderation_action INTEGER, + address_id INTEGER, + preferences_id INTEGER, + user_id INTEGER, + PRIMARY KEY (id) + ); + +INSERT INTO mem_backup SELECT + id, + _member_id, + role, + moderation_action, + address_id, + preferences_id, + user_id + FROM member; + + -- 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 list_id TEXT; ALTER TABLE ml_backup ADD COLUMN nntp_prefix_subject_too INTEGER; ALTER TABLE ml_backup ADD COLUMN newsgroup_moderation INTEGER; + +ALTER TABLE mem_backup ADD COLUMN list_id TEXT; diff --git a/src/mailman/database/tests/test_migrations.py b/src/mailman/database/tests/test_migrations.py index 4ad709c16..8df50f40e 100644 --- a/src/mailman/database/tests/test_migrations.py +++ b/src/mailman/database/tests/test_migrations.py @@ -39,6 +39,7 @@ from mailman.interfaces.archiver import ArchivePolicy from mailman.interfaces.listmanager import IListManager from mailman.interfaces.mailinglist import IAcceptableAliasSet from mailman.interfaces.nntp import NewsgroupModeration +from mailman.interfaces.subscriptions import ISubscriptionService from mailman.testing.helpers import temporary_db from mailman.testing.layers import ConfigLayer @@ -59,6 +60,9 @@ class MigrationTestBase(unittest.TestCase): * REMOVE archive_private * REMOVE archive_volume_frequency * REMOVE nntp_host + + table member: + * mailing_list -> list_id """ layer = ConfigLayer @@ -90,6 +94,9 @@ class TestMigration20120407Schema(MigrationTestBase): self._database.store.execute, 'select {0} from mailinglist;'.format(missing)) self._database.store.rollback() + self.assertRaises(DatabaseError, + self._database.store.execute, + 'select list_id from member;') for present in ('archive', 'archive_private', 'archive_volume_frequency', @@ -102,6 +109,8 @@ class TestMigration20120407Schema(MigrationTestBase): # that we can perform? self._database.store.execute( 'select {0} from mailinglist;'.format(present)) + # Again, this should not produce an exception. + self._database.store.execute('select mailing_list from member;') def test_post_upgrade_columns_migration(self): # Test that after the migration, the old table columns are missing @@ -119,6 +128,7 @@ class TestMigration20120407Schema(MigrationTestBase): # that we can perform? self._database.store.execute( 'select {0} from mailinglist;'.format(present)) + self._database.store.execute('select list_id from member;') for missing in ('archive', 'archive_private', 'archive_volume_frequency', @@ -131,6 +141,9 @@ class TestMigration20120407Schema(MigrationTestBase): self._database.store.execute, 'select {0} from mailinglist;'.format(missing)) self._database.store.rollback() + self.assertRaises(DatabaseError, + self._database.store.execute, + 'select mailing_list from member;') @@ -273,6 +286,14 @@ class TestMigration20120407MigratedData(MigrationTestBase): mlist = getUtility(IListManager).get('test@example.com') self.assertEqual(mlist.list_id, 'test.example.com') + def test_list_id_member(self): + # Test that the member table's mailing_list column becomes list_id. + self._upgrade() + with temporary_db(self._database): + service = getUtility(ISubscriptionService) + members = list(service.find_members(list_id='test.example.com')) + self.assertEqual(len(members), 4) + def test_news_moderation_none(self): # Test that news_moderation becomes newsgroup_moderation. self._database.store.execute( diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst index 94105c65c..06e0afa1d 100644 --- a/src/mailman/docs/NEWS.rst +++ b/src/mailman/docs/NEWS.rst @@ -72,13 +72,15 @@ Architecture Database -------- * Schema migrations (LP: #971013) - - include_list_post_header -> allow_list_posts - - news_prefix_subject_too -> nntp_prefix_subject_too - - news_moderation -> newsgroup_moderation - - archive and archive_private have been collapsed into archive_policy. - - nntp_host has been removed. - - generic_nonmember_action has been removed (LP: #975696) - - list_id added (LP: #1024509) + - mailinglist.include_list_post_header -> allow_list_posts + - mailinglist.news_prefix_subject_too -> nntp_prefix_subject_too + - mailinglist.news_moderation -> newsgroup_moderation + - mailinglist.archive and mailinglist.archive_private have been collapsed + into archive_policy. + - mailinglist.nntp_host has been removed. + - mailinglist.generic_nonmember_action has been removed (LP: #975696) + * Schema migrations (LP: #1024509) + - member.mailing_list -> list_id * The PostgreSQL port of the schema accidentally added a moderation_callback column to the mailinglist table. Since this is unused in Mailman, it was simply commented out of the base schema for PostgreSQL. diff --git a/src/mailman/model/member.py b/src/mailman/model/member.py index 343c69e66..76fe2f992 100644 --- a/src/mailman/model/member.py +++ b/src/mailman/model/member.py @@ -53,7 +53,7 @@ class Member(Model): id = Int(primary=True) _member_id = UUID() role = Enum(MemberRole) - list_id = Unicode(name='mailing_list') + list_id = Unicode() moderation_action = Enum(Action) address_id = Int() |
