diff --git a/pandora/app/monkey_patch.py b/pandora/app/monkey_patch.py index b106e224..8f48af00 100644 --- a/pandora/app/monkey_patch.py +++ b/pandora/app/monkey_patch.py @@ -32,4 +32,19 @@ def monkey_patch_username(): if isinstance(v, MaxLengthValidator): v.limit_value = 255 +def apply_patch(): + from django.db import connection, transaction + cursor = connection.cursor() + table = connection.introspection.get_table_description(cursor, User._meta.db_table) + sql = [] + for row in table: + if row.name in NEW_LENGTH and row.internal_size != NEW_LENGTH[row.name]: + sql.append('ALTER TABLE "%s" ALTER "%s" TYPE varchar(%d)' % (User._meta.db_table, row.name, NEW_LENGTH[row.name])) + + for q in sql: + cursor.execute(q) + if sql: + transaction.commit() + + monkey_patch_username() diff --git a/pandora/item/management/commands/sqlfindindex.py b/pandora/item/management/commands/sqlfindindex.py index c651e18f..3ecba6a8 100644 --- a/pandora/item/management/commands/sqlfindindex.py +++ b/pandora/item/management/commands/sqlfindindex.py @@ -31,6 +31,8 @@ class Command(BaseCommand): print(sql) cursor.execute(sql) + app.monkey_patch.apply_patch() + if settings.DB_GIN_TRGM: import entity.models import document.models