Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor all Analytics Module's Postgres queries to replace DELETE queries with INSERT and SELECT #226

Merged
merged 3 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
9 changes: 7 additions & 2 deletions DSL/Resql/delete-odp-settings.sql
Original file line number Diff line number Diff line change
@@ -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_%'
14 changes: 13 additions & 1 deletion DSL/Resql/delete-scheduled-report.sql
Original file line number Diff line number Diff line change
@@ -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;
13 changes: 12 additions & 1 deletion DSL/Resql/get-scheduled-report.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
SELECT *
SELECT
id,
name,
dataset_id,
period,
metrics,
created,
updated,
start_date,
end_date
FROM scheduled_reports
WHERE dataset_id = :datasetId
ORDER BY id DESC
LIMIT 1;
18 changes: 17 additions & 1 deletion DSL/Resql/get-scheduled-reports.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
SELECT *
WITH MaxReports AS (
SELECT MAX(id) maxId
FROM scheduled_reports
GROUP BY dataset_id
)
SELECT
id,
name,
dataset_id,
period,
metrics,
created,
updated,
start_date,
end_date
FROM scheduled_reports
JOIN MaxReports on id = maxId
WHERE NOT deleted;