Skip to content

Commit 4a37b00

Browse files
jnasbyupgradeclaude
andcommitted
Re-add capture__start(object_group_id) to the update script
The earlier removal of this re-declaration assumed 0.1.0's body and current source were byte-identical for this function. They aren't: 0.1.0 still has a dead, commented-out CREATE TEMP TABLE ... AS attempt in the EXCEPTION handler that current source has since dropped. Functionally inert either way, but pg_get_functiondef() returns comments verbatim, so an updated install's function body would literally differ from a fresh install's -- caught by bin/test_existing's structural diff (planted expressly to catch this class of divergence). Recreated with the current, comment-free body; confirmed structurally identical to a fresh install afterward. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 035c60d commit 4a37b00

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

sql/object_reference--0.1.0--stable.sql

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,60 @@ CREATE EVENT TRIGGER drop
648648
;
649649
$$);
650650

651+
/*
652+
* object_reference.capture__start(object_group_id): 0.1.0's body still has
653+
* a dead, commented-out CREATE TEMP TABLE ... AS attempt inside the
654+
* EXCEPTION handler that current source has since dropped -- functionally
655+
* inert either way, but pg_get_functiondef() returns comments verbatim, so
656+
* leaving it in place would make an updated install's function body
657+
* literally differ from a fresh install's (caught by this repo's own
658+
* fresh-vs-updated structural diff). Recreated here with the current,
659+
* comment-free body; the other overload (capture__start(object_group_name),
660+
* a thin wrapper) is untouched between 0.1.0 and current source and does
661+
* not need recreating.
662+
*/
663+
SELECT __object_reference.create_function(
664+
'object_reference.capture__start'
665+
, $args$
666+
object_group_id _object_reference.object_group.object_group_id%TYPE
667+
$args$
668+
, 'int SECURITY DEFINER LANGUAGE plpgsql'
669+
, $body$
670+
DECLARE
671+
c_next_level int := coalesce(capture_level, 0) + 1 FROM object_reference.capture__get_current();
672+
BEGIN
673+
-- Ensure object group exists
674+
PERFORM object_reference.object_group__get(object_group_id);
675+
676+
INSERT INTO pg_temp.__object_reference__ddl_capture
677+
SELECT c_next_level, capture__start.object_group_id
678+
;
679+
RETURN c_next_level;
680+
681+
EXCEPTION WHEN undefined_table THEN
682+
CREATE TEMP TABLE __object_reference__ddl_capture(
683+
capture_level int PRIMARY KEY
684+
, object_group_id INT NOT NULL -- temp tables can't reference permanent ones
685+
);
686+
-- This breaks if run directly under plpgsql
687+
EXECUTE $code$
688+
CREATE CONSTRAINT TRIGGER verify_capture_stop AFTER INSERT
689+
ON pg_temp.__object_reference__ddl_capture
690+
DEFERRABLE INITIALLY DEFERRED
691+
FOR EACH ROW -- CONSTRAINT triggers must be per-ROW
692+
EXECUTE PROCEDURE _object_reference._tg_capture_safety()
693+
$code$;
694+
695+
INSERT INTO pg_temp.__object_reference__ddl_capture
696+
SELECT c_next_level, capture__start.object_group_id
697+
;
698+
RETURN c_next_level;
699+
END
700+
$body$
701+
, 'Begin capturing newly created objects to <object_group_id>. Returns current capture level.'
702+
, 'object_reference__usage'
703+
);
704+
651705
/*
652706
* Re-enable the event triggers disabled near the top of this script, now
653707
* that every object they reference is back in its final, current-source

0 commit comments

Comments
 (0)