-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: persist protocols sets and fix hanging context
- Loading branch information
Showing
8 changed files
with
155 additions
and
34 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
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
2 changes: 2 additions & 0 deletions
2
db/migrations/000019_add_protocols_to_requests_table.down.sql
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 requests | ||
DROP COLUMN IF EXISTS protocols_set_id; |
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,7 @@ | ||
BEGIN; | ||
|
||
ALTER TABLE requests | ||
ADD COLUMN protocols_set_id INT, | ||
ADD CONSTRAINT fk_requests_protocols_set_id FOREIGN KEY (protocols_set_id) REFERENCES protocols_sets (id) ON DELETE SET NULL; | ||
|
||
COMMIT; |
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,5 @@ | ||
BEGIN; | ||
|
||
DROP FUNCTION IF EXISTS insert_request; | ||
|
||
COMMIT; |
59 changes: 59 additions & 0 deletions
59
db/migrations/000020_alter_insert_requests_function.up.sql
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,59 @@ | ||
BEGIN; | ||
|
||
CREATE OR REPLACE FUNCTION insert_request( | ||
new_timestamp TIMESTAMPTZ, | ||
new_request_type message_type, | ||
new_ant TEXT, | ||
new_multi_hash TEXT, | ||
new_key_multi_hash TEXT, | ||
new_multi_addresses TEXT[], | ||
new_agent_version_id INT, | ||
new_protocols_set_id INT | ||
) RETURNS RECORD AS | ||
$insert_request$ | ||
DECLARE | ||
new_multi_addresses_ids INT[]; | ||
new_request_id INT; | ||
new_peer_id INT; | ||
new_ant_id INT; | ||
new_key_id INT; | ||
BEGIN | ||
SELECT upsert_peer( | ||
new_multi_hash, | ||
new_agent_version_id, | ||
new_protocols_set_id, | ||
new_timestamp | ||
) INTO new_peer_id; | ||
|
||
SELECT id INTO new_ant_id | ||
FROM peers | ||
WHERE multi_hash = new_ant; | ||
|
||
SELECT insert_key(new_key_multi_hash) INTO new_key_id; | ||
|
||
SELECT array_agg(id) FROM upsert_multi_addresses(new_multi_addresses) INTO new_multi_addresses_ids; | ||
|
||
DELETE | ||
FROM peers_x_multi_addresses pxma | ||
WHERE peer_id = new_peer_id; | ||
|
||
INSERT INTO peers_x_multi_addresses (peer_id, multi_address_id) | ||
SELECT new_peer_id, new_multi_address_id | ||
FROM unnest(new_multi_addresses_ids) new_multi_address_id | ||
ON CONFLICT DO NOTHING; | ||
|
||
INSERT INTO requests (timestamp, request_type, ant_id, peer_id, key_id, multi_address_ids, protocols_set_id) | ||
SELECT new_timestamp, | ||
new_request_type, | ||
new_ant_id, | ||
new_peer_id, | ||
new_key_id, | ||
new_multi_addresses_ids, | ||
new_protocols_set_id | ||
RETURNING id INTO new_request_id; | ||
|
||
RETURN ROW(new_peer_id, new_request_id, new_key_id); | ||
END; | ||
$insert_request$ LANGUAGE plpgsql; | ||
|
||
COMMIT; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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