Skip to content

Commit ab734c0

Browse files
committed
fix: upsert store in platform_create_function_graph — reuse existing store by (database_id, name)
1 parent e9be48c commit ab734c0

2 files changed

Lines changed: 32 additions & 16 deletions

File tree

pgpm/constructive-compute/deploy/schemas/constructive_compute_public/procedures/platform_create_function_graph/procedure.sql

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,22 @@ DECLARE
1717
v_store_id uuid;
1818
v_graph_id uuid;
1919
BEGIN
20-
INSERT INTO "constructive_platform_function_graph_public".platform_function_graph_store (
21-
database_id,
22-
name
23-
)
24-
VALUES
25-
(platform_create_function_graph.database_id, platform_create_function_graph.name)
26-
RETURNING id INTO v_store_id;
27-
PERFORM "constructive_platform_function_graph_public".init_empty_repo(platform_create_function_graph.database_id, v_store_id);
20+
SELECT id
21+
FROM "constructive_platform_function_graph_public".platform_function_graph_store
22+
WHERE
23+
database_id = platform_create_function_graph.database_id
24+
AND name = platform_create_function_graph.name
25+
INTO v_store_id;
26+
IF v_store_id IS NULL THEN
27+
INSERT INTO "constructive_platform_function_graph_public".platform_function_graph_store (
28+
database_id,
29+
name
30+
)
31+
VALUES
32+
(platform_create_function_graph.database_id, platform_create_function_graph.name)
33+
RETURNING id INTO v_store_id;
34+
PERFORM "constructive_platform_function_graph_public".init_empty_repo(platform_create_function_graph.database_id, v_store_id);
35+
END IF;
2836
INSERT INTO "constructive_compute_public".platform_function_graphs (
2937
database_id,
3038
store_id,

pgpm/constructive-compute/sql/constructive-compute--0.0.1.sql

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -842,14 +842,22 @@ DECLARE
842842
v_store_id uuid;
843843
v_graph_id uuid;
844844
BEGIN
845-
INSERT INTO "constructive_platform_function_graph_public".platform_function_graph_store (
846-
database_id,
847-
name
848-
)
849-
VALUES
850-
(platform_create_function_graph.database_id, platform_create_function_graph.name)
851-
RETURNING id INTO v_store_id;
852-
PERFORM "constructive_platform_function_graph_public".init_empty_repo(platform_create_function_graph.database_id, v_store_id);
845+
SELECT id
846+
FROM "constructive_platform_function_graph_public".platform_function_graph_store
847+
WHERE
848+
database_id = platform_create_function_graph.database_id
849+
AND name = platform_create_function_graph.name
850+
INTO v_store_id;
851+
IF v_store_id IS NULL THEN
852+
INSERT INTO "constructive_platform_function_graph_public".platform_function_graph_store (
853+
database_id,
854+
name
855+
)
856+
VALUES
857+
(platform_create_function_graph.database_id, platform_create_function_graph.name)
858+
RETURNING id INTO v_store_id;
859+
PERFORM "constructive_platform_function_graph_public".init_empty_repo(platform_create_function_graph.database_id, v_store_id);
860+
END IF;
853861
INSERT INTO "constructive_compute_public".platform_function_graphs (
854862
database_id,
855863
store_id,

0 commit comments

Comments
 (0)