CREATE TABLE IF NOT EXISTS "users" (
"id" serial NOT NULL UNIQUE,
"username" varchar(255) NOT NULL UNIQUE,
"email" varchar(255) NOT NULL UNIQUE,
"fist_name" varchar(255) NOT NULL,
"last_name" varchar(255),
"phone" varchar(255),
"is_active" boolean NOT NULL DEFAULT false,
"avatar" varchar(255),
"created_at" timestamp without time zone,
"updated_at" timestamp without time zone,
PRIMARY KEY ("id")
);
CREATE TABLE IF NOT EXISTS "address" (
"id" serial NOT NULL UNIQUE,
"customer_id" bigint NOT NULL,
"address_line" varchar(255) NOT NULL,
"address_line2" varchar(255) NOT NULL,
"country" varchar(255) NOT NULL,
"region" varchar(255) NOT NULL,
"updated_at" timestamp without time zone NOT NULL,
"created_at" timestamp without time zone NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE IF NOT EXISTS "cart" (
"id" serial NOT NULL UNIQUE,
"customer_id" bigint,
"created_at" timestamp without time zone NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE IF NOT EXISTS "cart_item" (
"id" serial NOT NULL UNIQUE,
"cart_id" bigint NOT NULL,
"product_variation_id" bigint NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE IF NOT EXISTS "product_variations" (
"id" serial NOT NULL,
"product_id" bigint NOT NULL,
"updated_at" timestamp without time zone NOT NULL,
"created_at" timestamp without time zone NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE IF NOT EXISTS "product" (
"id" serial NOT NULL,
"title" varchar(255) NOT NULL,
"description" varchar(255) NOT NULL,
"brand" varchar(255) NOT NULL,
"created_at" timestamp without time zone NOT NULL,
"updated_at" timestamp without time zone NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE IF NOT EXISTS "product_var_options" (
"id" serial NOT NULL,
"product_variations_id" bigint NOT NULL,
"name" varchar(255) NOT NULL,
"product_var_values_id" bigint NOT NULL,
PRIMARY KEY ("id")
);
CREATE TABLE IF NOT EXISTS "product_var_values" (
"id" serial NOT NULL,
"value" varchar(255) NOT NULL,
PRIMARY KEY ("id")
);
ALTER TABLE "address" ADD CONSTRAINT "address_fk1" FOREIGN KEY ("customer_id")
REFERENCES "users"("id");
ALTER TABLE "cart" ADD CONSTRAINT "cart_fk1" FOREIGN KEY ("customer_id") REFERENCES
"users"("id");
ALTER TABLE "cart_item" ADD CONSTRAINT "cart_item_fk1" FOREIGN KEY ("cart_id")
REFERENCES "cart"("id");
ALTER TABLE "cart_item" ADD CONSTRAINT "cart_item_fk2" FOREIGN KEY
("product_variation_id") REFERENCES "product_variations"("id");
ALTER TABLE "product_variations" ADD CONSTRAINT "product_variations_fk1" FOREIGN
KEY ("product_id") REFERENCES "product"("id");
ALTER TABLE "product_var_options" ADD CONSTRAINT "product_var_options_fk1" FOREIGN
KEY ("product_variations_id") REFERENCES "product_variations"("id");
ALTER TABLE "product_var_options" ADD CONSTRAINT "product_var_options_fk3" FOREIGN
KEY ("product_var_values_id") REFERENCES "product_var_values"("id");