diff --git a/DSL/Liquibase/changelog/1715604012-add-deleted-to-scheduled_reports.sql b/DSL/Liquibase/changelog/1715604012-add-deleted-to-scheduled_reports.sql new file mode 100644 index 00000000..49b3aa65 --- /dev/null +++ b/DSL/Liquibase/changelog/1715604012-add-deleted-to-scheduled_reports.sql @@ -0,0 +1,4 @@ +-- liquibase formatted sql +-- changeset baha-a:1715604012 +ALTER TABLE scheduled_reports +ADD COLUMN IF NOT EXISTS deleted boolean NOT NULL DEFAULT FALSE; diff --git a/DSL/Resql/delete-odp-settings.sql b/DSL/Resql/delete-odp-settings.sql index 19a2a836..167adf4d 100644 --- a/DSL/Resql/delete-odp-settings.sql +++ b/DSL/Resql/delete-odp-settings.sql @@ -1,2 +1,7 @@ -DELETE FROM "configuration" -WHERE "key" LIKE 'odp_%'; +INSERT INTO configuration (key, value, deleted) +SELECT + key, + NULL AS value, + TRUE AS deleted +FROM configuration +WHERE key LIKE 'odp_%' diff --git a/DSL/Resql/delete-scheduled-report.sql b/DSL/Resql/delete-scheduled-report.sql index cddb1620..6c5a3997 100644 --- a/DSL/Resql/delete-scheduled-report.sql +++ b/DSL/Resql/delete-scheduled-report.sql @@ -1 +1,13 @@ -DELETE FROM scheduled_reports WHERE dataset_id = :id +INSERT INTO scheduled_reports (name, period, metrics, dataset_id, start_date, end_date, deleted) +SELECT + name, + period, + metrics, + dataset_id, + start_date, + end_date, + TRUE +FROM scheduled_reports +WHERE dataset_id = :id +ORDER BY id DESC +LIMIT 1; diff --git a/DSL/Resql/get-scheduled-report.sql b/DSL/Resql/get-scheduled-report.sql index fe424684..a13d8408 100644 --- a/DSL/Resql/get-scheduled-report.sql +++ b/DSL/Resql/get-scheduled-report.sql @@ -9,4 +9,6 @@ SELECT start_date, end_date FROM scheduled_reports -WHERE dataset_id = :datasetId; +WHERE dataset_id = :datasetId +ORDER BY id DESC +LIMIT 1; diff --git a/DSL/Resql/get-scheduled-reports.sql b/DSL/Resql/get-scheduled-reports.sql index 602d0940..78f0d0e9 100644 --- a/DSL/Resql/get-scheduled-reports.sql +++ b/DSL/Resql/get-scheduled-reports.sql @@ -1,3 +1,8 @@ +WITH MaxReports AS ( + SELECT MAX(id) AS maxId + FROM scheduled_reports + GROUP BY dataset_id +) SELECT id, name, @@ -8,4 +13,6 @@ SELECT updated, start_date, end_date -FROM scheduled_reports; +FROM scheduled_reports +JOIN MaxReports ON id = maxId +WHERE NOT deleted; \ No newline at end of file