>>107603525
>>107604457
I think I am going to go with a Babashka script that locates SQL comments of a certain format and replaces them with their contents after an EVAL
a preliminary function that is proving well:
(def begin-emission "-- Begin RoboSQL emission...")
(def end-emission "-- ...End RoboSQL emission")
(defn
immutable-column
[schema table column]
(format
"
%s
create function %s.%s_%s_tr_bu_fn()
returns trigger
as $$
begin
if old.%s is distinct from new.%s
then
raise exception '`%s` was updated.';
end if;
return new;
end;
$$
language plpgsql;
create trigger %s_%s_tr_bu
before update of %s
on %s.%s
for each row execute function %s.%s_%s_tr_bu_fn();
%s"
begin-emission
schema table column
column column
column
table column
column
schema table
schema table column
end-emission))
you would call it like:
--ROBO (immutable-column "some_scm" "some_tbl" "some_column")
or
/*ROBO
; Do whatever Babashka that you want that returns a string.
ROBO*/