diff options
| author | Barry Warsaw | 2007-11-04 18:10:21 -0500 |
|---|---|---|
| committer | Barry Warsaw | 2007-11-04 18:10:21 -0500 |
| commit | 46f480dfaa6286ff8950af817de1c35910b37e16 (patch) | |
| tree | 194e8a3fb2150b7fa9ce5063a4b5b4acdf821365 /Mailman/database/__init__.py | |
| parent | 85473d738ce8ec53ac518819832e0babc3558cf2 (diff) | |
| download | mailman-46f480dfaa6286ff8950af817de1c35910b37e16.tar.gz mailman-46f480dfaa6286ff8950af817de1c35910b37e16.tar.zst mailman-46f480dfaa6286ff8950af817de1c35910b37e16.zip | |
Target Mailman onto the Storm <http://storm.canonical.com> Python ORM. This
enables a few interesting things:
1. It makes it easier to do our "pillars of storage" idea, where list data and
messages could live in one database, but user information live in a
separate database.
2. It reduces the number of moving parts. SQLAlchemy and Elixir can both go
away in favor of just one database layer.
3. No more Unicode/string mush hell. Somewhere along the way the upgrade to
SQLAlchemy 0.4 and Elixir 0.4 made the strings coming out the database
sometimes Unicode and sometimes 8-bit. This was totally unpredictable.
Storm asserts that if a property is declared Unicode, it comes in and goes
out as Unicode.
4. 'flush' is gone.
One cost of this is that Storm does not yet currently support schema
generation. So I cheat by dumping the trunk's SQLite schema and using that as
a starting place for the Storm-based schema. I hope that Storm will
eventually address this.
Other related changes include:
- SQLALCHEMY_ENGINE_URL is renamed to DEFAULT_DATABASE_URL. This may still
get changed.
Things I still want to fix:
- Ickyness with clearing the databases.
- Really implement multiple stores with better management of the Store
instances.
- Fix all the circular import nasties.
Diffstat (limited to 'Mailman/database/__init__.py')
| -rw-r--r-- | Mailman/database/__init__.py | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/Mailman/database/__init__.py b/Mailman/database/__init__.py index acc74642f..a3a5293af 100644 --- a/Mailman/database/__init__.py +++ b/Mailman/database/__init__.py @@ -26,15 +26,13 @@ __all__ = [ import os from locknix.lockfile import Lock -from elixir import objectstore +from storm.properties import PropertyPublisherMeta from zope.interface import implements from Mailman.interfaces import IDatabase from Mailman.database.listmanager import ListManager from Mailman.database.usermanager import UserManager from Mailman.database.messagestore import MessageStore -from Mailman.database.model import Pendings -from Mailman.database.model import Requests # Test suite convenience. Application code should use config.db.flush() # instead. @@ -55,24 +53,52 @@ class StockDatabase: self.message_store = None self.pendings = None self.requests = None + self._store = None def initialize(self, debug=None): + # Avoid circular imports. from Mailman.configuration import config from Mailman.database import model + from Mailman.database.model import Pendings + from Mailman.database.model import Requests # Serialize this so we don't get multiple processes trying to create # the database at the same time. with Lock(os.path.join(config.LOCK_DIR, 'dbcreate.lck')): - model.initialize(debug) + self.store = model.initialize(debug) self.list_manager = ListManager() self.user_manager = UserManager() self.message_store = MessageStore() self.pendings = Pendings() self.requests = Requests() - self.flush() def flush(self): - objectstore.flush() + pass def _reset(self): - model._reset() + for model_class in _class_registry: + for row in self.store.find(model_class): + self.store.remove(row) + + +_class_registry = set() + + +class ModelMeta(PropertyPublisherMeta): + """Do more magic on table classes.""" + + def __init__(self, name, bases, dict): + # Before we let the base class do it's thing, force an __storm_table__ + # property to enforce our table naming convention. + self.__storm_table__ = name.lower() + super(ModelMeta, self).__init__(name, bases, dict) + # Register the model class so that it can be more easily cleared. + # This is required by the test framework. + if name == 'Model': + return + _class_registry.add(self) + + +class Model(object): + """Like Storm's `Storm` subclass, but with a bit extra.""" + __metaclass__ = ModelMeta |
