Renaming replace_table to replace_table_hack and documenting why it's a hack

We'd still prefer people use other solutions when possible!

This commit sponsored by Michał Masłowski.  Thank you!
This commit is contained in:
Christopher Allan Webber 2013-10-10 14:22:38 -05:00
parent 454a2c16bd
commit 0c875e1e96
2 changed files with 12 additions and 6 deletions

View File

@ -288,8 +288,9 @@ def inspect_table(metadata, table_name):
return Table(table_name, metadata, autoload=True, return Table(table_name, metadata, autoload=True,
autoload_with=metadata.bind) autoload_with=metadata.bind)
def replace_table(db, old_table,replacement_table): def replace_table_hack(db, old_table, replacement_table):
"""A function to fully replace a current table with a new one for migrati- """
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- -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 -tion, for example, dropping a boolean column in sqlite is impossible w/o
this method this method
@ -298,7 +299,12 @@ def replace_table(db, old_table,replacement_table):
inspect_table inspect_table
:param replacement_table A ref to the new table, gotten through :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() surviving_columns = replacement_table.columns.keys()
old_table_name = old_table.name old_table_name = old_table.name
for row in db.execute(select( for row in db.execute(select(

View File

@ -27,8 +27,8 @@ from migrate.changeset.constraint import UniqueConstraint
from mediagoblin.db.extratypes import JSONEncoded, MutationDict from mediagoblin.db.extratypes import JSONEncoded, MutationDict
from mediagoblin.db.migration_tools import (RegisterMigration, inspect_table, from mediagoblin.db.migration_tools import (
replace_table) RegisterMigration, inspect_table, replace_table_hack)
from mediagoblin.db.models import (MediaEntry, Collection, MediaComment, User, from mediagoblin.db.models import (MediaEntry, Collection, MediaComment, User,
Privilege) Privilege)
@ -695,7 +695,7 @@ def create_moderation_tables(db):
User_vR1.__table__.create(db.bind) User_vR1.__table__.create(db.bind)
db.commit() db.commit()
new_user_table = inspect_table(metadata, 'rename__users') 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: else:
# If the db is not run using SQLite, this process is much simpler ~~~~~ # If the db is not run using SQLite, this process is much simpler ~~~~~