0001-sql-add-a-last_update_time-column-to-views-8886.patch
tests/test_sql.py | ||
---|---|---|
1001 | 1001 |
formdatas = sql.AnyFormData.select(criterias) |
1002 | 1002 |
assert total_count == 1 |
1003 | 1003 |
assert formdatas[0].id == formdata_id |
1004 | ||
1005 |
@postgresql |
|
1006 |
def test_last_update_time(): |
|
1007 |
drop_formdef_tables() |
|
1008 |
conn, cur = sql.get_connection_and_cursor() |
|
1009 | ||
1010 |
wf = Workflow(name='test last update time') |
|
1011 |
st1 = wf.add_status('Status1', 'st1') |
|
1012 | ||
1013 |
commentable = CommentableWorkflowStatusItem() |
|
1014 |
commentable.id = '_commentable' |
|
1015 |
commentable.by = ['_submitter', '_receiver'] |
|
1016 |
st1.items.append(commentable) |
|
1017 |
commentable.parent = st1 |
|
1018 |
wf.store() |
|
1019 | ||
1020 |
formdef = FormDef() |
|
1021 |
formdef.name = 'test last update time' |
|
1022 |
formdef.fields = [] |
|
1023 |
formdef.workflow = wf |
|
1024 |
formdef.store() |
|
1025 | ||
1026 |
data_class = formdef.data_class(mode='sql') |
|
1027 |
formdata1 = data_class() |
|
1028 |
formdata1.status = 'wf-st1' |
|
1029 |
formdata1.just_created() |
|
1030 |
formdata1.jump_status('st1') # will add another evolution entry |
|
1031 |
formdata1.evolution[0].time = datetime.datetime(2015, 1, 1, 0, 0, 0).timetuple() |
|
1032 |
formdata1.evolution[1].time = datetime.datetime(2015, 1, 2, 0, 0, 0).timetuple() |
|
1033 |
formdata1.store() |
|
1034 | ||
1035 |
formdata2 = data_class() |
|
1036 |
formdata2.status = 'wf-st1' |
|
1037 |
formdata2.just_created() |
|
1038 |
formdata2.jump_status('st1') # will add another evolution entry |
|
1039 |
formdata2.evolution[0].time = datetime.datetime(2015, 1, 3, 0, 0, 0).timetuple() |
|
1040 |
formdata2.evolution[1].time = datetime.datetime(2015, 1, 4, 0, 0, 0).timetuple() |
|
1041 |
formdata2.store() |
|
1042 | ||
1043 |
cur.execute('''SELECT COUNT(*) FROM wcs_all_forms''') |
|
1044 |
assert bool(cur.fetchone()[0] == 2) |
|
1045 | ||
1046 |
cur.execute('''SELECT id FROM wcs_all_forms WHERE last_update_time = '2015-01-02 00:00' ''') |
|
1047 |
assert bool(cur.fetchone()[0] == formdata1.id) |
|
1048 | ||
1049 |
cur.execute('''SELECT id FROM wcs_all_forms WHERE last_update_time = '2015-01-04 00:00' ''') |
|
1050 |
assert bool(cur.fetchone()[0] == formdata2.id) |
wcs/sql.py | ||
---|---|---|
589 | 589 |
', '.join(["'wf-%s'" % x.id for x in endpoint_status]), |
590 | 590 |
'''is_at_endpoint''')) |
591 | 591 | |
592 |
view_fields.append(('''(SELECT MAX(time) FROM %s_evolutions ''' |
|
593 |
''' WHERE %s.id = %s_evolutions.formdata_id)''' % ( |
|
594 |
(table_name, )*3), |
|
595 |
'last_update_time')) |
|
596 | ||
592 | 597 |
view_fields.append(('concerned_roles_array', 'concerned_roles_array')) |
593 | 598 |
view_fields.append(('actions_roles_array', 'actions_roles_array')) |
594 | 599 |
view_fields.append(('fts', 'fts')) |
... | ... | |
638 | 643 |
common_fields.append(('actions_roles_array', 'actions_roles_array')) |
639 | 644 |
common_fields.append(('fts', 'fts')) |
640 | 645 |
common_fields.append(('is_at_endpoint', 'is_at_endpoint')) |
646 |
common_fields.append(('last_update_time', 'last_update_time')) |
|
641 | 647 | |
642 | 648 |
union = ' UNION '.join(['''SELECT %s FROM %s''' % ( |
643 | 649 |
', '.join([y[1] for y in common_fields]), x) for x in view_names]) |
... | ... | |
1078 | 1084 |
if hasattr(evo, '_sql_id'): |
1079 | 1085 |
sql_dict.update({'id': evo._sql_id}) |
1080 | 1086 |
sql_statement = '''UPDATE %s_evolutions SET |
1087 |
time = %%(time)s, |
|
1088 |
status = %%(status)s, |
|
1081 | 1089 |
comment = %%(comment)s, |
1082 | 1090 |
parts = %%(parts)s |
1083 | 1091 |
WHERE id = %%(id)s |
... | ... | |
1720 | 1728 |
migrate_views(conn, cur) |
1721 | 1729 |
for formdef in FormDef.select(): |
1722 | 1730 |
formdef.data_class().rebuild_security() |
1723 |
if sql_level < 8:
|
|
1731 |
if sql_level < 9:
|
|
1724 | 1732 |
# 7: add backoffice_submission to tables and views |
1725 | 1733 |
# 8: add submission_context to tables |
1734 |
# 9: add last_update_time to views |
|
1726 | 1735 |
migrate_views(conn, cur) |
1727 | 1736 | |
1728 | 1737 |
cur.execute('''UPDATE wcs_meta SET value = %s WHERE key = %s''', ( |
1729 |
- |