From 7b194a79f0ad789309b9c34340f19c5a962b0915 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 18 Dec 2011 17:02:27 +0100 Subject: SQL: mongokit like interface In trying to ease the migration to SQL, created an interface to sqlalchemy that looks a lot like the interface that is currently in use. *WARNING* Work in progress --- mediagoblin/db/sql/open.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 mediagoblin/db/sql/open.py (limited to 'mediagoblin/db/sql/open.py') diff --git a/mediagoblin/db/sql/open.py b/mediagoblin/db/sql/open.py new file mode 100644 index 00000000..57feaf50 --- /dev/null +++ b/mediagoblin/db/sql/open.py @@ -0,0 +1,29 @@ +from sqlalchemy import create_engine + +from mediagoblin.db.sql.base import Session +from mediagoblin.db.sql.models import Base + + +class DatabaseMaster(object): + def __init__(self, engine): + self.engine = engine + + for k,v in Base._decl_class_registry.iteritems(): + setattr(self, k, v) + + def commit(self): + Session.commit() + + def save(self, obj): + Session.add(obj) + Session.flush() + + def reset_after_request(self): + Session.remove() + + +def setup_connection_and_db_from_config(app_config): + engine = create_engine(app_config['sql_engine'], echo=True) + Session.configure(bind=engine) + + return "dummy conn", DatabaseMaster(engine) -- cgit v1.2.3 From 415077a743400f9d9fa476b37c5b3aff4683f942 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 1 Jan 2012 17:24:02 +0100 Subject: Factor out check_db_migrations_current When initializing the database connection the current mongo based setup checked for new migrations and warned about them. This was mongo specific so factor'd it out into a more generic check_db_migrations_current function in the mongo backend. Also created a dummy one in the sql backend. --- mediagoblin/db/sql/open.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'mediagoblin/db/sql/open.py') diff --git a/mediagoblin/db/sql/open.py b/mediagoblin/db/sql/open.py index 57feaf50..c682bd3b 100644 --- a/mediagoblin/db/sql/open.py +++ b/mediagoblin/db/sql/open.py @@ -27,3 +27,7 @@ def setup_connection_and_db_from_config(app_config): Session.configure(bind=engine) return "dummy conn", DatabaseMaster(engine) + + +def check_db_migrations_current(db): + pass -- cgit v1.2.3