From: Elrond Date: Fri, 10 Feb 2012 23:38:21 +0000 (+0100) Subject: sql db design suggestions by Svavar Kjarrval X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=eea6d276bc03bbbea7bba325f3cb6ebf6663b451;p=mediagoblin.git 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. --- 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)