From 51fba99125c63a6a5e68480e7d4b1ea08f33a4db Mon Sep 17 00:00:00 2001 From: Elrond Date: Sat, 28 Jan 2012 00:33:23 +0100 Subject: Some small SQL model improvements - Add default for User.email_verified - Add default for MediaEntry.state - Let PathTupleWithSlashes store [] as "NULL", but not handling the reverse properly yet! - Add _id alias field to MediaEntry and MediaComment --- mediagoblin/db/sql/models.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'mediagoblin/db/sql/models.py') diff --git a/mediagoblin/db/sql/models.py b/mediagoblin/db/sql/models.py index 9abd8ec7..7ec05876 100644 --- a/mediagoblin/db/sql/models.py +++ b/mediagoblin/db/sql/models.py @@ -50,7 +50,7 @@ class User(Base, UserMixin): email = Column(Unicode, nullable=False) created = Column(DateTime, nullable=False, default=datetime.datetime.now) pw_hash = Column(Unicode, nullable=False) - email_verified = Column(Boolean) + email_verified = Column(Boolean, default=False) status = Column(Unicode, default=u"needs_email_verification", nullable=False) verification_key = Column(Unicode) is_admin = Column(Boolean, default=False, nullable=False) @@ -77,7 +77,8 @@ class MediaEntry(Base, MediaEntryMixin): description = Column(UnicodeText) # ?? description_html = Column(UnicodeText) # ?? media_type = Column(Unicode, nullable=False) - state = Column(Unicode, nullable=False) # or use sqlalchemy.types.Enum? + state = Column(Unicode, default=u'unprocessed', nullable=False) + # or use sqlalchemy.types.Enum? license = Column(Unicode) fail_error = Column(Unicode) @@ -113,6 +114,8 @@ class MediaEntry(Base, MediaEntryMixin): # attachment_files # fail_error + _id = SimpleFieldAlias("id") + def get_comments(self, ascending=False): order_col = MediaComment.created if not ascending: @@ -215,6 +218,8 @@ class MediaComment(Base): get_author = relationship(User) + _id = SimpleFieldAlias("id") + def show_table_init(): from sqlalchemy import create_engine -- cgit v1.2.3 From 7f4ebeed7677a229f539bd2eaa78f9783dfc1477 Mon Sep 17 00:00:00 2001 From: Will Kahn-Greene Date: Wed, 8 Feb 2012 10:46:33 -0500 Subject: Fix copyright statements; add LICENSE for EXIF.py --- mediagoblin/db/sql/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/db/sql/models.py') diff --git a/mediagoblin/db/sql/models.py b/mediagoblin/db/sql/models.py index 7ec05876..36f94b25 100644 --- a/mediagoblin/db/sql/models.py +++ b/mediagoblin/db/sql/models.py @@ -1,5 +1,5 @@ # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011,2012 MediaGoblin contributors. See AUTHORS. +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by -- cgit v1.2.3 From eea6d276bc03bbbea7bba325f3cb6ebf6663b451 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sat, 11 Feb 2012 00:38:21 +0100 Subject: sql db design suggestions by Svavar Kjarrval Many thanks go to Svavar Kjarrval who has taken a deeper look at our current sql db design and made a bunch of suggestions. The suggestions are currently put as TODO items in the docstrings. This way we can keep track of them directly where we need it. --- mediagoblin/db/sql/models.py | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'mediagoblin/db/sql/models.py') diff --git a/mediagoblin/db/sql/models.py b/mediagoblin/db/sql/models.py index 36f94b25..9d06f79c 100644 --- a/mediagoblin/db/sql/models.py +++ b/mediagoblin/db/sql/models.py @@ -14,6 +14,10 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +""" +TODO: indexes on foreignkeys, where useful. +""" + import datetime @@ -43,6 +47,10 @@ class SimpleFieldAlias(object): class User(Base, UserMixin): + """ + TODO: We should consider moving some rarely used fields + into some sort of "shadow" table. + """ __tablename__ = "users" id = Column(Integer, primary_key=True) @@ -67,6 +75,9 @@ class User(Base, UserMixin): class MediaEntry(Base, MediaEntryMixin): + """ + TODO: Consider fetching the media_files using join + """ __tablename__ = "media_entries" id = Column(Integer, primary_key=True) @@ -145,6 +156,10 @@ class MediaEntry(Base, MediaEntryMixin): class MediaFile(Base): + """ + TODO: Highly consider moving "name" into a new table. + TODO: Consider preloading said table in software + """ __tablename__ = "mediafiles" media_entry = Column( @@ -221,12 +236,20 @@ class MediaComment(Base): _id = SimpleFieldAlias("id") -def show_table_init(): +def show_table_init(engine_uri): + if engine_uri is None: + engine_uri = 'sqlite:///:memory:' from sqlalchemy import create_engine - engine = create_engine('sqlite:///:memory:', echo=True) + engine = create_engine(engine_uri, echo=True) Base.metadata.create_all(engine) if __name__ == '__main__': - show_table_init() + from sys import argv + print repr(argv) + if len(argv) == 2: + uri = argv[1] + else: + uri = None + show_table_init(uri) -- cgit v1.2.3 From e61ab0998b77eaf18268001fd2d70917c3cd3e37 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sat, 4 Feb 2012 20:55:55 +0100 Subject: Drop pre-rendered html: User.bio_html After a bit of discussion, we decided to drop the pre-rendered html from the database and render it on the fly. In another step, we will use some proper caching method to cache this stuff. This commit affects the User.bio_html part. --- mediagoblin/db/sql/models.py | 1 - 1 file changed, 1 deletion(-) (limited to 'mediagoblin/db/sql/models.py') diff --git a/mediagoblin/db/sql/models.py b/mediagoblin/db/sql/models.py index 9d06f79c..3cf4ff40 100644 --- a/mediagoblin/db/sql/models.py +++ b/mediagoblin/db/sql/models.py @@ -64,7 +64,6 @@ class User(Base, UserMixin): is_admin = Column(Boolean, default=False, nullable=False) url = Column(Unicode) bio = Column(UnicodeText) # ?? - bio_html = Column(UnicodeText) # ?? fp_verification_key = Column(Unicode) fp_token_expire = Column(DateTime) -- cgit v1.2.3 From 1e72e075f8d542f4aa1ad0262f4fd1a5645cc731 Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 13 Feb 2012 13:42:59 +0100 Subject: Drop pre-rendered html: MediaEntry.description_html After a bit of discussion, we decided to drop the pre-rendered html from the database and render it on the fly. In another step, we will use some proper caching method to cache this stuff. This commit affects the MediaEntry.description_html part. --- mediagoblin/db/sql/models.py | 1 - 1 file changed, 1 deletion(-) (limited to 'mediagoblin/db/sql/models.py') diff --git a/mediagoblin/db/sql/models.py b/mediagoblin/db/sql/models.py index 3cf4ff40..72591f4e 100644 --- a/mediagoblin/db/sql/models.py +++ b/mediagoblin/db/sql/models.py @@ -85,7 +85,6 @@ class MediaEntry(Base, MediaEntryMixin): slug = Column(Unicode) created = Column(DateTime, nullable=False, default=datetime.datetime.now) description = Column(UnicodeText) # ?? - description_html = Column(UnicodeText) # ?? media_type = Column(Unicode, nullable=False) state = Column(Unicode, default=u'unprocessed', nullable=False) # or use sqlalchemy.types.Enum? -- cgit v1.2.3 From feba5c5287a7cb4c0ed8f5124ad60a8a291770ad Mon Sep 17 00:00:00 2001 From: Elrond Date: Sat, 18 Feb 2012 11:32:28 +0100 Subject: Drop pre-rendered html: MediaComment.content_html After a bit of discussion, we decided to drop the pre-rendered html from the database and render it on the fly. In another step, we will use some proper caching method to cache this stuff. This commit affects the MediaComment.content_html part. --- mediagoblin/db/sql/models.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'mediagoblin/db/sql/models.py') diff --git a/mediagoblin/db/sql/models.py b/mediagoblin/db/sql/models.py index 72591f4e..18e1dfd7 100644 --- a/mediagoblin/db/sql/models.py +++ b/mediagoblin/db/sql/models.py @@ -31,7 +31,7 @@ from sqlalchemy.ext.associationproxy import association_proxy from mediagoblin.db.sql.extratypes import PathTupleWithSlashes from mediagoblin.db.sql.base import Base, DictReadAttrProxy -from mediagoblin.db.mixin import UserMixin, MediaEntryMixin +from mediagoblin.db.mixin import UserMixin, MediaEntryMixin, MediaCommentMixin class SimpleFieldAlias(object): @@ -218,7 +218,7 @@ class MediaTag(Base): return DictReadAttrProxy(self) -class MediaComment(Base): +class MediaComment(Base, MediaCommentMixin): __tablename__ = "media_comments" id = Column(Integer, primary_key=True) @@ -227,7 +227,6 @@ class MediaComment(Base): author = Column(Integer, ForeignKey('users.id'), nullable=False) created = Column(DateTime, nullable=False, default=datetime.datetime.now) content = Column(UnicodeText, nullable=False) - content_html = Column(UnicodeText) get_author = relationship(User) -- cgit v1.2.3