diff options
Diffstat (limited to 'db/migrations/0098_far_sleeper.sql')
| -rw-r--r-- | db/migrations/0098_far_sleeper.sql | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/db/migrations/0098_far_sleeper.sql b/db/migrations/0098_far_sleeper.sql new file mode 100644 index 00000000..f6d20a99 --- /dev/null +++ b/db/migrations/0098_far_sleeper.sql @@ -0,0 +1,29 @@ +CREATE TABLE "materials" ( + "id" serial PRIMARY KEY NOT NULL, + "item_code" varchar(100), + "item_name" varchar(255) NOT NULL, + "description" text, + "parent_item_code" varchar(18), + "item_level" integer, + "delete_flag" varchar(1), + "unit_of_measure" varchar(3), + "steel_type" varchar(2), + "grade_material" varchar(50), + "change_date" varchar(8), + "base_unit_of_measure" varchar(3), + "created_at" timestamp DEFAULT now() NOT NULL, + "updated_at" timestamp DEFAULT now() NOT NULL, + CONSTRAINT "materials_item_code_unique" UNIQUE("item_code") +); +--> statement-breakpoint +CREATE TABLE "vendor_possible_materials" ( + "id" serial PRIMARY KEY NOT NULL, + "vendor_id" integer NOT NULL, + "item_code" varchar(100) NOT NULL, + "created_at" timestamp DEFAULT now() NOT NULL, + "updated_at" timestamp DEFAULT now() NOT NULL +); +--> statement-breakpoint +ALTER TABLE "vendor_possible_materials" ADD CONSTRAINT "vendor_possible_materials_vendor_id_vendors_id_fk" FOREIGN KEY ("vendor_id") REFERENCES "public"."vendors"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "vendor_possible_materials" ADD CONSTRAINT "vendor_possible_materials_item_code_materials_item_code_fk" FOREIGN KEY ("item_code") REFERENCES "public"."materials"("item_code") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +CREATE VIEW "public"."vendor_materials_view" AS (select "vendor_possible_materials"."id", "vendor_possible_materials"."vendor_id", "materials"."item_name", "materials"."item_code", "materials"."description", "vendor_possible_materials"."created_at", "vendor_possible_materials"."updated_at" from "vendor_possible_materials" left join "materials" on "vendor_possible_materials"."item_code" = "materials"."item_code");
\ No newline at end of file |
