formdata: add a page_id attribute (#85091)
This commit is contained in:
parent
e7e3b99fa5
commit
2f2b996066
|
@ -2436,6 +2436,35 @@ def test_migration_86_card_uuid(pub):
|
|||
cur.close()
|
||||
|
||||
|
||||
def test_migration_formdata_page_id(pub):
|
||||
FormDef.wipe()
|
||||
formdef = FormDef()
|
||||
formdef.name = 'tests migration formdata page_id'
|
||||
formdef.fields = []
|
||||
formdef.store()
|
||||
|
||||
formdata = formdef.data_class()()
|
||||
formdata.page_id = 'xxx'
|
||||
formdata.store()
|
||||
|
||||
assert formdef.data_class().get(formdata.id).page_id == 'xxx'
|
||||
|
||||
conn, cur = sql.get_connection_and_cursor()
|
||||
cur.execute('UPDATE wcs_meta SET value = 100 WHERE key = %s', ('sql_level',))
|
||||
|
||||
# drop page_id column
|
||||
cur.execute('ALTER TABLE %s DROP COLUMN page_id' % sql.get_formdef_table_name(formdef))
|
||||
assert not column_exists_in_table(cur, sql.get_formdef_table_name(formdef), 'page_id')
|
||||
|
||||
sql.migrate()
|
||||
|
||||
assert column_exists_in_table(cur, sql.get_formdef_table_name(formdef), 'page_id')
|
||||
assert migration_level(cur) >= 101
|
||||
|
||||
conn.commit()
|
||||
cur.close()
|
||||
|
||||
|
||||
def test_logged_error_store_without_integrity_error(pub, sql_queries):
|
||||
sql.LoggedError.record('there was an error')
|
||||
|
||||
|
|
|
@ -288,6 +288,7 @@ class FormData(StorableObject):
|
|||
status = None
|
||||
anonymised = None
|
||||
page_no = 0 # page to use when restoring from draft
|
||||
page_id = None
|
||||
evolution = None
|
||||
data = None
|
||||
editable_by = None
|
||||
|
|
10
wcs/sql.py
10
wcs/sql.py
|
@ -2201,6 +2201,7 @@ class SqlDataMixin(SqlMixin):
|
|||
('receipt_time', 'timestamp'),
|
||||
('status', 'varchar'),
|
||||
('page_no', 'varchar'),
|
||||
('page_id', 'varchar'),
|
||||
('anonymised', 'timestamptz'),
|
||||
('workflow_data', 'bytea'),
|
||||
('prefilling_data', 'bytea'),
|
||||
|
@ -2427,6 +2428,8 @@ class SqlDataMixin(SqlMixin):
|
|||
sql_dict['workflow_roles_array'] = None
|
||||
if hasattr(self, 'uuid'):
|
||||
sql_dict['uuid'] = self.uuid
|
||||
if hasattr(self, 'page_id'):
|
||||
sql_dict['page_id'] = self.page_id
|
||||
for attr in ('workflow_data', 'workflow_roles', 'submission_context', 'prefilling_data'):
|
||||
if getattr(self, attr):
|
||||
sql_dict[attr] = bytearray(pickle.dumps(getattr(self, attr), protocol=2))
|
||||
|
@ -5043,7 +5046,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 = (100, 'always create translation messages table')
|
||||
SQL_LEVEL = (101, 'add page_id on formdata')
|
||||
|
||||
|
||||
def migrate_global_views(conn, cur):
|
||||
|
@ -5362,6 +5365,11 @@ def migrate():
|
|||
for formdef in CardDef.select():
|
||||
do_formdef_tables(formdef, rebuild_views=False, rebuild_global_views=False)
|
||||
|
||||
if sql_level < 101:
|
||||
# 101: add page_id to formdatas
|
||||
for formdef in FormDef.select() + CardDef.select():
|
||||
do_formdef_tables(formdef, rebuild_views=False, rebuild_global_views=False)
|
||||
|
||||
if sql_level != SQL_LEVEL[0]:
|
||||
cur.execute(
|
||||
'''UPDATE wcs_meta SET value = %s, updated_at=NOW() WHERE key = %s''',
|
||||
|
|
Loading…
Reference in New Issue