summaryrefslogtreecommitdiff
path: root/src/mailman/database/stock.py
diff options
context:
space:
mode:
authorStephen A. Goss2011-09-26 17:34:01 -0700
committerStephen A. Goss2011-09-26 17:34:01 -0700
commite24d8cdc4f9006f8cdfd84e9610cb6416d5961b9 (patch)
treedd1241c559568a61baededc16d4e1b7b1bb4d430 /src/mailman/database/stock.py
parent32a70d458ca705869889c0ab7c494bd1289dcac2 (diff)
downloadmailman-e24d8cdc4f9006f8cdfd84e9610cb6416d5961b9.tar.gz
mailman-e24d8cdc4f9006f8cdfd84e9610cb6416d5961b9.tar.zst
mailman-e24d8cdc4f9006f8cdfd84e9610cb6416d5961b9.zip
LP: #860159 (experimental) PostgreSQL support
Diffstat (limited to '')
-rw-r--r--src/mailman/database/stock.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/mailman/database/stock.py b/src/mailman/database/stock.py
index e69fe9c7c..306d33451 100644
--- a/src/mailman/database/stock.py
+++ b/src/mailman/database/stock.py
@@ -97,18 +97,29 @@ class StockDatabase:
store = Store(database, GenerationalCache())
database.DEBUG = (as_boolean(config.database.debug)
if debug is None else debug)
- # Check the sqlite master database to see if the version file exists.
+ # Check the master / schema database to see if the version table exists.
# If so, then we assume the database schema is correctly initialized.
# Storm does not currently have schema creation. This is not an ideal
# way to handle creating the database, but it's cheap and easy for
# now.
+ parts = urlparse(url)
+ if parts.scheme == 'sqlite':
+ table_query = 'select tbl_name from sqlite_master;'
+ schema_file = 'mailman.sql'
+ elif parts.scheme == 'postgres':
+ table_query = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"
+ schema_file = 'mailman_pg.sql'
+ else:
+ raise Exception("Database not supported yet: " + parts.scheme)
+
table_names = [item[0] for item in
- store.execute('select tbl_name from sqlite_master;')]
+ store.execute(table_query)]
if 'version' not in table_names:
# Initialize the database.
- sql = resource_string('mailman.database', 'mailman.sql')
+ sql = resource_string('mailman.database', schema_file)
for statement in sql.split(';'):
- store.execute(statement + ';')
+ if statement.strip() != '':
+ store.execute(statement + ';')
# Validate schema version.
v = store.find(Version, component='schema').one()
if not v: