25 lines
1.2 KiB
SQL
25 lines
1.2 KiB
SQL
-- +goose Up
|
|
CREATE TABLE notification_settings (
|
|
id boolean PRIMARY KEY DEFAULT true CHECK (id),
|
|
ntfy_server text NOT NULL DEFAULT 'https://ntfy.sh',
|
|
ntfy_topic text NOT NULL DEFAULT '',
|
|
enabled boolean NOT NULL DEFAULT false,
|
|
retention_days integer NOT NULL DEFAULT 0 CHECK (retention_days >= 0),
|
|
updated_at timestamptz NOT NULL DEFAULT now()
|
|
);
|
|
INSERT INTO notification_settings DEFAULT VALUES;
|
|
|
|
DELETE FROM samples s USING samples duplicate
|
|
WHERE s.source = duplicate.source AND s.external_id = duplicate.external_id AND s.id > duplicate.id;
|
|
ALTER TABLE samples DROP CONSTRAINT samples_source_external_id_key;
|
|
ALTER TABLE samples ADD CONSTRAINT samples_device_source_external_id_key UNIQUE (device_id, source, external_id);
|
|
CREATE INDEX reports_period_idx ON reports (period_start DESC, period_end DESC);
|
|
CREATE INDEX samples_device_metric_ts_idx ON samples (device_id, metric, ts);
|
|
|
|
-- +goose Down
|
|
DROP INDEX samples_device_metric_ts_idx;
|
|
DROP INDEX reports_period_idx;
|
|
DROP TABLE notification_settings;
|
|
ALTER TABLE samples DROP CONSTRAINT samples_device_source_external_id_key;
|
|
ALTER TABLE samples ADD CONSTRAINT samples_source_external_id_key UNIQUE (source, external_id);
|