-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lesson 61: Design DB for Email verification
- Loading branch information
1 parent
2f8666c
commit a9ad1b2
Showing
15 changed files
with
238 additions
and
10 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 "verify_emails" CASCADE; | ||
|
||
ALTER TABLE "users" DROP COLUMN "is_email_verified"; |
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 TABLE "verify_emails" ( | ||
"id" bigserial PRIMARY KEY, | ||
"username" varchar NOT NULL, | ||
"email" varchar NOT NULL, | ||
"secret_code" varchar NOT NULL, | ||
"is_used" bool NOT NULL DEFAULT false, | ||
"created_at" timestamptz NOT NULL DEFAULT (now()), | ||
"expired_at" timestamptz NOT NULL DEFAULT (now() + interval '15 minutes') | ||
); | ||
|
||
ALTER TABLE "verify_emails" ADD FOREIGN KEY ("username") REFERENCES "users" ("username"); | ||
|
||
ALTER TABLE "users" ADD COLUMN "is_email_verified" bool NOT NULL DEFAULT false; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
-- name: CreateVerifyEmail :one | ||
INSERT INTO verify_emails ( | ||
username, | ||
email, | ||
secret_code | ||
) VALUES ( | ||
$1, $2, $3 | ||
) RETURNING *; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,71 @@ | ||
-- SQL dump generated using DBML (dbml-lang.org) | ||
-- Database: PostgreSQL | ||
-- Generated at: 2023-10-02T11:26:20.038Z | ||
|
||
CREATE TABLE "users" ( | ||
"username" varchar PRIMARY KEY, | ||
"hashed_password" varchar NOT NULL, | ||
"full_name" varchar NOT NULL, | ||
"email" varchar NOT NULL, | ||
"is_email_verified" bool NOT NULL DEFAULT false, | ||
"password_changed_at" timestamptz NOT NULL DEFAULT (0001-01-01), | ||
"created_at" timestamptz NOT NULL DEFAULT (now()) | ||
); | ||
|
||
CREATE TABLE "verify_emails" ( | ||
"id" bigserial PRIMARY KEY, | ||
"username" varchar NOT NULL, | ||
"email" varchar NOT NULL, | ||
"secret_code" varchar NOT NULL, | ||
"is_used" bool NOT NULL DEFAULT false, | ||
"created_at" timestamptz NOT NULL DEFAULT (now()), | ||
"expired_at" timestamptz NOT NULL DEFAULT (now() + interval '15 minutes') | ||
); | ||
|
||
CREATE TABLE "accounts" ( | ||
"id" BIGSERIAL PRIMARY KEY, | ||
"owner" varchar NOT NULL, | ||
"balance" numeric NOT NULL, | ||
"currency" varchar NOT NULL, | ||
"created_at" timestamptz NOT NULL DEFAULT (now()), | ||
"updated_at" timestamptz | ||
); | ||
|
||
CREATE TABLE "entries" ( | ||
"id" BIGSERIAL PRIMARY KEY, | ||
"account_id" bigint NOT NULL, | ||
"amount" numeric NOT NULL, | ||
"created_at" timestamptz NOT NULL DEFAULT (now()) | ||
); | ||
|
||
CREATE TABLE "transfers" ( | ||
"id" BIGSERIAL PRIMARY KEY, | ||
"from_account_id" bigint NOT NULL, | ||
"to_account_id" bigint NOT NULL, | ||
"amount" numeric NOT NULL, | ||
"created_at" timestamptz NOT NULL DEFAULT (now()) | ||
); | ||
|
||
CREATE INDEX ON "accounts" ("owner"); | ||
|
||
CREATE INDEX ON "entries" ("account_id"); | ||
|
||
CREATE INDEX ON "transfers" ("from_account_id"); | ||
|
||
CREATE INDEX ON "transfers" ("to_account_id"); | ||
|
||
CREATE INDEX ON "transfers" ("from_account_id", "to_account_id"); | ||
|
||
COMMENT ON COLUMN "entries"."amount" IS 'can be poitive or negative'; | ||
|
||
COMMENT ON COLUMN "transfers"."amount" IS 'must be positive'; | ||
|
||
ALTER TABLE "verify_emails" ADD FOREIGN KEY ("username") REFERENCES "users" ("username"); | ||
|
||
ALTER TABLE "accounts" ADD FOREIGN KEY ("owner") REFERENCES "users" ("username"); | ||
|
||
ALTER TABLE "entries" ADD FOREIGN KEY ("account_id") REFERENCES "accounts" ("id"); | ||
|
||
ALTER TABLE "transfers" ADD FOREIGN KEY ("from_account_id") REFERENCES "accounts" ("id"); | ||
|
||
ALTER TABLE "transfers" ADD FOREIGN KEY ("to_account_id") REFERENCES "accounts" ("id"); |
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
Oops, something went wrong.