0001-testdef-add-new-table-to-hold-form-tests-71296.patch
wcs/sql.py | ||
---|---|---|
1636 | 1636 |
cur.close() |
1637 | 1637 | |
1638 | 1638 | |
1639 |
def do_testdef_table(): |
|
1640 |
conn, cur = get_connection_and_cursor() |
|
1641 |
table_name = 'testdef' |
|
1642 | ||
1643 |
cur.execute( |
|
1644 |
'''SELECT COUNT(*) FROM information_schema.tables |
|
1645 |
WHERE table_schema = 'public' |
|
1646 |
AND table_name = %s''', |
|
1647 |
(table_name,), |
|
1648 |
) |
|
1649 |
if cur.fetchone()[0] == 0: |
|
1650 |
cur.execute( |
|
1651 |
'''CREATE TABLE %s (id varchar PRIMARY KEY, |
|
1652 |
name varchar, |
|
1653 |
slug varchar, |
|
1654 |
object_type varchar, |
|
1655 |
object_id varchar, |
|
1656 |
data jsonb |
|
1657 |
)''' |
|
1658 |
% table_name |
|
1659 |
) |
|
1660 |
cur.execute( |
|
1661 |
'''SELECT column_name FROM information_schema.columns |
|
1662 |
WHERE table_schema = 'public' |
|
1663 |
AND table_name = %s''', |
|
1664 |
(table_name,), |
|
1665 |
) |
|
1666 |
existing_fields = {x[0] for x in cur.fetchall()} |
|
1667 | ||
1668 |
needed_fields = {x[0] for x in CustomView._table_static_fields} |
|
1669 | ||
1670 |
# delete obsolete fields |
|
1671 |
for field in existing_fields - needed_fields: |
|
1672 |
cur.execute('''ALTER TABLE %s DROP COLUMN %s''' % (table_name, field)) |
|
1673 | ||
1674 |
conn.commit() |
|
1675 |
cur.close() |
|
1676 | ||
1677 | ||
1639 | 1678 |
def migrate_legacy_tokens(): |
1640 | 1679 |
# store old pickle tokens in SQL |
1641 | 1680 |
for token_id in wcs.qommon.tokens.Token.keys(): |
... | ... | |
4648 | 4687 |
# latest migration, number + description (description is not used |
4649 | 4688 |
# programmaticaly but will make sure git conflicts if two migrations are |
4650 | 4689 |
# separately added with the same number) |
4651 |
SQL_LEVEL = (69, 'add auto_geoloc field')
|
|
4690 |
SQL_LEVEL = (70, 'add testdef table')
|
|
4652 | 4691 | |
4653 | 4692 | |
4654 | 4693 |
def migrate_global_views(conn, cur): |
... | ... | |
4830 | 4869 |
if sql_level < 68: |
4831 | 4870 |
# 68: multilinguism |
4832 | 4871 |
TranslatableMessage.do_table() |
4872 |
if sql_level < 70: |
|
4873 |
# 70: create testdef table |
|
4874 |
do_testdef_table() |
|
4833 | 4875 |
if sql_level < 52: |
4834 | 4876 |
# 2: introduction of formdef_id in views |
4835 | 4877 |
# 5: add concerned_roles_array, is_at_endpoint and fts to views |
wcs/testdef.py | ||
---|---|---|
1 |
# w.c.s. - web application for online forms |
|
2 |
# Copyright (C) 2005-2022 Entr'ouvert |
|
3 |
# |
|
4 |
# This program is free software; you can redistribute it and/or modify |
|
5 |
# it under the terms of the GNU General Public License as published by |
|
6 |
# the Free Software Foundation; either version 2 of the License, or |
|
7 |
# (at your option) any later version. |
|
8 |
# |
|
9 |
# This program is distributed in the hope that it will be useful, |
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
# GNU General Public License for more details. |
|
13 |
# |
|
14 |
# You should have received a copy of the GNU General Public License |
|
15 |
# along with this program; if not, see <http://www.gnu.org/licenses/>. |
|
16 | ||
17 |
from .qommon.storage import StorableObject |
|
18 | ||
19 | ||
20 |
class TestDef(StorableObject): |
|
21 |
_names = 'testdef' |
|
22 | ||
23 |
name = '' |
|
24 |
slug = None |
|
25 |
object_type = None # (formdef, carddef, etc.) |
|
26 |
object_id = None |
|
27 | ||
28 |
data = None # (json export of formdata, carddata, etc.) |
|
0 |
- |