0001-misc-do-not-rebuild-fts-by-default-on-migrate-comman.patch
tests/test_sql.py | ||
---|---|---|
1107 | 1107 |
@postgresql |
1108 | 1108 |
def test_migration_21_users_ascii_name(): |
1109 | 1109 |
conn, cur = sql.get_connection_and_cursor() |
1110 |
cur.execute('UPDATE wcs_meta SET value = 11 WHERE key = %s', ('sql_level',))
|
|
1110 |
cur.execute('UPDATE wcs_meta SET value = 20 WHERE key = %s', ('sql_level',))
|
|
1111 | 1111 | |
1112 | 1112 |
sql.SqlUser.wipe() |
1113 | 1113 | |
... | ... | |
1118 | 1118 |
# remove the ascii_name column |
1119 | 1119 |
cur.execute('ALTER TABLE users DROP COLUMN ascii_name') |
1120 | 1120 |
assert not column_exists_in_table(cur, 'users', 'ascii_name') |
1121 | ||
1122 |
# migrate *without* rebuild fts for users |
|
1121 | 1123 |
sql.migrate() |
1122 | 1124 | |
1123 | 1125 |
assert column_exists_in_table(cur, 'users', 'ascii_name') |
1124 | 1126 |
assert migration_level(cur) >= 21 |
1125 | 1127 | |
1126 |
# make sure the ascii_name is filled after the migration |
|
1128 |
# no fts rebuild, ascii_name is not filled |
|
1129 |
assert sql.SqlUser.count([st.Equal('ascii_name', 'jean senisme')]) == 0 |
|
1130 | ||
1131 |
# fts rebuilded : make sure the ascii_name is filled after the migration |
|
1132 |
sql.migrate(rebuild_fts_user=True) |
|
1127 | 1133 |
assert sql.SqlUser.count([st.Equal('ascii_name', 'jean senisme')]) == 1 |
1128 | 1134 | |
1129 | 1135 |
conn.commit() |
wcs/publisher.py | ||
---|---|---|
289 | 289 |
for workflow in Workflow.select(): |
290 | 290 |
WorkflowGlobalActionTimeoutTrigger.apply(workflow) |
291 | 291 | |
292 |
def migrate_sql(self): |
|
292 |
def migrate_sql(self, rebuild_fts_user=False, rebuild_fts_formdata=False):
|
|
293 | 293 |
import sql |
294 |
sql.migrate() |
|
294 |
sql.migrate(rebuild_fts_user=rebuild_fts_user, rebuild_fts_formdata=rebuild_fts_formdata)
|
|
295 | 295 | |
296 | 296 |
def cleanup(self): |
297 | 297 |
if self.is_using_postgresql(): |
wcs/qommon/management/commands/migrate.py | ||
---|---|---|
23 | 23 |
class Command(BaseCommand): |
24 | 24 |
help = 'Migrate databases' |
25 | 25 | |
26 |
def add_arguments(self, parser): |
|
27 |
parser.add_argument('--rebuild-fts-user', |
|
28 |
action='store_true', dest='rebuild_fts_user', default=False, |
|
29 |
help="Rebuild full text search indexes for users") |
|
30 |
parser.add_argument('--rebuild-fts-formdata', |
|
31 |
action='store_true', dest='rebuild_fts_formdata', default=False, |
|
32 |
help="Rebuild full text search indexes for formdata objects") |
|
33 | ||
26 | 34 |
def handle(self, **options): |
27 | 35 |
Publisher = get_publisher_class() |
28 | 36 |
quixote.cleanup() |
... | ... | |
36 | 44 |
pub.app_dir = tenant_path |
37 | 45 |
pub.set_config() |
38 | 46 |
if pub.is_using_postgresql(): |
39 |
pub.migrate_sql() |
|
47 |
pub.migrate_sql(rebuild_fts_user=options['rebuild_fts_user'], |
|
48 |
rebuild_fts_formdata=options['rebuild_fts_formdata']) |
|
40 | 49 |
pub.cleanup() |
41 | 50 |
quixote.cleanup() |
wcs/sql.py | ||
---|---|---|
2003 | 2003 |
migrate_global_views(conn, cur) |
2004 | 2004 | |
2005 | 2005 |
@guard_postgres |
2006 |
def migrate(): |
|
2006 |
def migrate(rebuild_fts_user=False, rebuild_fts_formdata=False):
|
|
2007 | 2007 |
conn, cur = get_connection_and_cursor() |
2008 | 2008 |
sql_level = get_sql_level(conn, cur) |
2009 | 2009 |
if sql_level < 0: |
... | ... | |
2039 | 2039 |
migrate_views(conn, cur) |
2040 | 2040 |
for formdef in FormDef.select(): |
2041 | 2041 |
formdef.data_class().rebuild_security() |
2042 |
if sql_level < 23: |
|
2043 |
# 12: (second part), store fts in existing rows |
|
2044 |
# 21: (second part), store ascii_name of users |
|
2045 |
# 23: (first part), use misc.simplify() over full text queries |
|
2046 |
for user_id in SqlUser.keys(): |
|
2047 |
SqlUser.get(user_id).store() |
|
2048 |
if sql_level < 23: |
|
2042 |
if sql_level < 17: |
|
2049 | 2043 |
# 17: store last_update_time in tables |
2050 |
# 18: add user name to full-text search index |
|
2051 |
# 21: (third part), add user ascii_names to full-text index |
|
2052 |
# 23: (second part) use misc.simplify() over full text queries |
|
2053 |
# load and store all formdatas |
|
2054 |
from wcs.formdef import FormDef |
|
2055 |
for formdef in FormDef.select(): |
|
2056 |
for formdata in formdef.data_class().select(): |
|
2057 |
formdata.store() |
|
2044 |
# load and store all formdatas = same as rebuild fts |
|
2045 |
rebuild_fts_user = True |
|
2058 | 2046 |
if sql_level < 24: |
2059 | 2047 |
from wcs.formdef import FormDef |
2060 | 2048 |
# 24: add index on evolution(formdata_id) |
2061 | 2049 |
for formdef in FormDef.select(): |
2062 | 2050 |
do_formdef_indexes(formdef, created=False, conn=conn, cur=cur) |
2063 | 2051 | |
2052 |
if rebuild_fts_user: |
|
2053 |
for user_id in SqlUser.keys(): |
|
2054 |
SqlUser.get(user_id).store() |
|
2055 |
if rebuild_fts_formdata: |
|
2056 |
from wcs.formdef import FormDef |
|
2057 |
for formdef in FormDef.select(): |
|
2058 |
for formdata in formdef.data_class().select(): |
|
2059 |
formdata.store() |
|
2060 | ||
2064 | 2061 |
cur.execute('''UPDATE wcs_meta SET value = %s WHERE key = %s''', ( |
2065 | 2062 |
str(SQL_LEVEL), 'sql_level')) |
2066 | 2063 | |
2067 |
- |