-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af3c3b5
commit 0081a69
Showing
6 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE vss_db | ||
DROP COLUMN deleted; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
ALTER TABLE vss_db | ||
ADD COLUMN deleted BOOLEAN NOT NULL DEFAULT FALSE; | ||
|
||
-- modify upsert_vss_db to set deleted to false | ||
CREATE OR REPLACE FUNCTION upsert_vss_db( | ||
p_store_id TEXT, | ||
p_key TEXT, | ||
p_value bytea, | ||
p_version BIGINT | ||
) RETURNS VOID AS | ||
$$ | ||
BEGIN | ||
|
||
WITH new_values (store_id, key, value, version) AS (VALUES (p_store_id, p_key, p_value, p_version)) | ||
INSERT | ||
INTO vss_db | ||
(store_id, key, value, version) | ||
SELECT new_values.store_id, | ||
new_values.key, | ||
new_values.value, | ||
new_values.version | ||
FROM new_values | ||
LEFT JOIN vss_db AS existing | ||
ON new_values.store_id = existing.store_id | ||
AND new_values.key = existing.key | ||
WHERE CASE | ||
WHEN new_values.version >= 4294967295 THEN new_values.version >= COALESCE(existing.version, -1) | ||
ELSE new_values.version > COALESCE(existing.version, -1) | ||
END | ||
ON CONFLICT (store_id, key) | ||
DO UPDATE SET value = excluded.value, | ||
version = excluded.version, | ||
deleted = false; | ||
|
||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
-- modified upsert_vss_db but to delete | ||
CREATE OR REPLACE FUNCTION delete_item( | ||
p_store_id TEXT, | ||
p_key TEXT, | ||
p_version BIGINT | ||
) RETURNS VOID AS | ||
$$ | ||
BEGIN | ||
|
||
WITH new_values (store_id, key, version) AS (VALUES (p_store_id, p_key, p_version)) | ||
INSERT | ||
INTO vss_db | ||
(store_id, key, version) | ||
SELECT new_values.store_id, | ||
new_values.key, | ||
new_values.version | ||
FROM new_values | ||
LEFT JOIN vss_db AS existing | ||
ON new_values.store_id = existing.store_id | ||
AND new_values.key = existing.key | ||
WHERE CASE | ||
WHEN new_values.version >= 4294967295 THEN new_values.version >= COALESCE(existing.version, -1) | ||
ELSE new_values.version > COALESCE(existing.version, -1) | ||
END | ||
ON CONFLICT (store_id, key) | ||
DO UPDATE SET value = NULL, | ||
version = excluded.version, | ||
deleted = true; | ||
|
||
END; | ||
$$ LANGUAGE plpgsql; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,6 @@ diesel::table! { | |
version -> Int8, | ||
created_date -> Timestamp, | ||
updated_date -> Timestamp, | ||
deleted -> Bool, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters