-- Create "McuSrc" table
CREATE TABLE "public"."McuSrc" (
  "Id" serial NOT NULL,
  "CreatedAt" timestamptz NULL,
  "UpdatedAt" timestamptz NULL,
  "DeletedAt" timestamptz NULL,
  "Code" character varying(20) NULL,
  "Name" character varying(50) NULL,
  "CheckupCategory_Code" character varying(20) NULL,
  PRIMARY KEY ("Id"),
  CONSTRAINT "uni_McuSrc_Code" UNIQUE ("Code")
);
-- Create "McuSrcCategory" table
CREATE TABLE "public"."McuSrcCategory" (
  "Id" serial NOT NULL,
  "CreatedAt" timestamptz NULL,
  "UpdatedAt" timestamptz NULL,
  "DeletedAt" timestamptz NULL,
  "Code" character varying(20) NULL,
  "Name" character varying(50) NULL,
  "Scope_Code" character varying(10) NULL,
  PRIMARY KEY ("Id"),
  CONSTRAINT "uni_McuSrcCategory_Code" UNIQUE ("Code")
);
-- Create "MedicineGroup" table
CREATE TABLE "public"."MedicineGroup" (
  "Id" serial NOT NULL,
  "CreatedAt" timestamptz NULL,
  "UpdatedAt" timestamptz NULL,
  "DeletedAt" timestamptz NULL,
  "Code" character varying(50) NULL,
  "Name" character varying(100) NULL,
  PRIMARY KEY ("Id"),
  CONSTRAINT "uni_MedicineGroup_Code" UNIQUE ("Code")
);
-- Create "MedicineMethod" table
CREATE TABLE "public"."MedicineMethod" (
  "Id" serial NOT NULL,
  "CreatedAt" timestamptz NULL,
  "UpdatedAt" timestamptz NULL,
  "DeletedAt" timestamptz NULL,
  "Code" character varying(50) NULL,
  "Name" character varying(100) NULL,
  PRIMARY KEY ("Id"),
  CONSTRAINT "uni_MedicineMethod_Code" UNIQUE ("Code")
);
-- Create "Uom" table
CREATE TABLE "public"."Uom" (
  "Id" serial NOT NULL,
  "CreatedAt" timestamptz NULL,
  "UpdatedAt" timestamptz NULL,
  "DeletedAt" timestamptz NULL,
  "Code" character varying(10) NULL,
  "Name" character varying(50) NULL,
  PRIMARY KEY ("Id"),
  CONSTRAINT "uni_Uom_Code" UNIQUE ("Code")
);
-- Create "Item" table
CREATE TABLE "public"."Item" (
  "Id" bigserial NOT NULL,
  "CreatedAt" timestamptz NULL,
  "UpdatedAt" timestamptz NULL,
  "DeletedAt" timestamptz NULL,
  "Code" character varying(50) NULL,
  "Name" character varying(100) NULL,
  "ItemGroup_Code" character varying(10) NULL,
  "Uom_Code" character varying(10) NULL,
  "Infra_Id" smallint NULL,
  "Stock" numeric NULL,
  PRIMARY KEY ("Id"),
  CONSTRAINT "uni_Item_Code" UNIQUE ("Code"),
  CONSTRAINT "fk_Item_ItemGroup" FOREIGN KEY ("ItemGroup_Code") REFERENCES "public"."ItemGroup" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "fk_Item_Uom" FOREIGN KEY ("Uom_Code") REFERENCES "public"."Uom" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION
);
-- Create "Infra" table
CREATE TABLE "public"."Infra" (
  "Id" serial NOT NULL,
  "CreatedAt" timestamptz NULL,
  "UpdatedAt" timestamptz NULL,
  "DeletedAt" timestamptz NULL,
  "Code" character varying(10) NULL,
  "Name" character varying(50) NULL,
  "InfraGroup_Code" character varying(10) NULL,
  "Parent_Id" smallint NULL,
  "Item_Id" bigint NULL,
  PRIMARY KEY ("Id"),
  CONSTRAINT "uni_Infra_Code" UNIQUE ("Code"),
  CONSTRAINT "fk_Infra_InfraGroup" FOREIGN KEY ("InfraGroup_Code") REFERENCES "public"."InfraGroup" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "fk_Infra_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION
);
-- Create "ItemPrice" table
CREATE TABLE "public"."ItemPrice" (
  "Id" bigserial NOT NULL,
  "CreatedAt" timestamptz NULL,
  "UpdatedAt" timestamptz NULL,
  "DeletedAt" timestamptz NULL,
  "Item_Id" bigint NULL,
  "Price" numeric NULL,
  PRIMARY KEY ("Id"),
  CONSTRAINT "fk_ItemPrice_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION
);
