-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from bagashiz/feat/setup-database-migrations
feat: setup database migrations
- Loading branch information
Showing
16 changed files
with
193 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
DROP TABLE IF EXISTS "users"; | ||
|
||
DROP TYPE IF EXISTS "users_role_enum"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CREATE TYPE "users_role_enum" AS ENUM ('admin', 'cashier'); | ||
|
||
CREATE TABLE "users" ( | ||
"id" BIGSERIAL PRIMARY KEY, | ||
"name" varchar NOT NULL, | ||
"email" varchar NOT NULL, | ||
"password" varchar NOT NULL, | ||
"role" users_role_enum DEFAULT 'cashier', | ||
"created_at" timestamptz NOT NULL DEFAULT (now()), | ||
"updated_at" timestamptz NOT NULL DEFAULT (now()) | ||
); | ||
|
||
CREATE UNIQUE INDEX "email" ON "users" ("email"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS "payments"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CREATE TABLE "payments" ( | ||
"id" BIGSERIAL PRIMARY KEY, | ||
"name" varchar NOT NULL, | ||
"type" varchar NOT NULL, | ||
"logo" varchar, | ||
"created_at" timestamptz NOT NULL DEFAULT (now()), | ||
"updated_at" timestamptz NOT NULL DEFAULT (now()) | ||
); | ||
|
||
CREATE UNIQUE INDEX "payment_name" ON "payments" ("name"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ALTER TABLE | ||
IF EXISTS "orders" DROP CONSTRAINT "fk_users_orders"; | ||
|
||
ALTER TABLE | ||
IF EXISTS "orders" DROP CONSTRAINT "fk_payments_orders"; | ||
|
||
DROP TABLE IF EXISTS "orders"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
CREATE TABLE "orders" ( | ||
"id" BIGSERIAL PRIMARY KEY, | ||
"user_id" bigint NOT NULL, | ||
"payment_id" bigint NOT NULL, | ||
"customer_name" varchar NOT NULL, | ||
"total_price" decimal(18, 2) NOT NULL, | ||
"total_paid" decimal(18, 2) NOT NULL, | ||
"total_return" decimal(18, 2) NOT NULL, | ||
"receipt_code" uuid NOT NULL DEFAULT (gen_random_uuid()), | ||
"created_at" timestamptz NOT NULL DEFAULT (now()), | ||
"updated_at" timestamptz NOT NULL DEFAULT (now()) | ||
); | ||
|
||
CREATE INDEX "orders_customer_name" ON "orders" ("customer_name"); | ||
|
||
CREATE INDEX "orders_payment_id" ON "orders" ("payment_id"); | ||
|
||
CREATE INDEX "orders_user_id" ON "orders" ("user_id"); | ||
|
||
CREATE UNIQUE INDEX "receipt_code" ON "orders" ("receipt_code"); | ||
|
||
ALTER TABLE | ||
"orders" | ||
ADD | ||
CONSTRAINT "fk_payments_orders" FOREIGN KEY ("payment_id") REFERENCES "payments" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION; | ||
|
||
ALTER TABLE | ||
"orders" | ||
ADD | ||
CONSTRAINT "fk_users_orders" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS "categories"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CREATE TABLE "categories" ( | ||
"id" BIGSERIAL PRIMARY KEY, | ||
"name" varchar NOT NULL, | ||
"created_at" timestamptz NOT NULL DEFAULT (now()), | ||
"updated_at" timestamptz NOT NULL DEFAULT (now()) | ||
); | ||
|
||
CREATE UNIQUE INDEX "category_name" ON "categories" ("name"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ALTER TABLE | ||
"products" DROP CONSTRAINT "fk_categories_products"; | ||
|
||
DROP TABLE IF EXISTS "products"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
CREATE TABLE "products" ( | ||
"id" BIGSERIAL PRIMARY KEY, | ||
"category_id" bigint NOT NULL, | ||
"sku" varchar NOT NULL, | ||
"name" varchar NOT NULL, | ||
"stock" bigint NOT NULL, | ||
"price" decimal(18, 2) NOT NULL, | ||
"image" varchar, | ||
"created_at" timestamptz NOT NULL DEFAULT (now()), | ||
"updated_at" timestamptz NOT NULL DEFAULT (now()) | ||
); | ||
|
||
CREATE INDEX "products_category_id" ON "products" ("category_id"); | ||
|
||
CREATE INDEX "products_name" ON "products" ("name"); | ||
|
||
CREATE UNIQUE INDEX "sku" ON "products" ("sku"); | ||
|
||
ALTER TABLE | ||
"products" | ||
ADD | ||
CONSTRAINT "fk_categories_products" FOREIGN KEY ("category_id") REFERENCES "categories" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ALTER TABLE | ||
IF EXISTS "order_products" DROP CONSTRAINT "fk_products_order_products"; | ||
|
||
ALTER TABLE | ||
IF EXISTS "order_products" DROP CONSTRAINT "fk_orders_order_products"; | ||
|
||
DROP TABLE IF EXISTS "order_products"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
CREATE TABLE "order_products" ( | ||
"id" BIGSERIAL PRIMARY KEY, | ||
"order_id" bigint NOT NULL, | ||
"product_id" bigint NOT NULL, | ||
"quantity" bigint NOT NULL, | ||
"total_price" decimal(18, 2) NOT NULL, | ||
"created_at" timestamptz NOT NULL DEFAULT (now()), | ||
"updated_at" timestamptz NOT NULL DEFAULT (now()) | ||
); | ||
|
||
CREATE INDEX "order_product_order_id" ON "order_products" ("order_id"); | ||
|
||
CREATE INDEX "order_product_product_id" ON "order_products" ("product_id"); | ||
|
||
ALTER TABLE | ||
"order_products" | ||
ADD | ||
CONSTRAINT "fk_orders_order_products" FOREIGN KEY ("order_id") REFERENCES "orders" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION; | ||
|
||
ALTER TABLE | ||
"order_products" | ||
ADD | ||
CONSTRAINT "fk_products_order_products" FOREIGN KEY ("product_id") REFERENCES "products" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
version: "2" | ||
sql: | ||
- engine: "postgresql" | ||
schema: "./db/migrations" | ||
queries: "./db/queries" | ||
gen: | ||
go: | ||
package: "repository" | ||
out: "./internal/adapter/repository" | ||
sql_package: "pgx/v5" | ||
emit_json_tags: true | ||
emit_interface: true | ||
emit_empty_slices: true |