sql: get carddef/formdef table fields from data_class (#73674)

This commit is contained in:
Frédéric Péters 2022-09-06 16:20:22 +02:00 committed by Gitea
parent bd497d9e57
commit 484ef75682
1 changed files with 7 additions and 34 deletions

View File

@ -774,37 +774,8 @@ def do_formdef_tables(formdef, conn=None, cur=None, rebuild_views=False, rebuild
)
existing_fields = {x[0] for x in cur.fetchall()}
needed_fields = {
'id',
'user_id',
'receipt_time',
'status',
'workflow_data',
'id_display',
'fts',
'page_no',
'anonymised',
'workflow_roles',
# workflow_merged_roles_dict combines workflow_roles from formdef and
# formdata and is used to filter on function assignment.
'workflow_merged_roles_dict',
# workflow_roles_array is created from workflow_roles to be used in
# get_ids_with_indexed_value
'workflow_roles_array',
'concerned_roles_array',
'tracking_code',
'actions_roles_array',
'backoffice_submission',
'submission_context',
'submission_agent_id',
'submission_channel',
'criticality_level',
'last_update_time',
'digests',
'user_label',
'prefilling_data',
'auto_geoloc',
}
needed_fields = {x[0] for x in formdef.data_class()._table_static_fields}
needed_fields.add('fts')
# migrations
if 'fts' not in existing_fields:
@ -860,9 +831,6 @@ def do_formdef_tables(formdef, conn=None, cur=None, rebuild_views=False, rebuild
if 'prefilling_data' not in existing_fields:
cur.execute('''ALTER TABLE %s ADD COLUMN prefilling_data bytea''' % table_name)
if 'auto_geoloc' not in existing_fields:
cur.execute('''ALTER TABLE %s ADD COLUMN auto_geoloc POINT''' % table_name)
# add new fields
for field in formdef.get_all_fields():
assert field.id is not None
@ -2548,7 +2516,11 @@ class SqlDataMixin(SqlMixin):
('prefilling_data', 'bytea'),
('id_display', 'varchar'),
('workflow_roles', 'bytea'),
# workflow_merged_roles_dict combines workflow_roles from formdef and
# formdata and is used to filter on function assignment.
('workflow_merged_roles_dict', 'jsonb'),
# workflow_roles_array is created from workflow_roles to be used in
# get_ids_with_indexed_value
('workflow_roles_array', 'text[]'),
('concerned_roles_array', 'text[]'),
('actions_roles_array', 'text[]'),
@ -2561,6 +2533,7 @@ class SqlDataMixin(SqlMixin):
('last_update_time', 'timestamp'),
('digests', 'jsonb'),
('user_label', 'varchar'),
('auto_geoloc', 'point'),
]
def __init__(self, id=None):