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/model | |
| 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/model')
| -rw-r--r-- | Mailman/database/model/__init__.py | 47 | ||||
| -rw-r--r-- | Mailman/database/model/address.py | 27 | ||||
| -rw-r--r-- | Mailman/database/model/language.py | 8 | ||||
| -rw-r--r-- | Mailman/database/model/mailinglist.py | 233 | ||||
| -rw-r--r-- | Mailman/database/model/mailman.sql | 206 | ||||
| -rw-r--r-- | Mailman/database/model/member.py | 24 | ||||
| -rw-r--r-- | Mailman/database/model/message.py | 13 | ||||
| -rw-r--r-- | Mailman/database/model/pending.py | 21 | ||||
| -rw-r--r-- | Mailman/database/model/preferences.py | 26 | ||||
| -rw-r--r-- | Mailman/database/model/requests.py | 22 | ||||
| -rw-r--r-- | Mailman/database/model/roster.py | 1 | ||||
| -rw-r--r-- | Mailman/database/model/user.py | 18 | ||||
| -rw-r--r-- | Mailman/database/model/version.py | 15 |
13 files changed, 439 insertions, 222 deletions
diff --git a/Mailman/database/model/__init__.py b/Mailman/database/model/__init__.py index 86f79a84b..c15670403 100644 --- a/Mailman/database/model/__init__.py +++ b/Mailman/database/model/__init__.py @@ -15,6 +15,8 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. +from __future__ import with_statement + __all__ = [ 'Address', 'Language', @@ -28,9 +30,9 @@ __all__ = [ import os import sys -import elixir -from sqlalchemy import create_engine +from storm import database +from storm.locals import create_database, Store from string import Template from urlparse import urlparse @@ -39,12 +41,6 @@ import Mailman.Version 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 @@ -59,8 +55,8 @@ from Mailman.database.model.version import Version def initialize(debug): - # Calculate the engine url - url = Template(config.SQLALCHEMY_ENGINE_URL).safe_substitute(config.paths) + # Calculate the engine url. + url = Template(config.DEFAULT_DATABASE_URL).safe_substitute(config.paths) # XXX By design of SQLite, database file creation does not honor # umask. See their ticket #1193: # http://www.sqlite.org/cvstrac/tktview?tn=1193,31 @@ -75,21 +71,30 @@ def initialize(debug): # permissions. We only try to do this for SQLite engines, and yes, we # 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 if debug is None else debug) - elixir.metadata.bind = engine - elixir.setup_all() - elixir.create_all() + database = create_database(url) + store = Store(database) + database.DEBUG = (config.DEFAULT_DATABASE_ECHO if debug is None else debug) + # XXX Storm does not currently have schema creation. This is not an ideal + # way to handle creating the database, but it's cheap and easy for now. + import Mailman.database.model + schema_file = os.path.join( + os.path.dirname(Mailman.database.model.__file__), + 'mailman.sql') + with open(schema_file) as fp: + sql = fp.read() + for statement in sql.split(';'): + store.execute(statement + ';') # Validate schema version. - v = Version.get_by(component='schema') + v = store.find(Version, component=u'schema').one() if not v: # Database has not yet been initialized - v = Version(component='schema', + v = Version(component=u'schema', version=Mailman.Version.DATABASE_SCHEMA_VERSION) - elixir.session.flush() + store.add(v) elif v.version <> Mailman.Version.DATABASE_SCHEMA_VERSION: # XXX Update schema raise SchemaVersionMismatchError(v.version) + return store def touch(url): @@ -101,9 +106,3 @@ 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() diff --git a/Mailman/database/model/address.py b/Mailman/database/model/address.py index 3ba3c3dbf..022bbce36 100644 --- a/Mailman/database/model/address.py +++ b/Mailman/database/model/address.py @@ -15,31 +15,30 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. -from elixir import * from email.utils import formataddr +from storm.locals import * from zope.interface import implements from Mailman import Errors +from Mailman.database import Model from Mailman.interfaces import IAddress -MEMBER_KIND = 'Mailman.database.model.member.Member' -PREFERENCE_KIND = 'Mailman.database.model.preferences.Preferences' -USER_KIND = 'Mailman.database.model.user.User' - - -class Address(Entity): +class Address(Model): implements(IAddress) - address = Field(Unicode) - _original = Field(Unicode) - real_name = Field(Unicode) - verified_on = Field(DateTime) - registered_on = Field(DateTime) + id = Int(primary=True) + address = Unicode() + _original = Unicode() + real_name = Unicode() + verified_on = DateTime() + registered_on = DateTime() - user = ManyToOne(USER_KIND) - preferences = ManyToOne(PREFERENCE_KIND) + user_id = Int() + user = Reference(user_id, 'User') + preferences_id = Int() + preferences = Reference(preferences_id, 'Preferences') def __init__(self, address, real_name): super(Address, self).__init__() diff --git a/Mailman/database/model/language.py b/Mailman/database/model/language.py index ffdbd2cba..a5229ab6a 100644 --- a/Mailman/database/model/language.py +++ b/Mailman/database/model/language.py @@ -15,14 +15,16 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. -from elixir import * +from storm.locals import * from zope.interface import implements +from Mailman.database import Model from Mailman.interfaces import ILanguage -class Language(Entity): +class Language(Model): implements(ILanguage) - code = Field(Unicode) + id = Int(primary=True) + code = Unicode() diff --git a/Mailman/database/model/mailinglist.py b/Mailman/database/model/mailinglist.py index 4057c2161..ed34a3aae 100644 --- a/Mailman/database/model/mailinglist.py +++ b/Mailman/database/model/mailinglist.py @@ -18,142 +18,145 @@ import os import string -from elixir import * +from storm.locals import * from zope.interface import implements from Mailman.Utils import fqdn_listname, makedirs, split_listname from Mailman.configuration import config +from Mailman.database import Model +from Mailman.database.types import Enum from Mailman.interfaces import IMailingList, Personalization -from Mailman.database.types import EnumType, TimeDeltaType SPACE = ' ' UNDERSCORE = '_' -class MailingList(Entity): +class MailingList(Model): implements(IMailingList) + id = Int(primary=True) + # List identity - list_name = Field(Unicode) - host_name = Field(Unicode) + list_name = Unicode() + host_name = Unicode() # Attributes not directly modifiable via the web u/i - created_at = Field(DateTime) - web_page_url = Field(Unicode) - admin_member_chunksize = Field(Integer) - hold_and_cmd_autoresponses = Field(PickleType) + created_at = DateTime() + web_page_url = Unicode() + admin_member_chunksize = Int() + hold_and_cmd_autoresponses = Pickle() # Attributes which are directly modifiable via the web u/i. The more # complicated attributes are currently stored as pickles, though that # will change as the schema and implementation is developed. - next_request_id = Field(Integer) - next_digest_number = Field(Integer) - admin_responses = Field(PickleType) - postings_responses = Field(PickleType) - request_responses = Field(PickleType) - digest_last_sent_at = Field(Float) - one_last_digest = Field(PickleType) - volume = Field(Integer) - last_post_time = Field(DateTime) + next_request_id = Int() + next_digest_number = Int() + admin_responses = Pickle() + postings_responses = Pickle() + request_responses = Pickle() + digest_last_sent_at = Float() + one_last_digest = Pickle() + volume = Int() + last_post_time = DateTime() # Attributes which are directly modifiable via the web u/i. The more # complicated attributes are currently stored as pickles, though that # will change as the schema and implementation is developed. - accept_these_nonmembers = Field(PickleType) - acceptable_aliases = Field(PickleType) - admin_immed_notify = Field(Boolean) - admin_notify_mchanges = Field(Boolean) - administrivia = Field(Boolean) - advertised = Field(Boolean) - anonymous_list = Field(Boolean) - archive = Field(Boolean) - archive_private = Field(Boolean) - archive_volume_frequency = Field(Integer) - autorespond_admin = Field(Boolean) - autorespond_postings = Field(Boolean) - autorespond_requests = Field(Integer) - autoresponse_admin_text = Field(Unicode) - autoresponse_graceperiod = Field(TimeDeltaType) - autoresponse_postings_text = Field(Unicode) - autoresponse_request_text = Field(Unicode) - ban_list = Field(PickleType) - bounce_info_stale_after = Field(TimeDeltaType) - bounce_matching_headers = Field(Unicode) - bounce_notify_owner_on_disable = Field(Boolean) - bounce_notify_owner_on_removal = Field(Boolean) - bounce_processing = Field(Boolean) - bounce_score_threshold = Field(Integer) - bounce_unrecognized_goes_to_list_owner = Field(Boolean) - bounce_you_are_disabled_warnings = Field(Integer) - bounce_you_are_disabled_warnings_interval = Field(TimeDeltaType) - collapse_alternatives = Field(Boolean) - convert_html_to_plaintext = Field(Boolean) - default_member_moderation = Field(Boolean) - description = Field(Unicode) - digest_footer = Field(Unicode) - digest_header = Field(Unicode) - digest_is_default = Field(Boolean) - digest_send_periodic = Field(Boolean) - digest_size_threshold = Field(Integer) - digest_volume_frequency = Field(Integer) - digestable = Field(Boolean) - discard_these_nonmembers = Field(PickleType) - emergency = Field(Boolean) - encode_ascii_prefixes = Field(Boolean) - filter_action = Field(Integer) - filter_content = Field(Boolean) - filter_filename_extensions = Field(PickleType) - filter_mime_types = Field(PickleType) - first_strip_reply_to = Field(Boolean) - forward_auto_discards = Field(Boolean) - gateway_to_mail = Field(Boolean) - gateway_to_news = Field(Boolean) - generic_nonmember_action = Field(Integer) - goodbye_msg = Field(Unicode) - header_filter_rules = Field(PickleType) - hold_these_nonmembers = Field(PickleType) - include_list_post_header = Field(Boolean) - include_rfc2369_headers = Field(Boolean) - info = Field(Unicode) - linked_newsgroup = Field(Unicode) - max_days_to_hold = Field(Integer) - max_message_size = Field(Integer) - max_num_recipients = Field(Integer) - member_moderation_action = Field(Boolean) - member_moderation_notice = Field(Unicode) - mime_is_default_digest = Field(Boolean) - moderator_password = Field(Unicode) - msg_footer = Field(Unicode) - msg_header = Field(Unicode) - new_member_options = Field(Integer) - news_moderation = Field(EnumType) - news_prefix_subject_too = Field(Boolean) - nntp_host = Field(Unicode) - nondigestable = Field(Boolean) - nonmember_rejection_notice = Field(Unicode) - obscure_addresses = Field(Boolean) - pass_filename_extensions = Field(PickleType) - pass_mime_types = Field(PickleType) - personalize = Field(EnumType) - post_id = Field(Integer) - preferred_language = Field(Unicode) - private_roster = Field(Boolean) - real_name = Field(Unicode) - reject_these_nonmembers = Field(PickleType) - reply_goes_to_list = Field(EnumType) - reply_to_address = Field(Unicode) - require_explicit_destination = Field(Boolean) - respond_to_post_requests = Field(Boolean) - scrub_nondigest = Field(Boolean) - send_goodbye_msg = Field(Boolean) - send_reminders = Field(Boolean) - send_welcome_msg = Field(Boolean) - subject_prefix = Field(Unicode) - subscribe_auto_approval = Field(PickleType) - subscribe_policy = Field(Integer) - topics = Field(PickleType) - topics_bodylines_limit = Field(Integer) - topics_enabled = Field(Boolean) - unsubscribe_policy = Field(Integer) - welcome_msg = Field(Unicode) + accept_these_nonmembers = Pickle() + acceptable_aliases = Pickle() + admin_immed_notify = Bool() + admin_notify_mchanges = Bool() + administrivia = Bool() + advertised = Bool() + anonymous_list = Bool() + archive = Bool() + archive_private = Bool() + archive_volume_frequency = Int() + autorespond_admin = Bool() + autorespond_postings = Bool() + autorespond_requests = Int() + autoresponse_admin_text = Unicode() + autoresponse_graceperiod = TimeDelta() + autoresponse_postings_text = Unicode() + autoresponse_request_text = Unicode() + ban_list = Pickle() + bounce_info_stale_after = TimeDelta() + bounce_matching_headers = Unicode() + bounce_notify_owner_on_disable = Bool() + bounce_notify_owner_on_removal = Bool() + bounce_processing = Bool() + bounce_score_threshold = Int() + bounce_unrecognized_goes_to_list_owner = Bool() + bounce_you_are_disabled_warnings = Int() + bounce_you_are_disabled_warnings_interval = TimeDelta() + collapse_alternatives = Bool() + convert_html_to_plaintext = Bool() + default_member_moderation = Bool() + description = Unicode() + digest_footer = Unicode() + digest_header = Unicode() + digest_is_default = Bool() + digest_send_periodic = Bool() + digest_size_threshold = Int() + digest_volume_frequency = Int() + digestable = Bool() + discard_these_nonmembers = Pickle() + emergency = Bool() + encode_ascii_prefixes = Bool() + filter_action = Int() + filter_content = Bool() + filter_filename_extensions = Pickle() + filter_mime_types = Pickle() + first_strip_reply_to = Bool() + forward_auto_discards = Bool() + gateway_to_mail = Bool() + gateway_to_news = Bool() + generic_nonmember_action = Int() + goodbye_msg = Unicode() + header_filter_rules = Pickle() + hold_these_nonmembers = Pickle() + include_list_post_header = Bool() + include_rfc2369_headers = Bool() + info = Unicode() + linked_newsgroup = Unicode() + max_days_to_hold = Int() + max_message_size = Int() + max_num_recipients = Int() + member_moderation_action = Bool() + member_moderation_notice = Unicode() + mime_is_default_digest = Bool() + moderator_password = Unicode() + msg_footer = Unicode() + msg_header = Unicode() + new_member_options = Int() + news_moderation = Enum() + news_prefix_subject_too = Bool() + nntp_host = Unicode() + nondigestable = Bool() + nonmember_rejection_notice = Unicode() + obscure_addresses = Bool() + pass_filename_extensions = Pickle() + pass_mime_types = Pickle() + personalize = Enum() + post_id = Int() + preferred_language = Unicode() + private_roster = Bool() + real_name = Unicode() + reject_these_nonmembers = Pickle() + reply_goes_to_list = Enum() + reply_to_address = Unicode() + require_explicit_destination = Bool() + respond_to_post_requests = Bool() + scrub_nondigest = Bool() + send_goodbye_msg = Bool() + send_reminders = Bool() + send_welcome_msg = Bool() + subject_prefix = Unicode() + subscribe_auto_approval = Pickle() + subscribe_policy = Int() + topics = Pickle() + topics_bodylines_limit = Int() + topics_enabled = Bool() + unsubscribe_policy = Int() + welcome_msg = Unicode() # Relationships ## has_and_belongs_to_many( ## 'available_languages', diff --git a/Mailman/database/model/mailman.sql b/Mailman/database/model/mailman.sql new file mode 100644 index 000000000..3dabad8c6 --- /dev/null +++ b/Mailman/database/model/mailman.sql @@ -0,0 +1,206 @@ +CREATE TABLE _request ( + id INTEGER NOT NULL, + "key" TEXT, + type TEXT, + data_hash TEXT, + mailing_list_id INTEGER, + PRIMARY KEY (id), + CONSTRAINT _request_mailing_list_id_fk FOREIGN KEY(mailing_list_id) REFERENCES mailinglist (id) +); +CREATE TABLE address ( + id INTEGER NOT NULL, + address TEXT, + _original TEXT, + real_name TEXT, + verified_on TIMESTAMP, + registered_on TIMESTAMP, + user_id INTEGER, + preferences_id INTEGER, + PRIMARY KEY (id), + CONSTRAINT address_user_id_fk FOREIGN KEY(user_id) REFERENCES user (id), + CONSTRAINT address_preferences_id_fk FOREIGN KEY(preferences_id) REFERENCES preferences (id) +); +CREATE TABLE language ( + id INTEGER NOT NULL, + code TEXT, + PRIMARY KEY (id) +); +CREATE TABLE mailinglist ( + id INTEGER NOT NULL, + list_name TEXT, + host_name TEXT, + created_at TIMESTAMP, + web_page_url TEXT, + admin_member_chunksize INTEGER, + hold_and_cmd_autoresponses BLOB, + next_request_id INTEGER, + next_digest_number INTEGER, + admin_responses BLOB, + postings_responses BLOB, + request_responses BLOB, + digest_last_sent_at NUMERIC(10, 2), + one_last_digest BLOB, + volume INTEGER, + last_post_time TIMESTAMP, + accept_these_nonmembers BLOB, + acceptable_aliases BLOB, + admin_immed_notify BOOLEAN, + admin_notify_mchanges BOOLEAN, + administrivia BOOLEAN, + advertised BOOLEAN, + anonymous_list BOOLEAN, + archive BOOLEAN, + archive_private BOOLEAN, + archive_volume_frequency INTEGER, + autorespond_admin BOOLEAN, + autorespond_postings BOOLEAN, + autorespond_requests INTEGER, + autoresponse_admin_text TEXT, + autoresponse_graceperiod TEXT, + autoresponse_postings_text TEXT, + autoresponse_request_text TEXT, + ban_list BLOB, + bounce_info_stale_after TEXT, + bounce_matching_headers TEXT, + bounce_notify_owner_on_disable BOOLEAN, + bounce_notify_owner_on_removal BOOLEAN, + bounce_processing BOOLEAN, + bounce_score_threshold INTEGER, + bounce_unrecognized_goes_to_list_owner BOOLEAN, + bounce_you_are_disabled_warnings INTEGER, + bounce_you_are_disabled_warnings_interval TEXT, + collapse_alternatives BOOLEAN, + convert_html_to_plaintext BOOLEAN, + default_member_moderation BOOLEAN, + description TEXT, + digest_footer TEXT, + digest_header TEXT, + digest_is_default BOOLEAN, + digest_send_periodic BOOLEAN, + digest_size_threshold INTEGER, + digest_volume_frequency INTEGER, + digestable BOOLEAN, + discard_these_nonmembers BLOB, + emergency BOOLEAN, + encode_ascii_prefixes BOOLEAN, + filter_action INTEGER, + filter_content BOOLEAN, + filter_filename_extensions BLOB, + filter_mime_types BLOB, + first_strip_reply_to BOOLEAN, + forward_auto_discards BOOLEAN, + gateway_to_mail BOOLEAN, + gateway_to_news BOOLEAN, + generic_nonmember_action INTEGER, + goodbye_msg TEXT, + header_filter_rules BLOB, + hold_these_nonmembers BLOB, + include_list_post_header BOOLEAN, + include_rfc2369_headers BOOLEAN, + info TEXT, + linked_newsgroup TEXT, + max_days_to_hold INTEGER, + max_message_size INTEGER, + max_num_recipients INTEGER, + member_moderation_action BOOLEAN, + member_moderation_notice TEXT, + mime_is_default_digest BOOLEAN, + moderator_password TEXT, + msg_footer TEXT, + msg_header TEXT, + new_member_options INTEGER, + news_moderation TEXT, + news_prefix_subject_too BOOLEAN, + nntp_host TEXT, + nondigestable BOOLEAN, + nonmember_rejection_notice TEXT, + obscure_addresses BOOLEAN, + pass_filename_extensions BLOB, + pass_mime_types BLOB, + personalize TEXT, + post_id INTEGER, + preferred_language TEXT, + private_roster BOOLEAN, + real_name TEXT, + reject_these_nonmembers BLOB, + reply_goes_to_list TEXT, + reply_to_address TEXT, + require_explicit_destination BOOLEAN, + respond_to_post_requests BOOLEAN, + scrub_nondigest BOOLEAN, + send_goodbye_msg BOOLEAN, + send_reminders BOOLEAN, + send_welcome_msg BOOLEAN, + subject_prefix TEXT, + subscribe_auto_approval BLOB, + subscribe_policy INTEGER, + topics BLOB, + topics_bodylines_limit INTEGER, + topics_enabled BOOLEAN, + unsubscribe_policy INTEGER, + welcome_msg TEXT, + PRIMARY KEY (id) +); +CREATE TABLE member ( + id INTEGER NOT NULL, + role TEXT, + mailing_list TEXT, + address_id INTEGER, + preferences_id INTEGER, + PRIMARY KEY (id), + CONSTRAINT member_address_id_fk FOREIGN KEY(address_id) REFERENCES address (id), + CONSTRAINT member_preferences_id_fk FOREIGN KEY(preferences_id) REFERENCES preferences (id) +); +CREATE TABLE message ( + id INTEGER NOT NULL, + hash TEXT, + path TEXT, + message_id TEXT, + PRIMARY KEY (id) +); +CREATE TABLE pended ( + id INTEGER NOT NULL, + token TEXT, + expiration_date TIMESTAMP, + PRIMARY KEY (id) +); +CREATE TABLE pendedkeyvalue ( + id INTEGER NOT NULL, + "key" TEXT, + value TEXT, + pended_id INTEGER, + PRIMARY KEY (id), + CONSTRAINT pendedkeyvalue_pended_id_fk FOREIGN KEY(pended_id) REFERENCES pended (id) +); +CREATE TABLE preferences ( + id INTEGER NOT NULL, + acknowledge_posts BOOLEAN, + hide_address BOOLEAN, + preferred_language TEXT, + receive_list_copy BOOLEAN, + receive_own_postings BOOLEAN, + delivery_mode TEXT, + delivery_status TEXT, + PRIMARY KEY (id) +); +CREATE TABLE user ( + id INTEGER NOT NULL, + real_name TEXT, + password TEXT, + preferences_id INTEGER, + PRIMARY KEY (id), + CONSTRAINT user_preferences_id_fk FOREIGN KEY(preferences_id) REFERENCES preferences (id) +); +CREATE TABLE version ( + id INTEGER NOT NULL, + component TEXT, + version INTEGER, + PRIMARY KEY (id) +); +CREATE INDEX ix__request_mailing_list_id ON _request (mailing_list_id); +CREATE INDEX ix_address_preferences_id ON address (preferences_id); +CREATE INDEX ix_address_user_id ON address (user_id); +CREATE INDEX ix_member_address_id ON member (address_id); +CREATE INDEX ix_member_preferences_id ON member (preferences_id); +CREATE INDEX ix_pendedkeyvalue_pended_id ON pendedkeyvalue (pended_id); +CREATE INDEX ix_user_preferences_id ON user (preferences_id); diff --git a/Mailman/database/model/member.py b/Mailman/database/model/member.py index 4f353a06c..70a823a75 100644 --- a/Mailman/database/model/member.py +++ b/Mailman/database/model/member.py @@ -15,28 +15,28 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. -from elixir import * +from storm.locals import * from zope.interface import implements from Mailman.Utils import split_listname from Mailman.constants import SystemDefaultPreferences -from Mailman.database.types import EnumType +from Mailman.database import Model +from Mailman.database.types import Enum from Mailman.interfaces import IMember, IPreferences -ADDRESS_KIND = 'Mailman.database.model.address.Address' -PREFERENCE_KIND = 'Mailman.database.model.preferences.Preferences' - - -class Member(Entity): +class Member(Model): implements(IMember) - role = Field(EnumType) - mailing_list = Field(Unicode) - # Relationships - address = ManyToOne(ADDRESS_KIND) - preferences = ManyToOne(PREFERENCE_KIND) + id = Int(primary=True) + role = Enum() + mailing_list = Unicode() + + address_id = Int() + address = Reference(address_id, 'Address') + preferences_id = Int() + preferences = Reference(preferences_id, 'Preferences') def __repr__(self): return '<Member: %s on %s as %s>' % ( diff --git a/Mailman/database/model/message.py b/Mailman/database/model/message.py index eb4b4616d..7a6d7371a 100644 --- a/Mailman/database/model/message.py +++ b/Mailman/database/model/message.py @@ -15,18 +15,21 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. -from elixir import * +from storm.locals import * from zope.interface import implements +from Mailman.database import Model from Mailman.interfaces import IMessage -class Message(Entity): +class Message(Model): """A message in the message store.""" implements(IMessage) - hash = Field(Unicode) - path = Field(Unicode) - message_id = Field(Unicode) + id = Int(primary=True) + hash = Unicode() + path = Unicode() + # This is a Messge-ID field representation, not a database row id. + message_id = Unicode() diff --git a/Mailman/database/model/pending.py b/Mailman/database/model/pending.py index 75bb59d3c..058b5de09 100644 --- a/Mailman/database/model/pending.py +++ b/Mailman/database/model/pending.py @@ -22,35 +22,36 @@ import random import hashlib import datetime -from elixir import * +from storm.locals import * from zope.interface import implements from zope.interface.verify import verifyObject from Mailman.configuration import config +from Mailman.database import Model from Mailman.interfaces import ( IPendings, IPendable, IPendedKeyValue, IPended) -PEND_KIND = 'Mailman.database.model.pending.Pended' - -class PendedKeyValue(Entity): +class PendedKeyValue(Model): """A pended key/value pair, tied to a token.""" implements(IPendedKeyValue) - key = Field(Unicode) - value = Field(Unicode) - pended = ManyToOne(PEND_KIND) + id = Int(primary=True) + key = Unicode() + value = Unicode() -class Pended(Entity): +class Pended(Model): """A pended event, tied to a token.""" implements(IPended) - token = Field(Unicode) - expiration_date = Field(DateTime) + id = Int(primary=True) + token = Unicode() + expiration_date = DateTime() + key_values = Reference(id, PendedKeyValue.id) diff --git a/Mailman/database/model/preferences.py b/Mailman/database/model/preferences.py index 8cbb77e6a..085e33e06 100644 --- a/Mailman/database/model/preferences.py +++ b/Mailman/database/model/preferences.py @@ -15,29 +15,27 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. -from elixir import * from email.utils import formataddr +from storm.locals import * from zope.interface import implements -from Mailman.database.types import EnumType +from Mailman.database import Model +from Mailman.database.types import Enum from Mailman.interfaces import IPreferences -ADDRESS_KIND = 'Mailman.database.model.address.Address' -MEMBER_KIND = 'Mailman.database.model.member.Member' -USER_KIND = 'Mailman.database.model.user.User' - -class Preferences(Entity): +class Preferences(Model): implements(IPreferences) - acknowledge_posts = Field(Boolean) - hide_address = Field(Boolean) - preferred_language = Field(Unicode) - receive_list_copy = Field(Boolean) - receive_own_postings = Field(Boolean) - delivery_mode = Field(EnumType) - delivery_status = Field(EnumType) + id = Int(primary=True) + acknowledge_posts = Bool() + hide_address = Bool() + preferred_language = Unicode() + receive_list_copy = Bool() + receive_own_postings = Bool() + delivery_mode = Enum() + delivery_status = Enum() def __repr__(self): return '<Preferences object at %#x>' % id(self) diff --git a/Mailman/database/model/requests.py b/Mailman/database/model/requests.py index 037483c1a..d16e8f49d 100644 --- a/Mailman/database/model/requests.py +++ b/Mailman/database/model/requests.py @@ -18,17 +18,15 @@ """Implementations of the IRequests and IListRequests interfaces.""" from datetime import timedelta -from elixir import * +from storm.locals import * from zope.interface import implements from Mailman.configuration import config -from Mailman.database.types import EnumType +from Mailman.database import Model +from Mailman.database.types import Enum from Mailman.interfaces import IListRequests, IPendable, IRequests, RequestType -MAILINGLIST_KIND = 'Mailman.database.model.mailinglist.MailingList' - - __metaclass__ = type __all__ = [ 'Requests', @@ -127,11 +125,13 @@ class Requests: -class _Request(Entity): +class _Request(Model): """Table for mailing list hold requests.""" - key = Field(Unicode) - type = Field(EnumType) - data_hash = Field(Unicode) - # Relationships - mailing_list = ManyToOne(MAILINGLIST_KIND) + id = Int(primary=True) + key = Unicode() + type = Enum() + data_hash = Unicode() + + mailing_list_id = Int() + mailing_list = Reference(mailing_list_id, 'MailingList') diff --git a/Mailman/database/model/roster.py b/Mailman/database/model/roster.py index c8fa86d58..5a01e7c7b 100644 --- a/Mailman/database/model/roster.py +++ b/Mailman/database/model/roster.py @@ -22,7 +22,6 @@ the ones that fit a particular role. These are used as the member, owner, moderator, and administrator roster filters. """ -from sqlalchemy import * from zope.interface import implements from Mailman.constants import SystemDefaultPreferences diff --git a/Mailman/database/model/user.py b/Mailman/database/model/user.py index 17c388e0e..1ba5ba10e 100644 --- a/Mailman/database/model/user.py +++ b/Mailman/database/model/user.py @@ -15,28 +15,28 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. -from elixir import * from email.utils import formataddr +from storm.locals import * from zope.interface import implements from Mailman import Errors +from Mailman.database import Model from Mailman.database.model import Address from Mailman.database.model import Preferences from Mailman.interfaces import IUser -ADDRESS_KIND = 'Mailman.database.model.address.Address' -PREFERENCE_KIND = 'Mailman.database.model.preferences.Preferences' - -class User(Entity): +class User(Model): implements(IUser) - real_name = Field(Unicode) - password = Field(Unicode) + id = Int(primary=True) + real_name = Unicode() + password = Unicode() - addresses = OneToMany(ADDRESS_KIND) - preferences = ManyToOne(PREFERENCE_KIND) + addresses = ReferenceSet(id, 'Address.user_id') + preferences_id = Int() + preferences = Reference(preferences_id, 'Preferences') def __repr__(self): return '<User "%s" at %#x>' % (self.real_name, id(self)) diff --git a/Mailman/database/model/version.py b/Mailman/database/model/version.py index dbbf5b8c1..2f4ff3f4d 100644 --- a/Mailman/database/model/version.py +++ b/Mailman/database/model/version.py @@ -15,9 +15,16 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # USA. -from elixir import * +from storm.locals import * +from Mailman.database import Model -class Version(Entity): - component = Field(Unicode) - version = Field(Integer) + +class Version(Model): + id = Int(primary=True) + component = Unicode() + version = Int() + + def __init__(self, component, version): + self.component = component + self.version = version |
