summaryrefslogtreecommitdiff
path: root/db/migrations/0023_familiar_raza.sql
diff options
context:
space:
mode:
authorjoonhoekim <26rote@gmail.com>2025-03-25 15:55:45 +0900
committerjoonhoekim <26rote@gmail.com>2025-03-25 15:55:45 +0900
commit1a2241c40e10193c5ff7008a7b7b36cc1d855d96 (patch)
tree8a5587f10ca55b162d7e3254cb088b323a34c41b /db/migrations/0023_familiar_raza.sql
initial commit
Diffstat (limited to 'db/migrations/0023_familiar_raza.sql')
-rw-r--r--db/migrations/0023_familiar_raza.sql56
1 files changed, 56 insertions, 0 deletions
diff --git a/db/migrations/0023_familiar_raza.sql b/db/migrations/0023_familiar_raza.sql
new file mode 100644
index 00000000..1345d0bb
--- /dev/null
+++ b/db/migrations/0023_familiar_raza.sql
@@ -0,0 +1,56 @@
+CREATE TABLE "projects" (
+ "id" serial PRIMARY KEY NOT NULL,
+ "code" varchar(50) NOT NULL,
+ "name" text NOT NULL,
+ "created_at" timestamp DEFAULT now() NOT NULL,
+ "updated_at" timestamp DEFAULT now() NOT NULL
+);
+--> statement-breakpoint
+CREATE TABLE "contract_items" (
+ "id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "contract_items_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
+ "contract_id" integer NOT NULL,
+ "item_id" integer NOT NULL,
+ "quantity" integer DEFAULT 1 NOT NULL,
+ "price" numeric(10, 2),
+ "remark" text,
+ "created_at" timestamp DEFAULT now() NOT NULL,
+ "updated_at" timestamp DEFAULT now() NOT NULL,
+ CONSTRAINT "contract_items_item_id_unique" UNIQUE("item_id")
+);
+--> statement-breakpoint
+CREATE TABLE "contracts" (
+ "id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "contracts_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
+ "vendor_id" integer NOT NULL,
+ "contract_no" varchar(100) NOT NULL,
+ "status" varchar(50) DEFAULT 'ACTIVE' NOT NULL,
+ "start_date" date,
+ "end_date" date,
+ "created_at" timestamp DEFAULT now() NOT NULL,
+ "updated_at" timestamp DEFAULT now() NOT NULL,
+ CONSTRAINT "contracts_contract_no_unique" UNIQUE("contract_no")
+);
+--> statement-breakpoint
+CREATE TABLE "forms" (
+ "id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "forms_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
+ "form_code" varchar(100) NOT NULL,
+ "form_name" varchar(255) NOT NULL,
+ "tag_type" varchar(50) NOT NULL,
+ "created_at" timestamp DEFAULT now() NOT NULL,
+ "updated_at" timestamp DEFAULT now() NOT NULL,
+ CONSTRAINT "forms_form_code_unique" UNIQUE("form_code")
+);
+--> statement-breakpoint
+CREATE TABLE "tags" (
+ "id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "tags_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
+ "contract_item_id" integer NOT NULL,
+ "tag_no" varchar(100) NOT NULL,
+ "tag_type" varchar(50) NOT NULL,
+ "description" text,
+ "created_at" timestamp DEFAULT now() NOT NULL,
+ "updated_at" timestamp DEFAULT now() NOT NULL
+);
+--> statement-breakpoint
+ALTER TABLE "contract_items" ADD CONSTRAINT "contract_items_contract_id_contracts_id_fk" FOREIGN KEY ("contract_id") REFERENCES "public"."contracts"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
+ALTER TABLE "contract_items" ADD CONSTRAINT "contract_items_item_id_items_id_fk" FOREIGN KEY ("item_id") REFERENCES "public"."items"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
+ALTER TABLE "contracts" ADD CONSTRAINT "contracts_vendor_id_vendors_id_fk" FOREIGN KEY ("vendor_id") REFERENCES "public"."vendors"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
+ALTER TABLE "tags" ADD CONSTRAINT "tags_contract_item_id_contract_items_id_fk" FOREIGN KEY ("contract_item_id") REFERENCES "public"."contract_items"("id") ON DELETE cascade ON UPDATE no action; \ No newline at end of file