feat: 0.0.1
This commit is contained in:
146 files changed
+10444
No files matched your search
@@ -0,0 +1,3 @@
|
||||
DROP TABLE IF EXISTS "users";
|
||||
DROP TABLE IF EXISTS "verify_emails";
|
||||
DROP TABLE IF EXISTS "sessions";
|
||||
@@ -0,0 +1,39 @@
|
||||
-- SQL dump generated using DBML (dbml.dbdiagram.io)
|
||||
-- Database: PostgreSQL
|
||||
-- Generated at: 2025-11-30T03:13:20.470Z
|
||||
|
||||
CREATE TABLE "users" (
|
||||
"username" varchar PRIMARY KEY,
|
||||
"role" varchar NOT NULL DEFAULT 'member',
|
||||
"hashed_password" varchar NOT NULL,
|
||||
"full_name" varchar NOT NULL,
|
||||
"email" varchar UNIQUE 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 "sessions" (
|
||||
"id" uuid PRIMARY KEY,
|
||||
"username" varchar NOT NULL,
|
||||
"refresh_token" varchar NOT NULL,
|
||||
"user_agent" varchar NOT NULL,
|
||||
"client_ip" varchar NOT NULL,
|
||||
"is_blocked" boolean NOT NULL DEFAULT false,
|
||||
"expires_at" timestamptz NOT NULL,
|
||||
"created_at" timestamptz NOT NULL DEFAULT (now())
|
||||
);
|
||||
|
||||
ALTER TABLE "verify_emails" ADD FOREIGN KEY ("username") REFERENCES "users" ("username");
|
||||
|
||||
ALTER TABLE "sessions" ADD FOREIGN KEY ("username") REFERENCES "users" ("username");
|
||||
@@ -0,0 +1,17 @@
|
||||
-- name: CreateSession :one
|
||||
INSERT INTO sessions (
|
||||
id,
|
||||
username,
|
||||
refresh_token,
|
||||
user_agent,
|
||||
client_ip,
|
||||
is_blocked,
|
||||
expires_at
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5, $6, $7
|
||||
)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetSession :one
|
||||
SELECT * FROM sessions
|
||||
WHERE id = $1 LIMIT 1;
|
||||
@@ -0,0 +1,25 @@
|
||||
-- name: CreateUser :one
|
||||
INSERT INTO users (
|
||||
username,
|
||||
hashed_password,
|
||||
full_name,
|
||||
email
|
||||
) VALUES (
|
||||
$1, $2, $3, $4
|
||||
)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetUser :one
|
||||
SELECT * FROM users
|
||||
WHERE username = $1 LIMIT 1;
|
||||
|
||||
-- name: UpdateUser :one
|
||||
UPDATE users
|
||||
SET
|
||||
hashed_password = COALESCE(sqlc.narg('hashed_password'), hashed_password),
|
||||
password_changed_at = COALESCE(sqlc.narg('password_changed_at'), password_changed_at),
|
||||
full_name = COALESCE(sqlc.narg('full_name'), full_name),
|
||||
email = COALESCE(sqlc.narg('email'), email),
|
||||
is_email_verified = COALESCE(sqlc.narg('is_email_verified'), is_email_verified)
|
||||
WHERE username = sqlc.arg('username')
|
||||
RETURNING *;
|
||||
@@ -0,0 +1,21 @@
|
||||
-- name: CreateVerifyEmail :one
|
||||
INSERT INTO verify_emails (
|
||||
username,
|
||||
email,
|
||||
secret_code
|
||||
) VALUES (
|
||||
$1, $2, $3
|
||||
)
|
||||
RETURNING *;
|
||||
|
||||
|
||||
-- name: UpdateVerifyEmail :one
|
||||
UPDATE verify_emails
|
||||
SET
|
||||
is_used = TRUE
|
||||
WHERE
|
||||
id = @id
|
||||
AND secret_code = @secret_code
|
||||
AND is_used = FALSE
|
||||
AND expired_at > NOW()
|
||||
RETURNING *;
|
||||
Reference in new issue
Block a user