sql: add fts column to aggregation views (#7926)
This commit is contained in:
parent
fb32cc5f38
commit
2b41e9e1da
|
@ -46,6 +46,7 @@ réservé aux usages internes.
|
|||
<item><p><var>is_at_endpoint</var> : indicateur de fin de traitement</p></item>
|
||||
<item><p><var>category_id</var> : identifiant de la catégorie</p></item>
|
||||
<item><p><var>formdef_id</var> : identifiant du type de formulaire</p></item>
|
||||
<item><p><var>fts</var> : indexation texte intégral</p></item>
|
||||
</list>
|
||||
|
||||
<p>
|
||||
|
|
|
@ -835,3 +835,30 @@ def test_is_at_endpoint():
|
|||
assert [x.id for x in wf.get_endpoint_status()] == ['st1', 'st2']
|
||||
cur.execute('''SELECT COUNT(*) FROM wcs_all_forms WHERE is_at_endpoint = true''')
|
||||
assert bool(cur.fetchone()[0] == 2)
|
||||
|
||||
@postgresql
|
||||
def test_views_fts():
|
||||
drop_formdef_tables()
|
||||
conn, cur = sql.get_connection_and_cursor()
|
||||
|
||||
formdef = FormDef()
|
||||
formdef.name = 'test fts'
|
||||
formdef.fields = [
|
||||
fields.StringField(id='0', label='string'),
|
||||
]
|
||||
formdef.store()
|
||||
|
||||
data_class = formdef.data_class(mode='sql')
|
||||
formdata1 = data_class()
|
||||
formdata1.data = {'0': 'foo bar'}
|
||||
formdata1.store()
|
||||
|
||||
formdata2 = data_class()
|
||||
formdata2.data = {'0': 'foo'}
|
||||
formdata2.store()
|
||||
|
||||
cur.execute('''SELECT COUNT(*) FROM wcs_all_forms WHERE fts @@ plainto_tsquery(%s)''', ('foo',))
|
||||
assert bool(cur.fetchone()[0] == 2)
|
||||
|
||||
cur.execute('''SELECT COUNT(*) FROM wcs_all_forms WHERE fts @@ plainto_tsquery(%s)''', ('bar',))
|
||||
assert bool(cur.fetchone()[0] == 1)
|
||||
|
|
|
@ -577,6 +577,7 @@ def do_views(formdef, conn, cur, rebuild_global_views=True):
|
|||
'''is_at_endpoint'''))
|
||||
|
||||
view_fields.append(('concerned_roles_array', 'concerned_roles_array'))
|
||||
view_fields.append(('fts', 'fts'))
|
||||
|
||||
fields_list = ', '.join(['%s AS %s' % x for x in view_fields])
|
||||
|
||||
|
@ -620,6 +621,7 @@ def do_global_views(conn, cur):
|
|||
fake_formdef = FormDef()
|
||||
common_fields = get_view_fields(fake_formdef)
|
||||
common_fields.append(('concerned_roles_array', 'concerned_roles_array'))
|
||||
common_fields.append(('fts', 'fts'))
|
||||
common_fields.append(('is_at_endpoint', 'is_at_endpoint'))
|
||||
|
||||
union = ' UNION '.join(['''SELECT %s FROM %s''' % (
|
||||
|
@ -1634,7 +1636,8 @@ def migrate():
|
|||
# 3: introduction of _structured for user fields
|
||||
# 4: removal of identification_token
|
||||
do_user_table()
|
||||
if sql_level < 5: # 5: add concerned_roles_array and is_at_endpoint to views
|
||||
if sql_level < 5:
|
||||
# 5: add concerned_roles_array, is_at_endpoint and fts to views
|
||||
migrate_views(conn, cur)
|
||||
|
||||
cur.execute('''UPDATE wcs_meta SET value = %s WHERE key = %s''', (
|
||||
|
|
Loading…
Reference in New Issue