From 9ef8a1268f1b2902ad46852937dd7bc977c5b2b1 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Wed, 25 Jul 2012 12:23:29 -0400 Subject: Very nearly there with PostgreSQL support for testing the beta2 migration. - Improve migration logging - Disable pre_reset() and post_reset() on migrations, which might need to be re-enabled for SQLite support. - Be sure to record the migration version in PostgreSQL. - Parameterize the Error that will occur. - Better sample data for PostgreSQL and SQLite, which have different formats. --- src/mailman/database/postgresql.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/mailman/database/postgresql.py') diff --git a/src/mailman/database/postgresql.py b/src/mailman/database/postgresql.py index 14855c3f3..879594459 100644 --- a/src/mailman/database/postgresql.py +++ b/src/mailman/database/postgresql.py @@ -25,6 +25,8 @@ __all__ = [ ] +import psycopg2 + from operator import attrgetter from urlparse import urlsplit, urlunsplit @@ -39,8 +41,9 @@ class _TemporaryDB: self.database = database def cleanup(self): - self.database.execute('ROLLBACK TO SAVEPOINT testing;') - self.database.execute('DROP DATABASE mmtest;') + self.database.store.execute('ABORT;') + self.database.store.close() + config.db.store.execute('DROP DATABASE mmtest;') @@ -48,6 +51,7 @@ class PostgreSQLDatabase(StormBaseDatabase): """Database class for PostgreSQL.""" TAG = 'postgres' + Error = psycopg2.ProgrammingError def _database_exists(self, store): """See `BaseDatabase`.""" @@ -85,9 +89,13 @@ class PostgreSQLDatabase(StormBaseDatabase): new_parts = list(parts) new_parts[2] = '/mmtest' url = urlunsplit(new_parts) + # Use the existing database connection to create a new testing + # database. Create a savepoint, which will make it easy to reset + # after the test. + config.db.store.execute('ABORT;') + config.db.store.execute('CREATE DATABASE mmtest;') + # Now create a new, temporary database. database = PostgreSQLDatabase() - database.store.execute('SAVEPOINT testing;') - database.store.execute('CREATE DATABASE mmtest;') with configuration('database', url=url): database.initialize() return _TemporaryDB(database) -- cgit v1.2.3-70-g09d2