Files
imexrps/hasura/migrations/default/1663277904884_create_table_public_notifications/up.sql
2022-11-22 11:27:37 -08:00

18 lines
1015 B
PL/PgSQL

CREATE TABLE "public"."notifications" ("id" serial NOT NULL, "created_at" timestamptz NOT NULL DEFAULT now(), "updated_at" timestamptz NOT NULL DEFAULT now(), "bodyshopid" uuid, "effectivedate" timestamptz NOT NULL, "html" text NOT NULL, "acceptedat" timestamptz, "acceptedby" text, "requiresaacceptance" text NOT NULL DEFAULT 'false', PRIMARY KEY ("id") , FOREIGN KEY ("bodyshopid") REFERENCES "public"."bodyshops"("id") ON UPDATE restrict ON DELETE restrict);
CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_updated_at"()
RETURNS TRIGGER AS $$
DECLARE
_new record;
BEGIN
_new := NEW;
_new."updated_at" = NOW();
RETURN _new;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER "set_public_notifications_updated_at"
BEFORE UPDATE ON "public"."notifications"
FOR EACH ROW
EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"();
COMMENT ON TRIGGER "set_public_notifications_updated_at" ON "public"."notifications"
IS 'trigger to set value of column "updated_at" to current timestamp on row update';