summaryrefslogtreecommitdiff
path: root/src/mailman/database
diff options
context:
space:
mode:
authorBarry Warsaw2015-04-22 10:25:12 -0400
committerBarry Warsaw2015-04-22 10:25:12 -0400
commit6ab77ea42b65839ac87876719dc3069c0989d67a (patch)
tree097efcd0ca15da887c887b41f7d799ce08e30891 /src/mailman/database
parentab41980bf3e69b81eff43172149667e2c0834a2e (diff)
parent34586187d3b126f2efd6cbbf2cc86eaae285d838 (diff)
downloadmailman-6ab77ea42b65839ac87876719dc3069c0989d67a.tar.gz
mailman-6ab77ea42b65839ac87876719dc3069c0989d67a.tar.zst
mailman-6ab77ea42b65839ac87876719dc3069c0989d67a.zip
* The test suite now runs successfully again with PostgreSQL. Given by
Aurélien Bompard. (LP: #1435941)
Diffstat (limited to 'src/mailman/database')
-rw-r--r--src/mailman/database/factory.py6
-rw-r--r--src/mailman/database/postgresql.py15
2 files changed, 16 insertions, 5 deletions
diff --git a/src/mailman/database/factory.py b/src/mailman/database/factory.py
index 7222ba395..8b30b9417 100644
--- a/src/mailman/database/factory.py
+++ b/src/mailman/database/factory.py
@@ -135,6 +135,12 @@ class DatabaseTestingFactory:
database = call_name(database_class)
verifyObject(IDatabase, database)
database.initialize()
+ # Remove existing tables (PostgreSQL will keep them across runs)
+ metadata = MetaData(bind=database.engine)
+ metadata.reflect()
+ metadata.drop_all()
+ database.commit()
+ # Now create the current model without Alembic upgrades.
Model.metadata.create_all(database.engine)
database.commit()
# Make _reset() a bound method of the database instance.
diff --git a/src/mailman/database/postgresql.py b/src/mailman/database/postgresql.py
index 9877f110d..ea6540721 100644
--- a/src/mailman/database/postgresql.py
+++ b/src/mailman/database/postgresql.py
@@ -24,6 +24,7 @@ __all__ = [
from mailman.database.base import SABaseDatabase
from mailman.database.model import Model
+from sqlalchemy import Integer
@@ -42,8 +43,12 @@ class PostgreSQLDatabase(SABaseDatabase):
# http://stackoverflow.com/questions/544791/
# django-postgresql-how-to-reset-primary-key
for table in tables:
- store.execute("""\
- SELECT setval('"{0}_id_seq"', coalesce(max("id"), 1),
- max("id") IS NOT null)
- FROM "{0}";
- """.format(table))
+ for column in table.primary_key:
+ if (column.autoincrement
+ and isinstance(column.type, Integer)
+ and not column.foreign_keys):
+ store.execute("""\
+ SELECT setval('"{0}_{1}_seq"', coalesce(max("{1}"), 1),
+ max("{1}") IS NOT null)
+ FROM "{0}";
+ """.format(table, column.name))