From c4466cb4dcf194f634b6fe855f5e5fad09e70df1 Mon Sep 17 00:00:00 2001 From: Elrond Date: Thu, 13 Dec 2012 12:35:27 +0100 Subject: [PATCH] Add inspect_table. In our current scheme of migrations, we reflect the current sql schema into an SQLAlchemy schema. So let's have a tool function for this. --- mediagoblin/db/migrations.py | 11 ++++------- mediagoblin/db/sql/migration_tools.py | 7 +++++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/mediagoblin/db/migrations.py b/mediagoblin/db/migrations.py index 95270198..469d2874 100644 --- a/mediagoblin/db/migrations.py +++ b/mediagoblin/db/migrations.py @@ -23,7 +23,7 @@ from sqlalchemy.exc import ProgrammingError from sqlalchemy.ext.declarative import declarative_base from migrate.changeset.constraint import UniqueConstraint -from mediagoblin.db.sql.migration_tools import RegisterMigration +from mediagoblin.db.sql.migration_tools import RegisterMigration, inspect_table from mediagoblin.db.models import MediaEntry, Collection, User MIGRATIONS = {} @@ -60,8 +60,7 @@ def add_wants_notification_column(db_conn): def add_transcoding_progress(db_conn): metadata = MetaData(bind=db_conn.bind) - media_entry = Table('core__media_entries', metadata, autoload=True, - autoload_with=db_conn.bind) + media_entry = inspect_table(metadata, 'core__media_entries') col = Column('transcoding_progress', SmallInteger) col.create(media_entry) @@ -115,8 +114,7 @@ def add_collection_tables(db_conn): def add_mediaentry_collected(db_conn): metadata = MetaData(bind=db_conn.bind) - media_entry = Table('core__media_entries', metadata, autoload=True, - autoload_with=db_conn.bind) + media_entry = inspect_table(metadata, 'core__media_entries') col = Column('collected', Integer, default=0) col.create(media_entry) @@ -172,8 +170,7 @@ def fix_CollectionItem_v0_constraint(db_conn): metadata = MetaData(bind=db_conn.bind) - CollectionItem_table = Table('core__collection_items', - metadata, autoload=True, autoload_with=db_conn.bind) + CollectionItem_table = inspect_table(metadata, 'core__collection_items') constraint = UniqueConstraint('collection', 'media_entry', name='core__collection_items_collection_media_entry_key', diff --git a/mediagoblin/db/sql/migration_tools.py b/mediagoblin/db/sql/migration_tools.py index ee84e06f..e5380a3b 100644 --- a/mediagoblin/db/sql/migration_tools.py +++ b/mediagoblin/db/sql/migration_tools.py @@ -15,6 +15,7 @@ # along with this program. If not, see . from mediagoblin.tools.common import simple_printer +from sqlalchemy import Table class MigrationManager(object): @@ -261,3 +262,9 @@ def assure_migrations_table_setup(db): if not MigrationData.__table__.exists(db.bind): MigrationData.metadata.create_all( db.bind, tables=[MigrationData.__table__]) + + +def inspect_table(metadata, table_name): + """Simple helper to get a ref to an already existing table""" + return Table(table_name, metadata, autoload=True, + autoload_with=metadata.bind) -- 2.25.1