feat: added sqlc and binded schema.sql as postgresql's init script
This commit is contained in:
@@ -37,7 +37,7 @@ services:
|
||||
- easywish-network
|
||||
volumes:
|
||||
- ./postgres_data:/var/lib/postgresql/data
|
||||
|
||||
- ./sqlc/schema.sql:/docker-entrypoint-initdb.d/init.sql
|
||||
redis:
|
||||
image: eqalpha/keydb
|
||||
command: ["redis-server", "--requirepass", "${REDIS_PASSWORD}"]
|
||||
|
||||
2
sqlc/query.sql
Normal file
2
sqlc/query.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
-- name: CreateUser :one
|
||||
INSERT INTO user (username, verified, banned, registration_date) VALUES ($1, false, false, NOW()) RETURNING id, username, verified, banned, registration_date;
|
||||
47
sqlc/schema.sql
Normal file
47
sqlc/schema.sql
Normal file
@@ -0,0 +1,47 @@
|
||||
-- TODO: login information must exist too
|
||||
CREATE TABLE IF NOT EXISTS "users" (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
username VARCHAR(20) UNIQUE NOT NULL,
|
||||
banned BOOLEAN NOT NULL,
|
||||
registration_date TIMESTAMP NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "login_informations" (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
user_id BIGINT UNIQUE NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
email VARCHAR(75),
|
||||
password_hash VARCHAR(512) NOT NULL,
|
||||
totp_encrypted VARCHAR(512),
|
||||
email_2fa_enabled BOOLEAN,
|
||||
password_change_time TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "confirmation_codes" (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
user_id BIGINT UNIQUE NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
type INTEGER NOT NULL,
|
||||
code VARCHAR(36) NOT NULL,
|
||||
expires_at TIMESTAMP NOT NULL,
|
||||
used BOOLEAN,
|
||||
deleted BOOLEAN
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "sessions" (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
user_id BIGINT UNIQUE NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
guid VARCHAR(36) NOT NULL,
|
||||
name VARCHAR(100),
|
||||
platform VARCHAR(32),
|
||||
latest_ip VARCHAR(16),
|
||||
login_time TIMESTAMP NOT NULL,
|
||||
last_seen_date TIMESTAMP NOT NULL,
|
||||
terminated BOOLEAN
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "profiles" (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
user_id BIGINT UNIQUE NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
name VARCHAR(75) NOT NULL,
|
||||
avatar_url VARCHAR(255),
|
||||
birthday TIMESTAMP
|
||||
);
|
||||
14
sqlc/sqlc.yaml
Normal file
14
sqlc/sqlc.yaml
Normal file
@@ -0,0 +1,14 @@
|
||||
version: "2"
|
||||
sql:
|
||||
- schema: "../postgresql/schema.sql"
|
||||
queries: "query.sql"
|
||||
engine: "postgresql"
|
||||
gen:
|
||||
go:
|
||||
out: "../backend/internal/database"
|
||||
sql_package: "pgx/v5"
|
||||
database:
|
||||
# managed: true
|
||||
uri: "postgresql://postgres:postgres@localhost:5432/mydb?sslmode=disable"
|
||||
rules:
|
||||
- sqlc/db-prepare
|
||||
Reference in New Issue
Block a user