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

fix: backup unique constraint #795

Merged
merged 1 commit into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion packages/db/postgres/functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ BEGIN
values (inserted_upload_id,
backup_url,
(data ->> 'inserted_at')::timestamptz)
ON CONFLICT ( url ) DO NOTHING;
ON CONFLICT ( upload_id, url ) DO NOTHING;
end loop;

return (inserted_upload_id)::TEXT;
Expand Down
5 changes: 3 additions & 2 deletions packages/db/postgres/tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ CREATE TABLE IF NOT EXISTS backup
-- Upload that resulted in this backup.
upload_id BIGINT NOT NULL REFERENCES upload (id) ON DELETE CASCADE,
-- Backup url location.
url TEXT NOT NULL UNIQUE,
inserted_at TIMESTAMP WITH TIME ZONE DEFAULT timezone('utc'::text, now()) NOT NULL
url TEXT NOT NULL,
inserted_at TIMESTAMP WITH TIME ZONE DEFAULT timezone('utc'::text, now()) NOT NULL,
UNIQUE (upload_id, url)
);

CREATE INDEX IF NOT EXISTS backup_upload_id_idx ON backup (upload_id);
Expand Down