summaryrefslogtreecommitdiff
path: root/src/mailman/database/model.py
diff options
context:
space:
mode:
authorBarry Warsaw2012-02-12 10:01:07 -0500
committerBarry Warsaw2012-02-12 10:01:07 -0500
commitfaa56a174328af3ab76ccd1a5b4c9d630ac9779f (patch)
tree4a91273e2f7b7ae833827a37e1ac71ab90c251fb /src/mailman/database/model.py
parent125ba2db2ba59ad693e6142e9c761d4bad2f478c (diff)
downloadmailman-faa56a174328af3ab76ccd1a5b4c9d630ac9779f.tar.gz
mailman-faa56a174328af3ab76ccd1a5b4c9d630ac9779f.tar.zst
mailman-faa56a174328af3ab76ccd1a5b4c9d630ac9779f.zip
Diffstat (limited to 'src/mailman/database/model.py')
-rw-r--r--src/mailman/database/model.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/mailman/database/model.py b/src/mailman/database/model.py
index 9f6bf9845..c45517c9b 100644
--- a/src/mailman/database/model.py
+++ b/src/mailman/database/model.py
@@ -25,6 +25,8 @@ __all__ = [
]
+import sys
+
from operator import attrgetter
from storm.properties import PropertyPublisherMeta
@@ -50,12 +52,37 @@ class ModelMeta(PropertyPublisherMeta):
@staticmethod
def _reset(store):
from mailman.config import config
+ from mailman.model.version import Version
config.db._pre_reset(store)
+ # Give each schema migration a chance to do its pre-reset. See below
+ # for calling its post reset too.
+ versions = sorted(version.version for version in
+ store.find(Version, component='schema'))
+ migrations = {}
+ for version in versions:
+ # We have to give the migrations module that loaded this version a
+ # chance to do both pre- and post-reset operations. The following
+ # find the actual the module path for the migration. See
+ # StormBaseDatabase.load_schema().
+ migration = store.find(Version, component=version).one()
+ if migration is None:
+ continue
+ migrations[version] = module_path = migration.version
+ module = sys.modules[module_path]
+ pre_reset = getattr(module, 'pre_reset', None)
+ if pre_reset is not None:
+ pre_reset(store)
# Make sure this is deterministic, by sorting on the storm table name.
classes = sorted(ModelMeta._class_registry,
key=attrgetter('__storm_table__'))
for model_class in classes:
store.find(model_class).remove()
+ # Now give each migration a chance to do post-reset operations.
+ for version in versions:
+ module = sys.modules[migrations[version]]
+ post_reset = getattr(module, 'post_reset', None)
+ if post_reset is not None:
+ post_reset(store)
config.db._post_reset(store)