redo search tokens creation
gitea/wcs/pipeline/head There was a failure building this commit
Details
gitea/wcs/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
4b9acaa7c1
commit
1bdea59526
|
@ -445,6 +445,7 @@ class WcsPublisher(QommonPublisher):
|
|||
sql.ApplicationElement.do_table()
|
||||
sql.SearchableFormDef.do_table()
|
||||
sql.TranslatableMessage.do_table()
|
||||
sql.init_search_tokens()
|
||||
sql.do_meta_table()
|
||||
from .carddef import CardDef
|
||||
from .formdef import FormDef
|
||||
|
|
15
wcs/sql.py
15
wcs/sql.py
|
@ -95,6 +95,10 @@ SQL_TYPE_MAPPING = {
|
|||
'computed': 'jsonb',
|
||||
}
|
||||
|
||||
def _table_exists(cur, table_name):
|
||||
cur.execute("SELECT 1 FROM pg_class WHERE relname = %s;", (table_name,))
|
||||
rows = cur.fetchall()
|
||||
return len(rows) > 0;
|
||||
|
||||
class WcsPgConnection(psycopg2.extensions.connection):
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
@ -1579,7 +1583,7 @@ def do_global_views(conn, cur):
|
|||
% (name, category.id)
|
||||
)
|
||||
|
||||
init_search_tokens(cur)
|
||||
init_search_tokens_triggers(cur)
|
||||
|
||||
|
||||
def clean_global_views(conn, cur):
|
||||
|
@ -1685,10 +1689,7 @@ def init_search_tokens(conn=None, cur=None):
|
|||
own_cur = True
|
||||
conn, cur = get_connection_and_cursor()
|
||||
|
||||
cur.execute("SELECT 1 FROM pg_class WHERE relname = 'wcs_search_tokens';")
|
||||
rows = cur.fetchall()
|
||||
if len(rows) == 1:
|
||||
# table already exists, nothing to do.
|
||||
if _table_exists(cur, 'wcs_search_tokens'):
|
||||
if own_cur:
|
||||
cur.close()
|
||||
return
|
||||
|
@ -1738,6 +1739,10 @@ def init_search_tokens_triggers(cur):
|
|||
# Instead, a weekly cron job will delete obsolete entries, thus making it sure no
|
||||
# personal data is kept uselessly.
|
||||
|
||||
if not(_table_exists(cur, 'wcs_search_tokens')):
|
||||
# abort trigger creation if tokens table doesn't exist yet
|
||||
return
|
||||
|
||||
# First part: the appending function
|
||||
cur.execute("""CREATE OR REPLACE FUNCTION wcs_search_tokens_trigger_fn ()
|
||||
RETURNS trigger
|
||||
|
|
Loading…
Reference in New Issue