diff options
| author | Barry Warsaw | 2015-04-22 10:28:04 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2015-04-22 10:28:04 -0400 |
| commit | 16570b8a7525dcb6720bc4b04790b6117ac3483b (patch) | |
| tree | 097efcd0ca15da887c887b41f7d799ce08e30891 /src/mailman/database/postgresql.py | |
| parent | ab41980bf3e69b81eff43172149667e2c0834a2e (diff) | |
| parent | 6ab77ea42b65839ac87876719dc3069c0989d67a (diff) | |
| download | mailman-16570b8a7525dcb6720bc4b04790b6117ac3483b.tar.gz mailman-16570b8a7525dcb6720bc4b04790b6117ac3483b.tar.zst mailman-16570b8a7525dcb6720bc4b04790b6117ac3483b.zip | |
Diffstat (limited to 'src/mailman/database/postgresql.py')
| -rw-r--r-- | src/mailman/database/postgresql.py | 15 |
1 files changed, 10 insertions, 5 deletions
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)) |
