Skip to content

Commit

Permalink
fix: backup unique constraint (#795)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Shaw authored Dec 15, 2021
1 parent a98b390 commit b19790f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
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

0 comments on commit b19790f

Please sign in to comment.