Projet

Général

Profil

0001-testdata-add-new-table-to-hold-form-tests-71296.patch

Valentin Deniaud, 17 novembre 2022 15:59

Télécharger (3,93 ko)

Voir les différences:

Subject: [PATCH 1/2] testdata: add new table to hold form tests (#71296)

 wcs/sql.py      | 44 +++++++++++++++++++++++++++++++++++++++++++-
 wcs/testdata.py | 31 +++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+), 1 deletion(-)
 create mode 100644 wcs/testdata.py
wcs/sql.py
1622 1622
    cur.close()
1623 1623

  
1624 1624

  
1625
def do_testdata_table():
1626
    conn, cur = get_connection_and_cursor()
1627
    table_name = 'testdata'
1628

  
1629
    cur.execute(
1630
        '''SELECT COUNT(*) FROM information_schema.tables
1631
                    WHERE table_schema = 'public'
1632
                      AND table_name = %s''',
1633
        (table_name,),
1634
    )
1635
    if cur.fetchone()[0] == 0:
1636
        cur.execute(
1637
            '''CREATE TABLE %s (id varchar PRIMARY KEY,
1638
                                        name varchar,
1639
                                        slug varchar,
1640
                                        object_type varchar,
1641
                                        object_id varchar,
1642
                                        formdata jsonb
1643
                                        )'''
1644
            % table_name
1645
        )
1646
    cur.execute(
1647
        '''SELECT column_name FROM information_schema.columns
1648
                    WHERE table_schema = 'public'
1649
                      AND table_name = %s''',
1650
        (table_name,),
1651
    )
1652
    existing_fields = {x[0] for x in cur.fetchall()}
1653

  
1654
    needed_fields = {x[0] for x in CustomView._table_static_fields}
1655

  
1656
    # delete obsolete fields
1657
    for field in existing_fields - needed_fields:
1658
        cur.execute('''ALTER TABLE %s DROP COLUMN %s''' % (table_name, field))
1659

  
1660
    conn.commit()
1661
    cur.close()
1662

  
1663

  
1625 1664
def migrate_legacy_tokens():
1626 1665
    # store old pickle tokens in SQL
1627 1666
    for token_id in wcs.qommon.tokens.Token.keys():
......
4462 4501
# latest migration, number + description (description is not used
4463 4502
# programmaticaly but will make sure git conflicts if two migrations are
4464 4503
# separately added with the same number)
4465
SQL_LEVEL = (67, 're-migrate legacy tokens')
4504
SQL_LEVEL = (68, 'add testdata table')
4466 4505

  
4467 4506

  
4468 4507
def migrate_global_views(conn, cur):
......
4741 4780
        init_global_table(conn, cur)
4742 4781
        for formdef in FormDef.select():
4743 4782
            do_formdef_tables(formdef, rebuild_views=False, rebuild_global_views=False)
4783
    if sql_level < 68:
4784
        # 68: create testdata table
4785
        do_testdata_table()
4744 4786

  
4745 4787
    if sql_level != SQL_LEVEL[0]:
4746 4788
        cur.execute(
wcs/testdata.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 TestData(StorableObject):
21
    _names = 'testdata'
22

  
23
    name = None
24
    slug = None
25
    object_type = None  # (formdef, carddef, etc.)
26
    object_id = None
27

  
28
    data = None  # (json export of formdata, carddata, etc.)
29

  
30
    def __str__(self):
31
        return self.name
0
-