From 0c875e1e96b77892bd3f9bd5a91959c57ab7b91c Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Thu, 10 Oct 2013 14:22:38 -0500 Subject: [PATCH] Renaming replace_table to replace_table_hack and documenting why it's a hack MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit We'd still prefer people use other solutions when possible! This commit sponsored by Michał Masłowski. Thank you! --- mediagoblin/db/migration_tools.py | 12 +++++++++--- mediagoblin/db/migrations.py | 6 +++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/mediagoblin/db/migration_tools.py b/mediagoblin/db/migration_tools.py index 6b51025e..e39070c3 100644 --- a/mediagoblin/db/migration_tools.py +++ b/mediagoblin/db/migration_tools.py @@ -288,8 +288,9 @@ def inspect_table(metadata, table_name): return Table(table_name, metadata, autoload=True, autoload_with=metadata.bind) -def replace_table(db, old_table,replacement_table): - """A function to fully replace a current table with a new one for migrati- +def replace_table_hack(db, old_table, replacement_table): + """ + A function to fully replace a current table with a new one for migrati- -ons. This is necessary because some changes are made tricky in some situa- -tion, for example, dropping a boolean column in sqlite is impossible w/o this method @@ -298,7 +299,12 @@ def replace_table(db, old_table,replacement_table): inspect_table :param replacement_table A ref to the new table, gotten through - inspect_table""" + inspect_table + + Users are encouraged to sqlalchemy-migrate replace table solutions, unless + that is not possible... in which case, this solution works, + at least for sqlite. + """ surviving_columns = replacement_table.columns.keys() old_table_name = old_table.name for row in db.execute(select( diff --git a/mediagoblin/db/migrations.py b/mediagoblin/db/migrations.py index 6e37e437..966817fc 100644 --- a/mediagoblin/db/migrations.py +++ b/mediagoblin/db/migrations.py @@ -27,8 +27,8 @@ from migrate.changeset.constraint import UniqueConstraint from mediagoblin.db.extratypes import JSONEncoded, MutationDict -from mediagoblin.db.migration_tools import (RegisterMigration, inspect_table, - replace_table) +from mediagoblin.db.migration_tools import ( + RegisterMigration, inspect_table, replace_table_hack) from mediagoblin.db.models import (MediaEntry, Collection, MediaComment, User, Privilege) @@ -695,7 +695,7 @@ def create_moderation_tables(db): User_vR1.__table__.create(db.bind) db.commit() new_user_table = inspect_table(metadata, 'rename__users') - replace_table(db,user_table, new_user_table) + replace_table_hack(db, user_table, new_user_table) else: # If the db is not run using SQLite, this process is much simpler ~~~~~ -- 2.25.1