IO-1914 Schema for inventory and basic adding to inventory.

This commit is contained in:
Patrick Fic
2022-05-30 17:39:43 -07:00
parent 96995fdd1b
commit 908c17aa68
35 changed files with 769 additions and 9 deletions

View File

@@ -0,0 +1 @@
DROP TABLE "public"."inventory";

View File

@@ -0,0 +1,18 @@
CREATE TABLE "public"."inventory" ("id" uuid NOT NULL DEFAULT gen_random_uuid(), "created_at" timestamptz NOT NULL DEFAULT now(), "updated_at" timestamptz NOT NULL DEFAULT now(), "shopid" uuid NOT NULL, "billid" uuid, "joblineid" uuid, "line_desc" text NOT NULL, "actual_price" numeric NOT NULL, "actual_cost" numeric NOT NULL, "quantity" numeric NOT NULL, PRIMARY KEY ("id") , FOREIGN KEY ("joblineid") REFERENCES "public"."joblines"("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_inventory_updated_at"
BEFORE UPDATE ON "public"."inventory"
FOR EACH ROW
EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"();
COMMENT ON TRIGGER "set_public_inventory_updated_at" ON "public"."inventory"
IS 'trigger to set value of column "updated_at" to current timestamp on row update';
CREATE EXTENSION IF NOT EXISTS pgcrypto;

View File

@@ -0,0 +1 @@
alter table "public"."inventory" drop constraint "inventory_billid_fkey";

View File

@@ -0,0 +1,5 @@
alter table "public"."inventory"
add constraint "inventory_billid_fkey"
foreign key ("billid")
references "public"."billlines"
("id") on update restrict on delete restrict;

View File

@@ -0,0 +1 @@
alter table "public"."inventory" drop constraint "inventory_shopid_fkey";

View File

@@ -0,0 +1,5 @@
alter table "public"."inventory"
add constraint "inventory_shopid_fkey"
foreign key ("shopid")
references "public"."bodyshops"
("id") on update restrict on delete restrict;

View File

@@ -0,0 +1 @@
alter table "public"."inventory" rename column "billlineid" to "billid";

View File

@@ -0,0 +1 @@
alter table "public"."inventory" rename column "billid" to "billlineid";

View File

@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."inventory" add column "consumedbybillid" uuid
-- null;

View File

@@ -0,0 +1,2 @@
alter table "public"."inventory" add column "consumedbybillid" uuid
null;

View File

@@ -0,0 +1 @@
alter table "public"."inventory" drop constraint "inventory_consumedbybillid_fkey";

View File

@@ -0,0 +1,5 @@
alter table "public"."inventory"
add constraint "inventory_consumedbybillid_fkey"
foreign key ("consumedbybillid")
references "public"."bills"
("id") on update restrict on delete restrict;

View File

@@ -0,0 +1,5 @@
alter table "public"."inventory" drop constraint "inventory_consumedbybillid_fkey",
add constraint "inventory_consumedbybillid_fkey"
foreign key ("shopid")
references "public"."bodyshops"
("id") on update restrict on delete restrict;

View File

@@ -0,0 +1,5 @@
alter table "public"."inventory" drop constraint "inventory_consumedbybillid_fkey",
add constraint "inventory_consumedbybillid_fkey"
foreign key ("consumedbybillid")
references "public"."bills"
("id") on update restrict on delete set null;

View File

@@ -0,0 +1,5 @@
alter table "public"."inventory" drop constraint "inventory_consumedbybillid_fkey",
add constraint "inventory_consumedbybillid_fkey"
foreign key ("shopid")
references "public"."bodyshops"
("id") on update restrict on delete restrict;

View File

@@ -0,0 +1,5 @@
alter table "public"."inventory" drop constraint "inventory_consumedbybillid_fkey",
add constraint "inventory_consumedbybillid_fkey"
foreign key ("consumedbybillid")
references "public"."bills"
("id") on update cascade on delete set null;

View File

@@ -0,0 +1 @@
DROP INDEX IF EXISTS "public"."inventory_consumedbybillid";

View File

@@ -0,0 +1,2 @@
CREATE INDEX "inventory_consumedbybillid" on
"public"."inventory" using btree ("consumedbybillid");

View File

@@ -0,0 +1 @@
DROP INDEX IF EXISTS "public"."inventory_shopididx";

View File

@@ -0,0 +1,2 @@
CREATE INDEX "inventory_shopididx" on
"public"."inventory" using btree ("shopid");