From 7473a9a190f7c03fed771c94467508142bef344d Mon Sep 17 00:00:00 2001 From: Thomas NOEL Date: Wed, 21 Mar 2018 11:02:04 +0100 Subject: [PATCH] misc: do not rebuild fts by default on migrate command (#22383) --- tests/test_sql.py | 10 ++++++++-- wcs/publisher.py | 4 ++-- wcs/qommon/management/commands/migrate.py | 11 ++++++++++- wcs/sql.py | 29 +++++++++++++---------------- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/tests/test_sql.py b/tests/test_sql.py index 3a423a3e..a89113d5 100644 --- a/tests/test_sql.py +++ b/tests/test_sql.py @@ -1107,7 +1107,7 @@ def test_migration_12_users_fts(): @postgresql def test_migration_21_users_ascii_name(): conn, cur = sql.get_connection_and_cursor() - cur.execute('UPDATE wcs_meta SET value = 11 WHERE key = %s', ('sql_level',)) + cur.execute('UPDATE wcs_meta SET value = 20 WHERE key = %s', ('sql_level',)) sql.SqlUser.wipe() @@ -1118,12 +1118,18 @@ def test_migration_21_users_ascii_name(): # remove the ascii_name column cur.execute('ALTER TABLE users DROP COLUMN ascii_name') assert not column_exists_in_table(cur, 'users', 'ascii_name') + + # migrate *without* rebuild fts for users sql.migrate() assert column_exists_in_table(cur, 'users', 'ascii_name') assert migration_level(cur) >= 21 - # make sure the ascii_name is filled after the migration + # no fts rebuild, ascii_name is not filled + assert sql.SqlUser.count([st.Equal('ascii_name', 'jean senisme')]) == 0 + + # fts rebuilded : make sure the ascii_name is filled after the migration + sql.migrate(rebuild_fts_user=True) assert sql.SqlUser.count([st.Equal('ascii_name', 'jean senisme')]) == 1 conn.commit() diff --git a/wcs/publisher.py b/wcs/publisher.py index a005788d..1900e2e5 100644 --- a/wcs/publisher.py +++ b/wcs/publisher.py @@ -289,9 +289,9 @@ class WcsPublisher(StubWcsPublisher): for workflow in Workflow.select(): WorkflowGlobalActionTimeoutTrigger.apply(workflow) - def migrate_sql(self): + def migrate_sql(self, rebuild_fts_user=False, rebuild_fts_formdata=False): import sql - sql.migrate() + sql.migrate(rebuild_fts_user=rebuild_fts_user, rebuild_fts_formdata=rebuild_fts_formdata) def cleanup(self): if self.is_using_postgresql(): diff --git a/wcs/qommon/management/commands/migrate.py b/wcs/qommon/management/commands/migrate.py index 4fe70a77..60577703 100644 --- a/wcs/qommon/management/commands/migrate.py +++ b/wcs/qommon/management/commands/migrate.py @@ -23,6 +23,14 @@ from qommon.publisher import get_publisher_class class Command(BaseCommand): help = 'Migrate databases' + def add_arguments(self, parser): + parser.add_argument('--rebuild-fts-user', + action='store_true', dest='rebuild_fts_user', default=False, + help="Rebuild full text search indexes for users") + parser.add_argument('--rebuild-fts-formdata', + action='store_true', dest='rebuild_fts_formdata', default=False, + help="Rebuild full text search indexes for formdata objects") + def handle(self, **options): Publisher = get_publisher_class() quixote.cleanup() @@ -36,6 +44,7 @@ class Command(BaseCommand): pub.app_dir = tenant_path pub.set_config() if pub.is_using_postgresql(): - pub.migrate_sql() + pub.migrate_sql(rebuild_fts_user=options['rebuild_fts_user'], + rebuild_fts_formdata=options['rebuild_fts_formdata']) pub.cleanup() quixote.cleanup() diff --git a/wcs/sql.py b/wcs/sql.py index b4a4af54..f4f002e5 100644 --- a/wcs/sql.py +++ b/wcs/sql.py @@ -2003,7 +2003,7 @@ def migrate_views(conn, cur): migrate_global_views(conn, cur) @guard_postgres -def migrate(): +def migrate(rebuild_fts_user=False, rebuild_fts_formdata=False): conn, cur = get_connection_and_cursor() sql_level = get_sql_level(conn, cur) if sql_level < 0: @@ -2039,28 +2039,25 @@ def migrate(): migrate_views(conn, cur) for formdef in FormDef.select(): formdef.data_class().rebuild_security() - if sql_level < 23: - # 12: (second part), store fts in existing rows - # 21: (second part), store ascii_name of users - # 23: (first part), use misc.simplify() over full text queries - for user_id in SqlUser.keys(): - SqlUser.get(user_id).store() - if sql_level < 23: + if sql_level < 17: # 17: store last_update_time in tables - # 18: add user name to full-text search index - # 21: (third part), add user ascii_names to full-text index - # 23: (second part) use misc.simplify() over full text queries - # load and store all formdatas - from wcs.formdef import FormDef - for formdef in FormDef.select(): - for formdata in formdef.data_class().select(): - formdata.store() + # load and store all formdatas = same as rebuild fts + rebuild_fts_user = True if sql_level < 24: from wcs.formdef import FormDef # 24: add index on evolution(formdata_id) for formdef in FormDef.select(): do_formdef_indexes(formdef, created=False, conn=conn, cur=cur) + if rebuild_fts_user: + for user_id in SqlUser.keys(): + SqlUser.get(user_id).store() + if rebuild_fts_formdata: + from wcs.formdef import FormDef + for formdef in FormDef.select(): + for formdata in formdef.data_class().select(): + formdata.store() + cur.execute('''UPDATE wcs_meta SET value = %s WHERE key = %s''', ( str(SQL_LEVEL), 'sql_level')) -- 2.16.2