diff options
| author | Barry Warsaw | 2007-10-31 17:38:51 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2007-10-31 17:38:51 -0400 |
| commit | f321d85d91a370294e771dbaa22493008d78dfdd (patch) | |
| tree | 8cf4c3e7cab70ccc9059f147ff1bf4b3bf150115 /Mailman/database/model/__init__.py | |
| parent | 1ad73a52bb9d82ef3af1e34ad9ef66ac2eda2909 (diff) | |
| download | mailman-f321d85d91a370294e771dbaa22493008d78dfdd.tar.gz mailman-f321d85d91a370294e771dbaa22493008d78dfdd.tar.zst mailman-f321d85d91a370294e771dbaa22493008d78dfdd.zip | |
Diffstat (limited to 'Mailman/database/model/__init__.py')
| -rw-r--r-- | Mailman/database/model/__init__.py | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/Mailman/database/model/__init__.py b/Mailman/database/model/__init__.py index ed91fe018..86f79a84b 100644 --- a/Mailman/database/model/__init__.py +++ b/Mailman/database/model/__init__.py @@ -36,11 +36,15 @@ from urlparse import urlparse import Mailman.Version -elixir.delay_setup = True - from Mailman import constants from Mailman.Errors import SchemaVersionMismatchError from Mailman.configuration import config + +# This /must/ be set before any Elixir classes are defined (i.e. imported). +# This tells Elixir to use the short table names (i.e. the class name) instead +# of a mangled full class path. +elixir.options_defaults['shortnames'] = True + from Mailman.database.model.address import Address from Mailman.database.model.language import Language from Mailman.database.model.mailinglist import MailingList @@ -54,7 +58,7 @@ from Mailman.database.model.version import Version -def initialize(): +def initialize(debug): # Calculate the engine url url = Template(config.SQLALCHEMY_ENGINE_URL).safe_substitute(config.paths) # XXX By design of SQLite, database file creation does not honor @@ -72,16 +76,17 @@ def initialize(): # could have chmod'd the file after the fact, but half dozen and all... touch(url) engine = create_engine(url) - engine.echo = config.SQLALCHEMY_ECHO - elixir.metadata.connect(engine) + engine.echo = (config.SQLALCHEMY_ECHO if debug is None else debug) + elixir.metadata.bind = engine elixir.setup_all() + elixir.create_all() # Validate schema version. v = Version.get_by(component='schema') if not v: # Database has not yet been initialized v = Version(component='schema', version=Mailman.Version.DATABASE_SCHEMA_VERSION) - elixir.objectstore.flush() + elixir.session.flush() elif v.version <> Mailman.Version.DATABASE_SCHEMA_VERSION: # XXX Update schema raise SchemaVersionMismatchError(v.version) @@ -96,3 +101,9 @@ def touch(url): # Ignore errors if fd > 0: os.close(fd) + + +def _reset(): + for entity in elixir.entities: + for row in entity.query.filter_by().all(): + row.delete() |
