From 64ae2d6d44c8bcb2a24ead62316228c8c9b088d5 Mon Sep 17 00:00:00 2001 From: Rogee Date: Tue, 23 Sep 2025 17:36:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=A0=E9=99=A4=E6=97=A7=E7=9A=84?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E5=B9=B6=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=96=B0=E7=9A=84=E6=95=B0=E6=8D=AE=E5=BA=93=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E4=BB=A5=E6=94=AF=E6=8C=81=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E3=80=81=E4=BC=9A=E8=AF=9D=E5=92=8C=E5=AE=A1=E8=AE=A1=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...fig.full.toml.raw => config.full.toml.tpl} | 0 templates/project/config.toml.raw | 99 ------------------- .../migrations/00001_initial_schema.sql | 50 ++++++++++ 3 files changed, 50 insertions(+), 99 deletions(-) rename templates/project/{config.full.toml.raw => config.full.toml.tpl} (100%) delete mode 100755 templates/project/config.toml.raw create mode 100644 templates/project/database/migrations/00001_initial_schema.sql diff --git a/templates/project/config.full.toml.raw b/templates/project/config.full.toml.tpl similarity index 100% rename from templates/project/config.full.toml.raw rename to templates/project/config.full.toml.tpl diff --git a/templates/project/config.toml.raw b/templates/project/config.toml.raw deleted file mode 100755 index f776c3c..0000000 --- a/templates/project/config.toml.raw +++ /dev/null @@ -1,99 +0,0 @@ -# ========================= -# 应用基础配置 -# ========================= -[App] -# 应用运行模式:development | production | testing -Mode = "development" -# 应用基础URI,用于生成完整URL -BaseURI = "http://localhost:8080" - -# ========================= -# HTTP 服务器配置 -# ========================= -[Http] -# HTTP服务监听端口 -Port = 8080 -# 监听地址(可选,默认 0.0.0.0) -# Host = "0.0.0.0" -# 全局路由前缀(可选) -# BaseURI = "/api/v1" - -# ========================= -# 数据库配置 -# ========================= -[Database] -# 数据库主机地址 -Host = "localhost" -# 数据库端口 -Port = 5432 -# 数据库名称 -Database = "{{.ProjectName}}" -# 数据库用户名 -Username = "postgres" -# 数据库密码 -Password = "password" -# SSL模式:disable | require | verify-ca | verify-full -SslMode = "disable" -# 时区 -TimeZone = "Asia/Shanghai" -# 连接池配置(可选) -MaxIdleConns = 10 -MaxOpenConns = 100 -ConnMaxLifetime = "1800s" -ConnMaxIdleTime = "300s" - -# ========================= -# JWT 认证配置 -# ========================= -[JWT] -# JWT签名密钥(生产环境请使用强密钥) -SigningKey = "your-secret-key-change-in-production" -# Token过期时间,如:72h, 168h, 720h -ExpiresTime = "168h" -# 签发者(可选) -Issuer = "{{.ProjectName}}" - -# ========================= -# HashIDs 配置 -# ========================= -[HashIDs] -# 盐值(用于ID加密,请使用随机字符串) -Salt = "your-random-salt-here" -# 最小长度(可选) -MinLength = 8 -# 自定义字符集(可选) -# Alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" - -# ========================= -# Redis 缓存配置 -# ========================= -[Redis] -# Redis主机地址 -Host = "localhost" -# Redis端口 -Port = 6379 -# Redis密码(可选) -Password = "" -# 数据库编号 -DB = 0 -# 连接池配置(可选) -PoolSize = 50 -MinIdleConns = 10 -MaxRetries = 3 -# 超时配置(可选) -DialTimeout = "5s" -ReadTimeout = "3s" -WriteTimeout = "3s" - -# ========================= -# 日志配置 -# ========================= -[Log] -# 日志级别:debug | info | warn | error -Level = "info" -# 日志格式:json | text -Format = "json" -# 输出文件(可选,未配置则输出到控制台) -# Output = "./logs/app.log" -# 是否启用调用者信息(文件名:行号) -EnableCaller = true \ No newline at end of file diff --git a/templates/project/database/migrations/00001_initial_schema.sql b/templates/project/database/migrations/00001_initial_schema.sql new file mode 100644 index 0000000..116c670 --- /dev/null +++ b/templates/project/database/migrations/00001_initial_schema.sql @@ -0,0 +1,50 @@ +-- +goose Up +-- +goose StatementBegin +CREATE TABLE IF NOT EXISTS users ( + id SERIAL PRIMARY KEY, + username VARCHAR(255) UNIQUE NOT NULL, + email VARCHAR(255) UNIQUE NOT NULL, + password_hash VARCHAR(255) NOT NULL, + created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP +); + +CREATE TABLE IF NOT EXISTS sessions ( + id SERIAL PRIMARY KEY, + user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE, + token VARCHAR(255) UNIQUE NOT NULL, + expires_at TIMESTAMP WITH TIME ZONE NOT NULL, + created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP +); + +CREATE TABLE IF NOT EXISTS audit_logs ( + id SERIAL PRIMARY KEY, + action VARCHAR(100) NOT NULL, + entity_type VARCHAR(100) NOT NULL, + entity_id INTEGER, + user_id INTEGER REFERENCES users(id), + metadata JSONB, + ip_address INET, + user_agent TEXT, + created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP +); + +-- Create indexes for better performance +CREATE INDEX IF NOT EXISTS idx_users_email ON users(email); +CREATE INDEX IF NOT EXISTS idx_users_username ON users(username); +CREATE INDEX IF NOT EXISTS idx_sessions_token ON sessions(token); +CREATE INDEX IF NOT EXISTS idx_sessions_expires_at ON sessions(expires_at); +CREATE INDEX IF NOT EXISTS idx_audit_logs_created_at ON audit_logs(created_at); +CREATE INDEX IF NOT EXISTS idx_audit_logs_user_id ON audit_logs(user_id); +CREATE INDEX IF NOT EXISTS idx_audit_logs_entity ON audit_logs(entity_type, entity_id); + +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin + +DROP TABLE IF EXISTS audit_logs; +DROP TABLE IF EXISTS sessions; +DROP TABLE IF EXISTS users; + +-- +goose StatementEnd \ No newline at end of file