Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views2 pages

Label

The document contains SQL commands to create several tables for a database, including 'users', 'address', 'cart', 'cart_item', 'product_variations', 'product', 'product_var_options', and 'product_var_values'. Each table has defined fields, constraints, and relationships through foreign keys. The structure is designed to manage user information, addresses, shopping carts, and product details effectively.

Uploaded by

santiagoxgames
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Label

The document contains SQL commands to create several tables for a database, including 'users', 'address', 'cart', 'cart_item', 'product_variations', 'product', 'product_var_options', and 'product_var_values'. Each table has defined fields, constraints, and relationships through foreign keys. The structure is designed to manage user information, addresses, shopping carts, and product details effectively.

Uploaded by

santiagoxgames
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

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

You might also like