Merge lp:~abompard/mailman/pgsql_upgrade into lp:mailman

Proposed by Aurélien Bompard
Status: Rejected
Rejected by: Barry Warsaw
Proposed branch: lp:~abompard/mailman/pgsql_upgrade
Merge into: lp:mailman
Diff against target: 169 lines (+150/-0)
2 files modified
src/mailman/database/schema/mm_20140715000000.py (+84/-0)
src/mailman/database/tests/test_migrations.py (+66/-0)
To merge this branch: bzr merge lp:~abompard/mailman/pgsql_upgrade
Reviewer Review Type Date Requested Status
Mailman Coders Pending
Review via email: mp+227289@code.launchpad.net

Description of the change

As explained on http://www.mail-archive.com/mailman-developers%40python.org/msg14659.html, the schema upgrade of 20130406 is missing the PostgreSQL part. This branch adds it in a new migration.

To post a comment you must log in.
Revision history for this message
Barry Warsaw (barry) wrote :

Any chance you could write some tests for this branch? I'm basically in favor of it, but tests would be good. OTOH, LP: #1170063 kind of sinks us, doesn't it? Have you looked at Gustavo's comments in that bug?

Revision history for this message
Aurélien Bompard (abompard) wrote :

OK I'll try to write some tests for this migration.
There's a workaround for #1170063 in the ticket that works for me, event if it's not perfect.
And with the SQLite lockups I reported long ago (#1091586), we can't afford to have neither SQLite nor PostgreSQL support...

lp:~abompard/mailman/pgsql_upgrade updated
7253. By Aurelien Bompard <email address hidden>

Add tests for the 20140715 migration

Revision history for this message
Barry Warsaw (barry) wrote :

Gosh, I'm finally catching up on merge proposals. Aurelien, I think with the switch to SA and Alembic, this one is no longer relevant.

Unmerged revisions

7253. By Aurelien Bompard <email address hidden>

Add tests for the 20140715 migration

7252. By Aurélien Bompard

Add PostgreSQL migration missing from the 20130406 schema upgrade

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'src/mailman/database/schema/mm_20140715000000.py'
--- src/mailman/database/schema/mm_20140715000000.py 1970-01-01 00:00:00 +0000
+++ src/mailman/database/schema/mm_20140715000000.py 2014-07-30 21:05:44 +0000
@@ -0,0 +1,84 @@
1# Copyright (C) 2012-2014 by the Free Software Foundation, Inc.
2#
3# This file is part of GNU Mailman.
4#
5# GNU Mailman is free software: you can redistribute it and/or modify it under
6# the terms of the GNU General Public License as published by the Free
7# Software Foundation, either version 3 of the License, or (at your option)
8# any later version.
9#
10# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13# more details.
14#
15# You should have received a copy of the GNU General Public License along with
16# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
17
18"""3.0b3 -> 3.0b4 schema migrations for PostgreSQL.
19
20* Renames:
21 - bounceevent.list_name -> bounceevent.list_id
22
23* Added:
24 - listarchiver table
25"""
26
27from __future__ import absolute_import, print_function, unicode_literals
28
29__metaclass__ = type
30__all__ = [
31 'upgrade',
32 ]
33
34
35from mailman.database.schema.helpers import make_listid
36
37
38VERSION = '20140715000000'
39
40
41
042
43def upgrade(database, store, version, module_path):
44 if database.TAG == 'sqlite':
45 upgrade_sqlite(database, store, version, module_path)
46 else:
47 upgrade_postgres(database, store, version, module_path)
48
49
50
151
52def upgrade_sqlite(database, store, version, module_path):
53 pass # done with 20130406000000
54
55
256
57def upgrade_postgres(database, store, version, module_path):
58 # Rename bounceevent.list_name to list_id
59 store.execute("""
60 ALTER TABLE bounceevent
61 RENAME COLUMN list_name TO list_id;
62 """)
63 results = store.execute("""
64 SELECT id, list_id
65 FROM bounceevent;
66 """)
67 for id, list_name in results:
68 store.execute("""
69 UPDATE bounceevent SET list_id = '{}'
70 WHERE id = {};
71 """.format(make_listid(list_name), id))
72 # Create listarchiver table
73 store.execute("""
74 CREATE TABLE listarchiver (
75 id SERIAL NOT NULL,
76 mailing_list_id INTEGER NOT NULL,
77 name TEXT NOT NULL,
78 _is_enabled BOOLEAN,
79 PRIMARY KEY (id)
80 );
81 """)
82 store.execute("""
83 CREATE INDEX ix_listarchiver_mailing_list_id
84 ON listarchiver(mailing_list_id);
85 """)
86 # Record the migration in the version table.
87 database.load_schema(store, version, None, module_path)
388
=== modified file 'src/mailman/database/tests/test_migrations.py'
--- src/mailman/database/tests/test_migrations.py 2014-01-01 14:59:42 +0000
+++ src/mailman/database/tests/test_migrations.py 2014-07-30 21:05:44 +0000
@@ -28,6 +28,7 @@
28 'TestMigration20121015Schema',28 'TestMigration20121015Schema',
29 'TestMigration20130406MigratedData',29 'TestMigration20130406MigratedData',
30 'TestMigration20130406Schema',30 'TestMigration20130406Schema',
31 'TestMigration20140715Schema',
31 ]32 ]
3233
3334
@@ -504,3 +505,68 @@
504 self.assertEqual(events[0].message_id, '<abc@example.com>')505 self.assertEqual(events[0].message_id, '<abc@example.com>')
505 self.assertEqual(events[0].context, BounceContext.normal)506 self.assertEqual(events[0].context, BounceContext.normal)
506 self.assertFalse(events[0].processed)507 self.assertFalse(events[0].processed)
508
509
510
507511
512class TestMigration20140715Schema(MigrationTestBase):
513 """Test column migrations."""
514
515 def test_pre_upgrade_column_migrations(self):
516 if self._database.TAG == 'sqlite':
517 raise unittest.SkipTest
518 self._missing_present('bounceevent',
519 ['20140714999999'],
520 ('list_id',),
521 ('list_name',))
522
523 def test_post_upgrade_column_migrations(self):
524 if self._database.TAG == 'sqlite':
525 raise unittest.SkipTest
526 self._missing_present('bounceevent',
527 ['20140714999999',
528 '20140715000000'],
529 ('list_name',),
530 ('list_id',))
531
532 def test_pre_listarchiver_table(self):
533 if self._database.TAG == 'sqlite':
534 raise unittest.SkipTest
535 self._table_missing_present(['20140714999999'], ('listarchiver',), ())
536
537 def test_post_listarchiver_table(self):
538 if self._database.TAG == 'sqlite':
539 raise unittest.SkipTest
540 self._table_missing_present(['20140714999999',
541 '20140715000000'],
542 (),
543 ('listarchiver',))
544
545
546
508547
548class TestMigration20140715MigratedData(MigrationTestBase):
549 """Test migrated data."""
550
551 def test_migration_bounceevent(self):
552 if self._database.TAG == 'sqlite':
553 raise unittest.SkipTest
554 # Load all migrations to just before the one we're testing.
555 self._database.load_migrations('20140714999999')
556 # Insert a bounce event.
557 self._database.store.execute("""
558 INSERT INTO bounceevent VALUES (
559 1, 'test@example.com', 'anne@example.com',
560 '2013-04-06 21:12:00', '<abc@example.com>',
561 1, 0);
562 """)
563 # Update to the current migration we're testing
564 self._database.load_migrations('20140715000000')
565 # The bounce event should exist, but with a list-id instead of a fqdn
566 # list name.
567 events = list(self._database.store.find(BounceEvent))
568 self.assertEqual(len(events), 1)
569 self.assertEqual(events[0].list_id, 'test.example.com')
570 self.assertEqual(events[0].email, 'anne@example.com')
571 self.assertEqual(events[0].timestamp, datetime(2013, 4, 6, 21, 12))
572 self.assertEqual(events[0].message_id, '<abc@example.com>')
573 self.assertEqual(events[0].context, BounceContext.normal)
574 self.assertFalse(events[0].processed)