diff --git a/hasura/migrations/1685561607407_create_table_public_parts_dispatch/down.sql b/hasura/migrations/1685561607407_create_table_public_parts_dispatch/down.sql new file mode 100644 index 000000000..42325ddf5 --- /dev/null +++ b/hasura/migrations/1685561607407_create_table_public_parts_dispatch/down.sql @@ -0,0 +1 @@ +DROP TABLE "public"."parts_dispatch"; diff --git a/hasura/migrations/1685561607407_create_table_public_parts_dispatch/up.sql b/hasura/migrations/1685561607407_create_table_public_parts_dispatch/up.sql new file mode 100644 index 000000000..d8c7c2729 --- /dev/null +++ b/hasura/migrations/1685561607407_create_table_public_parts_dispatch/up.sql @@ -0,0 +1,18 @@ +CREATE TABLE "public"."parts_dispatch" ("id" uuid NOT NULL DEFAULT gen_random_uuid(), "created_at" timestamptz NOT NULL DEFAULT now(), "updated_at" timestamptz NOT NULL DEFAULT now(), "jobid" uuid NOT NULL, "number" serial NOT NULL, "employeeid" uuid NOT NULL, "dispatched_at" timestamptz NOT NULL, "dispatched_by" text NOT NULL, PRIMARY KEY ("id") , FOREIGN KEY ("jobid") REFERENCES "public"."jobs"("id") ON UPDATE cascade ON DELETE cascade); +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_parts_dispatch_updated_at" +BEFORE UPDATE ON "public"."parts_dispatch" +FOR EACH ROW +EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"(); +COMMENT ON TRIGGER "set_public_parts_dispatch_updated_at" ON "public"."parts_dispatch" +IS 'trigger to set value of column "updated_at" to current timestamp on row update'; +CREATE EXTENSION IF NOT EXISTS pgcrypto; diff --git a/hasura/migrations/1685561715531_create_table_public_parts_dispatch_lines/down.sql b/hasura/migrations/1685561715531_create_table_public_parts_dispatch_lines/down.sql new file mode 100644 index 000000000..a12867253 --- /dev/null +++ b/hasura/migrations/1685561715531_create_table_public_parts_dispatch_lines/down.sql @@ -0,0 +1 @@ +DROP TABLE "public"."parts_dispatch_lines"; diff --git a/hasura/migrations/1685561715531_create_table_public_parts_dispatch_lines/up.sql b/hasura/migrations/1685561715531_create_table_public_parts_dispatch_lines/up.sql new file mode 100644 index 000000000..5146e2c7e --- /dev/null +++ b/hasura/migrations/1685561715531_create_table_public_parts_dispatch_lines/up.sql @@ -0,0 +1,18 @@ +CREATE TABLE "public"."parts_dispatch_lines" ("id" uuid NOT NULL DEFAULT gen_random_uuid(), "created_at" timestamptz NOT NULL DEFAULT now(), "updated_at" timestamptz NOT NULL DEFAULT now(), "partsdispatchid" UUID NOT NULL, "joblineid" uuid NOT NULL, "quantity" numeric NOT NULL DEFAULT 1, "accepted_at" timestamptz NOT NULL, PRIMARY KEY ("id") , FOREIGN KEY ("joblineid") REFERENCES "public"."joblines"("id") ON UPDATE cascade ON DELETE cascade); +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_parts_dispatch_lines_updated_at" +BEFORE UPDATE ON "public"."parts_dispatch_lines" +FOR EACH ROW +EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"(); +COMMENT ON TRIGGER "set_public_parts_dispatch_lines_updated_at" ON "public"."parts_dispatch_lines" +IS 'trigger to set value of column "updated_at" to current timestamp on row update'; +CREATE EXTENSION IF NOT EXISTS pgcrypto;