diff --git a/src/main/resources/db/migration/V10__replace_templates_with_dataqueries.sql b/src/main/resources/db/migration/V10__replace_templates_with_dataqueries.sql index 6c535547..30f367da 100644 --- a/src/main/resources/db/migration/V10__replace_templates_with_dataqueries.sql +++ b/src/main/resources/db/migration/V10__replace_templates_with_dataqueries.sql @@ -1,7 +1,3 @@ --- Not sure if we can just drop the old tables for templates and saved queries or if we have to migrate them first --- drop table query_template; --- drop table saved_query; - CREATE TABLE dataquery ( id SERIAL PRIMARY KEY, @@ -11,4 +7,29 @@ CREATE TABLE dataquery crtdl TEXT, last_modified TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, result_size INTEGER -); \ No newline at end of file +); + +insert into dataquery (created_by, label, comment, crtdl, last_modified, result_size) +select q.created_by, + sq.label, + sq.comment, + CONCAT('{"version":null,"display":"","cohortDefinition":', qc.query_content, ',"dataExtraction":null}'), + q.created_at, + sq.result_size +from saved_query sq + left join query q on sq.query_id = q.id + left join query_content qc on q.query_content_id = qc.id ; + +insert into dataquery (created_by, label, comment, crtdl, last_modified) +select q.created_by, + qt.label, + qt.comment, + CONCAT('{"version":null,"display":"","cohortDefinition":', qc.query_content, ',"dataExtraction":null}'), + q.created_at +from query_template qt + left join query q on qt.query_id = q.id + left join query_content qc on q.query_content_id = qc.id ; + +-- Not sure if we should already delete those tables or wait for the next release to check if everything was converted as expected +-- drop table query_template; +-- drop table saved_query; \ No newline at end of file