Sha256: d5025ac057df2308eda637c8abfb36581a0b200933960e3bc326850ced6a8dd5
Contents?: true
Size: 970 Bytes
Versions: 3
Compression:
Stored size: 970 Bytes
Contents
CREATE OR REPLACE FUNCTION "%{table}_insert" () RETURNS TRIGGER AS $$ BEGIN -- "obsoleted_dt" is set when a history row is created by -- UPDATE. Leave it alone. IF NEW.obsoleted_dt <> 'infinity' THEN RETURN NEW; END IF; NEW.obsoleted_dt = 'infinity'; NEW.group_id = NEW.id; -- FIXME: Handle cases where created_dt is sent in on creation. This -- is only useful for debugging. Consider removing the surronding -- IF for production version. IF NEW.created_dt IS NULL THEN NEW.created_dt = 'now()'; END IF; RETURN NEW; END; $$ LANGUAGE plpgsql; DROP TRIGGER IF EXISTS %{table}_insert ON %{table}; CREATE TRIGGER "%{table}_insert" BEFORE INSERT ON "%{table}" FOR EACH ROW EXECUTE PROCEDURE "%{table}_insert"(); -- Add constraint to make sure o_user_id is set iff obsoleted_dt is -- not infinity (i.e. object is obsoleted). ALTER TABLE "%{table}" ADD CONSTRAINT check_o_user CHECK ((obsoleted_dt = 'Infinity') = (o_user_id IS NULL));
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
mcfly-0.0.7 | lib/mcfly/insert_trig.sql |
mcfly-0.0.6 | lib/mcfly/insert_trig.sql |
mcfly-0.0.5 | lib/mcfly/insert_trig.sql |