diff options
| author | Abhilash Raj | 2014-09-18 19:02:08 +0530 |
|---|---|---|
| committer | Abhilash Raj | 2014-09-18 19:02:08 +0530 |
| commit | f774c7d7fc1f67b80ac701b3d640e2fab24422b4 (patch) | |
| tree | 9259c198de61333e71b65f8ead6d9c2c6bc7bb20 /src/mailman/database/base.py | |
| parent | f8212e1d9d32f29039b620d8805f1a53f579dd34 (diff) | |
| download | mailman-f774c7d7fc1f67b80ac701b3d640e2fab24422b4.tar.gz mailman-f774c7d7fc1f67b80ac701b3d640e2fab24422b4.tar.zst mailman-f774c7d7fc1f67b80ac701b3d640e2fab24422b4.zip | |
Diffstat (limited to 'src/mailman/database/base.py')
| -rw-r--r-- | src/mailman/database/base.py | 57 |
1 files changed, 16 insertions, 41 deletions
diff --git a/src/mailman/database/base.py b/src/mailman/database/base.py index 0bc530e6b..b66513a2c 100644 --- a/src/mailman/database/base.py +++ b/src/mailman/database/base.py @@ -31,6 +31,7 @@ from lazr.config import as_boolean from pkg_resources import resource_listdir, resource_string from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker +from sqlalchemy.orm.session import Session from zope.interface import implementer from mailman.config import config @@ -55,6 +56,7 @@ class SABaseDatabase: def __init__(self): self.url = None self.store = None + self.transaction = None def begin(self): pass @@ -101,10 +103,22 @@ class SABaseDatabase: self.url = url self._prepare(url) self.engine = create_engine(url) - Session = sessionmaker(bind=self.engine) - self.store = Session() + session = sessionmaker(bind=self.engine) + self.store = session() self.store.commit() + # def initialize_testing(self): + # url = expand(config.database.url, config.paths) + # log.debug('Database url: %s', url) + # self.url = url + # self._prepare(url) + # self.engine = create_engine(url) + # connection = self.engine.connect() + # self.transaction = connection.begin_nested() + # self.store = Session(connection) + # self.store.commit() + + def load_migrations(self, until=None): """Load schema migrations. @@ -114,45 +128,6 @@ class SABaseDatabase: """ from mailman.database.model import Model Model.metadata.create_all(self.engine) - # migrations_path = config.database.migrations_path - # if '.' in migrations_path: - # parent, dot, child = migrations_path.rpartition('.') - # else: - # parent = migrations_path - # child = '' - # # If the database does not yet exist, load the base schema. - # filenames = sorted(resource_listdir(parent, child)) - # # Find out which schema migrations have already been loaded. - # if self._database_exists(self.store): - # versions = set(version.version for version in - # self.store.query(Version, component='schema')) - # else: - # versions = set() - # for filename in filenames: - # module_fn, extension = os.path.splitext(filename) - # if extension != '.py': - # continue - # parts = module_fn.split('_') - # if len(parts) < 2: - # continue - # version = parts[1].strip() - # if len(version) == 0: - # # Not a schema migration file. - # continue - # if version in versions: - # log.debug('already migrated to %s', version) - # continue - # if until is not None and version > until: - # # We're done. - # break - # module_path = migrations_path + '.' + module_fn - # __import__(module_path) - # upgrade = getattr(sys.modules[module_path], 'upgrade', None) - # if upgrade is None: - # continue - # log.debug('migrating db to %s: %s', version, module_path) - # upgrade(self, self.store, version, module_path) - # self.commit() def load_sql(self, store, sql): """Load the given SQL into the store. |
