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

@@ -402,6 +402,14 @@
- name: jobline
using:
foreign_key_constraint_on: joblineid
array_relationships:
- name: inventories
using:
foreign_key_constraint_on:
column: billlineid
table:
schema: public
name: inventory
insert_permissions:
- role: user
permission:
@@ -541,6 +549,13 @@
table:
schema: public
name: exportlog
- name: inventories
using:
foreign_key_constraint_on:
column: consumedbybillid
table:
schema: public
name: inventory
- name: parts_orders
using:
foreign_key_constraint_on:
@@ -751,6 +766,13 @@
table:
schema: public
name: exportlog
- name: inventories
using:
foreign_key_constraint_on:
column: shopid
table:
schema: public
name: inventory
- name: jobs
using:
foreign_key_constraint_on:
@@ -2112,6 +2134,96 @@
- active:
_eq: true
allow_aggregations: true
- table:
schema: public
name: inventory
object_relationships:
- name: bill
using:
foreign_key_constraint_on: consumedbybillid
- name: billline
using:
foreign_key_constraint_on: billlineid
- name: bodyshop
using:
foreign_key_constraint_on: shopid
- name: jobline
using:
foreign_key_constraint_on: joblineid
insert_permissions:
- role: user
permission:
check:
bodyshop:
associations:
_and:
- user:
authid:
_eq: X-Hasura-User-Id
- active:
_eq: true
columns:
- actual_cost
- actual_price
- billlineid
- consumedbybillid
- created_at
- id
- joblineid
- line_desc
- quantity
- shopid
- updated_at
backend_only: false
select_permissions:
- role: user
permission:
columns:
- actual_cost
- actual_price
- billlineid
- consumedbybillid
- created_at
- id
- joblineid
- line_desc
- quantity
- shopid
- updated_at
filter:
bodyshop:
associations:
_and:
- user:
authid:
_eq: X-Hasura-User-Id
- active:
_eq: true
update_permissions:
- role: user
permission:
columns:
- actual_cost
- actual_price
- billlineid
- consumedbybillid
- created_at
- id
- joblineid
- line_desc
- quantity
- shopid
- updated_at
filter:
bodyshop:
associations:
_and:
- user:
authid:
_eq: X-Hasura-User-Id
- active:
_eq: true
check: null
- table:
schema: public
name: ioevents
@@ -2211,6 +2323,13 @@
table:
schema: public
name: billlines
- name: inventories
using:
foreign_key_constraint_on:
column: joblineid
table:
schema: public
name: inventory
- name: parts_order_lines
using:
foreign_key_constraint_on:

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");