From 9ba033613589aed6597bbaf04ebc7c6c74b48e7e Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Thu, 17 Nov 2022 15:22:15 +0100 Subject: [PATCH 1/3] testdef: add new table to hold form tests (#71296) --- wcs/sql.py | 44 +++++++++++++++++++++++++++++++++++++++++++- wcs/testdef.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 wcs/testdef.py diff --git a/wcs/sql.py b/wcs/sql.py index 7c543fd49..0a3cb8ddc 100644 --- a/wcs/sql.py +++ b/wcs/sql.py @@ -1636,6 +1636,45 @@ def do_tokens_table(concurrently=False): cur.close() +def do_testdef_table(): + conn, cur = get_connection_and_cursor() + table_name = 'testdef' + + cur.execute( + '''SELECT COUNT(*) FROM information_schema.tables + WHERE table_schema = 'public' + AND table_name = %s''', + (table_name,), + ) + if cur.fetchone()[0] == 0: + cur.execute( + '''CREATE TABLE %s (id varchar PRIMARY KEY, + name varchar, + slug varchar, + object_type varchar, + object_id varchar, + data jsonb + )''' + % table_name + ) + cur.execute( + '''SELECT column_name FROM information_schema.columns + WHERE table_schema = 'public' + AND table_name = %s''', + (table_name,), + ) + existing_fields = {x[0] for x in cur.fetchall()} + + needed_fields = {x[0] for x in CustomView._table_static_fields} + + # delete obsolete fields + for field in existing_fields - needed_fields: + cur.execute('''ALTER TABLE %s DROP COLUMN %s''' % (table_name, field)) + + conn.commit() + cur.close() + + def migrate_legacy_tokens(): # store old pickle tokens in SQL for token_id in wcs.qommon.tokens.Token.keys(): @@ -4648,7 +4687,7 @@ def get_period_total( # 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 = (69, 'add auto_geoloc field') +SQL_LEVEL = (70, 'add testdef table') def migrate_global_views(conn, cur): @@ -4830,6 +4869,9 @@ def migrate(): if sql_level < 68: # 68: multilinguism TranslatableMessage.do_table() + if sql_level < 70: + # 70: create testdef table + do_testdef_table() if sql_level < 52: # 2: introduction of formdef_id in views # 5: add concerned_roles_array, is_at_endpoint and fts to views diff --git a/wcs/testdef.py b/wcs/testdef.py new file mode 100644 index 000000000..7c3db9267 --- /dev/null +++ b/wcs/testdef.py @@ -0,0 +1,28 @@ +# w.c.s. - web application for online forms +# Copyright (C) 2005-2022 Entr'ouvert +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . + +from .qommon.storage import StorableObject + + +class TestDef(StorableObject): + _names = 'testdef' + + name = '' + slug = None + object_type = None # (formdef, carddef, etc.) + object_id = None + + data = None # (json export of formdata, carddata, etc.) -- 2.35.1