Skip to content

Commit d1a14e8

Browse files
committed
fix(graph): upsert in create_function_graph — reuse existing graph by (store_id, name)
Same pattern as the store lookup above: SELECT existing graph by (store_id, name) before INSERT. Re-importing a graph with the same name returns the existing graph_id instead of hitting idx_platform_function_graphs_unique_name.
1 parent b4f6061 commit d1a14e8

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

  • pgpm/constructive-compute/deploy/schemas/constructive_compute_public/procedures/platform_create_function_graph

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,25 @@ BEGIN
3131
RETURNING id INTO v_store_id;
3232
PERFORM "constructive_platform_function_graph_public".init_empty_repo(platform_create_function_graph.database_id, v_store_id);
3333
END IF;
34-
INSERT INTO "constructive_compute_public".platform_function_graphs (
35-
database_id,
36-
store_id,
37-
name,
38-
description,
39-
context,
40-
entity_id,
41-
created_by,
42-
definitions_commit_id
43-
)
44-
VALUES
45-
(platform_create_function_graph.database_id, v_store_id, platform_create_function_graph.name, platform_create_function_graph.description, platform_create_function_graph.context, platform_create_function_graph.entity_id, platform_create_function_graph.created_by, platform_create_function_graph.definitions_commit_id)
46-
RETURNING id INTO v_graph_id;
34+
SELECT g.id
35+
FROM "constructive_compute_public".platform_function_graphs AS g
36+
WHERE
37+
g.store_id = v_store_id AND g.name = platform_create_function_graph.name INTO v_graph_id;
38+
IF v_graph_id IS NULL THEN
39+
INSERT INTO "constructive_compute_public".platform_function_graphs (
40+
database_id,
41+
store_id,
42+
name,
43+
description,
44+
context,
45+
entity_id,
46+
created_by,
47+
definitions_commit_id
48+
)
49+
VALUES
50+
(platform_create_function_graph.database_id, v_store_id, platform_create_function_graph.name, platform_create_function_graph.description, platform_create_function_graph.context, platform_create_function_graph.entity_id, platform_create_function_graph.created_by, platform_create_function_graph.definitions_commit_id)
51+
RETURNING id INTO v_graph_id;
52+
END IF;
4753
RETURN v_graph_id;
4854
END;
4955
$_PGFN_$ LANGUAGE plpgsql VOLATILE SECURITY INVOKER;

0 commit comments

Comments
 (0)