summaryrefslogtreecommitdiff
path: root/src/mailman/database/sqlite.py
diff options
context:
space:
mode:
authorBarry Warsaw2014-11-01 12:49:15 -0400
committerBarry Warsaw2014-11-01 12:49:15 -0400
commit8ab9c5111a05277e185b5e038bf12e13cd6df15e (patch)
tree9307b9f2fb65a90bc4d61a2c97478b582a96de87 /src/mailman/database/sqlite.py
parentb6bc505e45a2f1f4f99d7dd2cdd868d533270ee9 (diff)
parentfb38e482aa42edd4032a23e7c1f727066991fa62 (diff)
downloadmailman-8ab9c5111a05277e185b5e038bf12e13cd6df15e.tar.gz
mailman-8ab9c5111a05277e185b5e038bf12e13cd6df15e.tar.zst
mailman-8ab9c5111a05277e185b5e038bf12e13cd6df15e.zip
Database
-------- * The ORM layer, previously implemented with Storm, has been replaced by SQLAlchemy, thanks to the fantastic work by Abhilash Raj and Aurélien Bompard. Alembic is now used for all database schema migrations. * The new logger `mailman.database` logs any errors at the database layer. API --- * Several changes to the internal API: - `IListManager.mailing_lists` is guaranteed to be sorted in List-ID order. - `IDomains.mailing_lists` is guaranteed to be sorted in List-ID order. - Iteration over domains via the `IDomainManager` is guaranteed to be sorted by `IDomain.mail_host` order. - `ITemporaryDatabase` interface and all implementations are removed.
Diffstat (limited to 'src/mailman/database/sqlite.py')
-rw-r--r--src/mailman/database/sqlite.py46
1 files changed, 5 insertions, 41 deletions
diff --git a/src/mailman/database/sqlite.py b/src/mailman/database/sqlite.py
index 15629615f..db7860390 100644
--- a/src/mailman/database/sqlite.py
+++ b/src/mailman/database/sqlite.py
@@ -22,63 +22,27 @@ from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
'SQLiteDatabase',
- 'make_temporary',
]
import os
-import types
-import shutil
-import tempfile
-from functools import partial
+from mailman.database.base import SABaseDatabase
from urlparse import urlparse
-from mailman.database.base import StormBaseDatabase
-from mailman.testing.helpers import configuration
-
-class SQLiteDatabase(StormBaseDatabase):
+class SQLiteDatabase(SABaseDatabase):
"""Database class for SQLite."""
- TAG = 'sqlite'
-
- def _database_exists(self, store):
- """See `BaseDatabase`."""
- table_query = 'select tbl_name from sqlite_master;'
- table_names = set(item[0] for item in
- store.execute(table_query))
- return 'version' in table_names
-
def _prepare(self, url):
parts = urlparse(url)
assert parts.scheme == 'sqlite', (
'Database url mismatch (expected sqlite prefix): {0}'.format(url))
+ # Ensure that the SQLite database file has the proper permissions,
+ # since SQLite doesn't play nice with umask.
path = os.path.normpath(parts.path)
- fd = os.open(path, os.O_WRONLY | os.O_NONBLOCK | os.O_CREAT, 0666)
+ fd = os.open(path, os.O_WRONLY | os.O_NONBLOCK | os.O_CREAT, 0o666)
# Ignore errors
if fd > 0:
os.close(fd)
-
-
-
-# Test suite adapter for ITemporaryDatabase.
-
-def _cleanup(self, tempdir):
- shutil.rmtree(tempdir)
-
-
-def make_temporary(database):
- """Adapts by monkey patching an existing SQLite IDatabase."""
- tempdir = tempfile.mkdtemp()
- url = 'sqlite:///' + os.path.join(tempdir, 'mailman.db')
- with configuration('database', url=url):
- database.initialize()
- database._cleanup = types.MethodType(
- partial(_cleanup, tempdir=tempdir),
- database)
- # bool column values in SQLite must be integers.
- database.FALSE = 0
- database.TRUE = 1
- return database