@@ -329,7 +329,7 @@ SET sql = 'CREATE TABLE credential_to_scope (
329329)'
330330WHERE type = ' table' AND name = ' credential_to_scope'
331331
332- /* Migration 2022 -05-08-00 - Add timestamp to xapi_statement */
332+ /* Migration 2023 -05-08-00 - Add timestamp to xapi_statement */
333333
334334-- :name query-xapi-statement-timestamp-exists
335335-- :command :query
@@ -348,7 +348,7 @@ ALTER TABLE xapi_statement ADD COLUMN timestamp TIMESTAMP
348348UPDATE xapi_statement SET timestamp = strftime(' %Y-%m-%dT%H:%M:%f000000Z' , json_extract(payload, ' $.timestamp' ))
349349WHERE timestamp IS NULL ;
350350
351- /* Migration 2022 -05-08-01 - Add stored to xapi_statement */
351+ /* Migration 2023 -05-08-01 - Add stored to xapi_statement */
352352
353353-- :name query-xapi-statement-stored-exists
354354-- :command :query
@@ -366,3 +366,63 @@ ALTER TABLE xapi_statement ADD COLUMN stored TIMESTAMP
366366-- :doc Backfill `xapi_statement.stored` with the values from the payload
367367UPDATE xapi_statement SET stored = strftime(' %Y-%m-%dT%H:%M:%f000000Z' , json_extract(payload, ' $.stored' ))
368368WHERE stored IS NULL ;
369+
370+
371+ /* Migration 2023-05-11-00 - Convert timestamps for consistency */
372+
373+ -- :name query-state-document-last-modified-is-timestamp
374+ -- :command :query
375+ -- :result :one
376+ -- :doc Query to see if `state_document.last_modified` is a timestamp.
377+ SELECT 1 FROM pragma_table_info(' state_document' ) WHERE name = ' last_modified' AND type = ' TIMESTAMP' ;
378+
379+ -- :name migrate-timestamps-state-01!
380+ -- :command :execute
381+ -- :doc Convert `state_document.last_modified` to timestamp - 01
382+ ALTER TABLE state_document ADD COLUMN last_modified_tmp TIMESTAMP ;
383+ -- :name migrate-timestamps-state-02!
384+ -- :command :execute
385+ -- :doc Convert `state_document.last_modified` to timestamp - 02
386+ UPDATE state_document SET last_modified_tmp = last_modified WHERE last_modified_tmp IS NULL ;
387+ -- :name migrate-timestamps-state-03!
388+ -- :command :execute
389+ -- :doc Convert `state_document.last_modified` to timestamp - 03
390+ ALTER TABLE state_document DROP COLUMN last_modified;
391+ -- :name migrate-timestamps-state-04!
392+ -- :command :execute
393+ -- :doc Convert `state_document.last_modified` to timestamp - 04
394+ ALTER TABLE state_document RENAME COLUMN last_modified_tmp TO last_modified;
395+
396+ -- :name migrate-timestamps-agent-profile-01!
397+ -- :command :execute
398+ -- :doc Convert `agent_profile_document.last_modified` to timestamp - 01
399+ ALTER TABLE agent_profile_document ADD COLUMN last_modified_tmp TIMESTAMP ;
400+ -- :name migrate-timestamps-agent-profile-02!
401+ -- :command :execute
402+ -- :doc Convert `agent_profile_document.last_modified` to timestamp - 02
403+ UPDATE agent_profile_document SET last_modified_tmp = last_modified WHERE last_modified_tmp IS NULL ;
404+ -- :name migrate-timestamps-agent-profile-03!
405+ -- :command :execute
406+ -- :doc Convert `agent_profile_document.last_modified` to timestamp - 03
407+ ALTER TABLE agent_profile_document DROP COLUMN last_modified;
408+ -- :name migrate-timestamps-agent-profile-04!
409+ -- :command :execute
410+ -- :doc Convert `agent_profile_document.last_modified` to timestamp - 04
411+ ALTER TABLE agent_profile_document RENAME COLUMN last_modified_tmp TO last_modified;
412+
413+ -- :name migrate-timestamps-activity-profile-01!
414+ -- :command :execute
415+ -- :doc Convert `activity_profile_document.last_modified` to timestamp - 01
416+ ALTER TABLE activity_profile_document ADD COLUMN last_modified_tmp TIMESTAMP ;
417+ -- :name migrate-timestamps-activity-profile-02!
418+ -- :command :execute
419+ -- :doc Convert `activity_profile_document.last_modified` to timestamp - 02
420+ UPDATE activity_profile_document SET last_modified_tmp = last_modified WHERE last_modified_tmp IS NULL ;
421+ -- :name migrate-timestamps-activity-profile-03!
422+ -- :command :execute
423+ -- :doc Convert `activity_profile_document.last_modified` to timestamp - 03
424+ ALTER TABLE activity_profile_document DROP COLUMN last_modified;
425+ -- :name migrate-timestamps-activity-profile-04!
426+ -- :command :execute
427+ -- :doc Convert `activity_profile_document.last_modified` to timestamp - 04
428+ ALTER TABLE activity_profile_document RENAME COLUMN last_modified_tmp TO last_modified;
0 commit comments