sql: add index on status column (#48307)
This commit is contained in:
parent
f91dca84ef
commit
ad166e31a5
|
@ -1045,7 +1045,7 @@ def test_sql_level():
|
|||
cur.execute('DROP TABLE wcs_meta')
|
||||
assert sql.get_sql_level(conn, cur) == 0
|
||||
sql.migrate()
|
||||
assert sql.get_sql_level(conn, cur) == sql.SQL_LEVEL
|
||||
assert sql.get_sql_level(conn, cur) == sql.SQL_LEVEL[0]
|
||||
|
||||
# insert negative SQL level, to trigger an error, and check it's not
|
||||
# changed.
|
||||
|
|
15
wcs/sql.py
15
wcs/sql.py
|
@ -627,7 +627,7 @@ def do_formdef_indexes(formdef, created, conn, cur, concurrently=False):
|
|||
cur.execute('''%s %s_fid ON %s (formdata_id)''' % (
|
||||
create_index, evolutions_table_name, evolutions_table_name))
|
||||
|
||||
for attr in ('receipt_time', 'anonymised', 'user_id'):
|
||||
for attr in ('receipt_time', 'anonymised', 'user_id', 'status'):
|
||||
if not table_name + '_' + attr + '_idx' in existing_indexes:
|
||||
cur.execute('%(create_index)s %(table_name)s_%(attr)s_idx ON %(table_name)s (%(attr)s)' % {
|
||||
'create_index': create_index,
|
||||
|
@ -874,7 +874,7 @@ def do_meta_table(conn=None, cur=None, insert_current_sql_level=True):
|
|||
key varchar,
|
||||
value varchar)''')
|
||||
if insert_current_sql_level:
|
||||
sql_level = SQL_LEVEL
|
||||
sql_level = SQL_LEVEL[0]
|
||||
else:
|
||||
sql_level = 0
|
||||
cur.execute('''INSERT INTO wcs_meta (id, key, value)
|
||||
|
@ -2687,7 +2687,10 @@ def get_yearly_totals(period_start=None, period_end=None, criterias=None):
|
|||
return result
|
||||
|
||||
|
||||
SQL_LEVEL = 44
|
||||
# latest migration, number + description (description is not used
|
||||
# programmaticaly but will make sure git conflicts if two migrations are
|
||||
# separately added with the same number)
|
||||
SQL_LEVEL = (45, 'add index on formdata(status)')
|
||||
|
||||
|
||||
def migrate_global_views(conn, cur):
|
||||
|
@ -2815,10 +2818,12 @@ def migrate():
|
|||
set_reindex('formdata', 'needed', conn=conn, cur=cur)
|
||||
if sql_level < 36:
|
||||
from wcs.formdef import FormDef
|
||||
from wcs.carddef import CardDef
|
||||
# 24: add index on evolution(formdata_id)
|
||||
# 35: add indexes on formdata(receipt_time) and formdata(anonymised)
|
||||
# 36: add index on formdata(user_id)
|
||||
for formdef in FormDef.select():
|
||||
# 45: add index on formdata(status)
|
||||
for formdef in FormDef.select() + CardDef.select():
|
||||
do_formdef_indexes(formdef, created=False, conn=conn, cur=cur)
|
||||
if sql_level < 32:
|
||||
# 25: create session_table
|
||||
|
@ -2842,7 +2847,7 @@ def migrate():
|
|||
do_snapshots_table()
|
||||
|
||||
cur.execute('''UPDATE wcs_meta SET value = %s WHERE key = %s''', (
|
||||
str(SQL_LEVEL), 'sql_level'))
|
||||
str(SQL_LEVEL[0]), 'sql_level'))
|
||||
|
||||
conn.commit()
|
||||
cur.close()
|
||||
|
|
Loading…
Reference in New Issue