mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-06 15:46:37 +08:00
框架表改名 w_{name}
This commit is contained in:
@@ -219,7 +219,7 @@ func buildAccessLogFilters(ctx context.Context, c *gin.Context) ([]string, []int
|
|||||||
func fetchAccessLogDetails(ctx context.Context, whereClause string, args []interface{}, pageSize int, offset int) ([]accessLogItem, error) {
|
func fetchAccessLogDetails(ctx context.Context, whereClause string, args []interface{}, pageSize int, offset int) ([]accessLogItem, error) {
|
||||||
dataQuery := fmt.Sprintf(`
|
dataQuery := fmt.Sprintf(`
|
||||||
SELECT id, user_id, path, method, ip, user_agent, headers, status, latency, created_at
|
SELECT id, user_id, path, method, ip, user_agent, headers, status, latency, created_at
|
||||||
FROM user_access_logs
|
FROM w_user_access_logs
|
||||||
%s
|
%s
|
||||||
ORDER BY created_at DESC, id DESC
|
ORDER BY created_at DESC, id DESC
|
||||||
LIMIT ? OFFSET ?
|
LIMIT ? OFFSET ?
|
||||||
@@ -325,7 +325,7 @@ func GetAccessLogs(c *gin.Context) {
|
|||||||
|
|
||||||
// 4. 查询日志总数
|
// 4. 查询日志总数
|
||||||
var total uint64
|
var total uint64
|
||||||
countQuery := fmt.Sprintf("SELECT count() FROM user_access_logs %s", whereClause)
|
countQuery := fmt.Sprintf("SELECT count() FROM w_user_access_logs %s", whereClause)
|
||||||
if err := db.ChConn.QueryRow(c.Request.Context(), countQuery, args...).Scan(&total); err != nil {
|
if err := db.ChConn.QueryRow(c.Request.Context(), countQuery, args...).Scan(&total); err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, util.Err("查询 ClickHouse 日志统计失败: "+err.Error()))
|
c.JSON(http.StatusInternalServerError, util.Err("查询 ClickHouse 日志统计失败: "+err.Error()))
|
||||||
return
|
return
|
||||||
@@ -412,7 +412,7 @@ func GetLogsAnalytics(c *gin.Context) {
|
|||||||
func queryAccessTrend(ctx context.Context, startTime time.Time) []trendItem {
|
func queryAccessTrend(ctx context.Context, startTime time.Time) []trendItem {
|
||||||
trendRows, err := db.ChConn.Query(ctx, `
|
trendRows, err := db.ChConn.Query(ctx, `
|
||||||
SELECT toDate(created_at) as date, count() as count
|
SELECT toDate(created_at) as date, count() as count
|
||||||
FROM user_access_logs
|
FROM w_user_access_logs
|
||||||
WHERE created_at >= ?
|
WHERE created_at >= ?
|
||||||
GROUP BY date
|
GROUP BY date
|
||||||
ORDER BY date ASC
|
ORDER BY date ASC
|
||||||
@@ -451,7 +451,7 @@ func queryAccessTrend(ctx context.Context, startTime time.Time) []trendItem {
|
|||||||
func queryBrowserDistribution(ctx context.Context, startTime time.Time) []browserItem {
|
func queryBrowserDistribution(ctx context.Context, startTime time.Time) []browserItem {
|
||||||
uaRows, err := db.ChConn.Query(ctx, `
|
uaRows, err := db.ChConn.Query(ctx, `
|
||||||
SELECT user_agent, count() as count
|
SELECT user_agent, count() as count
|
||||||
FROM user_access_logs
|
FROM w_user_access_logs
|
||||||
WHERE created_at >= ?
|
WHERE created_at >= ?
|
||||||
GROUP BY user_agent
|
GROUP BY user_agent
|
||||||
`, startTime)
|
`, startTime)
|
||||||
@@ -486,7 +486,7 @@ func queryBrowserDistribution(ctx context.Context, startTime time.Time) []browse
|
|||||||
func queryTopActiveUsers(ctx context.Context, startTime time.Time) []topUserItem {
|
func queryTopActiveUsers(ctx context.Context, startTime time.Time) []topUserItem {
|
||||||
userRows, err := db.ChConn.Query(ctx, `
|
userRows, err := db.ChConn.Query(ctx, `
|
||||||
SELECT user_id, count() as count
|
SELECT user_id, count() as count
|
||||||
FROM user_access_logs
|
FROM w_user_access_logs
|
||||||
WHERE created_at >= ? AND user_id > 0
|
WHERE created_at >= ? AND user_id > 0
|
||||||
GROUP BY user_id
|
GROUP BY user_id
|
||||||
ORDER BY count DESC
|
ORDER BY count DESC
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ func ListUsers(c *gin.Context) {
|
|||||||
var users []user
|
var users []user
|
||||||
var total int64
|
var total int64
|
||||||
|
|
||||||
query := db.DB(c.Request.Context()).Table("users")
|
query := db.DB(c.Request.Context()).Model(&model.User{})
|
||||||
|
|
||||||
username := strings.TrimSpace(req.Username)
|
username := strings.TrimSpace(req.Username)
|
||||||
|
|
||||||
@@ -217,7 +217,7 @@ func UpdateUserStatus(c *gin.Context) {
|
|||||||
IsAdmin bool `gorm:"column:is_admin"`
|
IsAdmin bool `gorm:"column:is_admin"`
|
||||||
}
|
}
|
||||||
if err := db.DB(c.Request.Context()).
|
if err := db.DB(c.Request.Context()).
|
||||||
Table("users").
|
Model(&model.User{}).
|
||||||
Select("id, is_admin").
|
Select("id, is_admin").
|
||||||
Where("id = ?", id).
|
Where("id = ?", id).
|
||||||
First(&targetUser).Error; err != nil {
|
First(&targetUser).Error; err != nil {
|
||||||
@@ -235,7 +235,7 @@ func UpdateUserStatus(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := db.DB(c.Request.Context()).
|
if err := db.DB(c.Request.Context()).
|
||||||
Table("users").
|
Model(&model.User{}).
|
||||||
Where("id = ?", id).
|
Where("id = ?", id).
|
||||||
Update("is_active", req.IsActive).Error; err != nil {
|
Update("is_active", req.IsActive).Error; err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, util.Err(updateUserFailed))
|
c.JSON(http.StatusInternalServerError, util.Err(updateUserFailed))
|
||||||
@@ -276,7 +276,7 @@ func DeleteUser(c *gin.Context) {
|
|||||||
IsAdmin bool `gorm:"column:is_admin"`
|
IsAdmin bool `gorm:"column:is_admin"`
|
||||||
}
|
}
|
||||||
if err := db.DB(c.Request.Context()).
|
if err := db.DB(c.Request.Context()).
|
||||||
Table("users").
|
Model(&model.User{}).
|
||||||
Select("id, is_admin").
|
Select("id, is_admin").
|
||||||
Where("id = ?", id).
|
Where("id = ?", id).
|
||||||
First(&targetUser).Error; err != nil {
|
First(&targetUser).Error; err != nil {
|
||||||
@@ -354,7 +354,7 @@ func CreateUser(c *gin.Context) {
|
|||||||
|
|
||||||
ctx := c.Request.Context()
|
ctx := c.Request.Context()
|
||||||
var count int64
|
var count int64
|
||||||
if err := db.DB(ctx).Table("users").Where("username = ?", req.Username).Count(&count).Error; err != nil {
|
if err := db.DB(ctx).Model(&model.User{}).Where("username = ?", req.Username).Count(&count).Error; err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, util.Err(err.Error()))
|
c.JSON(http.StatusInternalServerError, util.Err(err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ func startBatchWorker() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
b, err := db.ChConn.PrepareBatch(ctx, "INSERT INTO user_access_logs (id, user_id, path, method, ip, user_agent, headers, status, latency, created_at)")
|
b, err := db.ChConn.PrepareBatch(ctx, "INSERT INTO w_user_access_logs (id, user_id, path, method, ip, user_agent, headers, status, latency, created_at)")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.ErrorF(ctx, "[RiskControl] Prepare ClickHouse batch failed: %v", err)
|
logger.ErrorF(ctx, "[RiskControl] Prepare ClickHouse batch failed: %v", err)
|
||||||
batch = nil
|
batch = nil
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ func TestLoginRequiresPasswordChangeForInitialPlaintextAdmin(t *testing.T) {
|
|||||||
)
|
)
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
if err := dbConn.Exec(
|
if err := dbConn.Exec(
|
||||||
`INSERT INTO users (id, username, password, nickname, is_active, is_admin, last_login_at, created_at, updated_at)
|
`INSERT INTO w_users (id, username, password, nickname, is_active, is_admin, last_login_at, created_at, updated_at)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||||
adminID,
|
adminID,
|
||||||
adminUsername,
|
adminUsername,
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
-- +goose Up
|
||||||
|
ALTER TABLE users RENAME TO w_users;
|
||||||
|
ALTER TABLE auth_sources RENAME TO w_auth_sources;
|
||||||
|
ALTER TABLE external_accounts RENAME TO w_external_accounts;
|
||||||
|
ALTER TABLE system_configs RENAME TO w_system_configs;
|
||||||
|
ALTER TABLE uploads RENAME TO w_uploads;
|
||||||
|
ALTER TABLE access_tokens RENAME TO w_access_tokens;
|
||||||
|
ALTER TABLE task_executions RENAME TO w_task_executions;
|
||||||
|
ALTER TABLE templates RENAME TO w_templates;
|
||||||
|
ALTER TABLE schedules RENAME TO w_schedules;
|
||||||
|
|
||||||
|
-- Rename indexes for consistency
|
||||||
|
ALTER INDEX IF EXISTS idx_users_email RENAME TO idx_w_users_email;
|
||||||
|
ALTER INDEX IF EXISTS idx_users_is_active RENAME TO idx_w_users_is_active;
|
||||||
|
ALTER INDEX IF EXISTS idx_users_last_login_at RENAME TO idx_w_users_last_login_at;
|
||||||
|
ALTER INDEX IF EXISTS idx_users_created_at RENAME TO idx_w_users_created_at;
|
||||||
|
ALTER INDEX IF EXISTS idx_auth_sources_is_active RENAME TO idx_w_auth_sources_is_active;
|
||||||
|
ALTER INDEX IF EXISTS idx_external_accounts_auth_source_id RENAME TO idx_w_external_accounts_auth_source_id;
|
||||||
|
ALTER INDEX IF EXISTS idx_external_accounts_user_id RENAME TO idx_w_external_accounts_user_id;
|
||||||
|
ALTER INDEX IF EXISTS idx_external_accounts_source_external RENAME TO idx_w_external_accounts_source_external;
|
||||||
|
ALTER INDEX IF EXISTS idx_uploads_user_id RENAME TO idx_w_uploads_user_id;
|
||||||
|
ALTER INDEX IF EXISTS idx_uploads_file_path RENAME TO idx_w_uploads_file_path;
|
||||||
|
ALTER INDEX IF EXISTS idx_uploads_hash RENAME TO idx_w_uploads_hash;
|
||||||
|
ALTER INDEX IF EXISTS idx_uploads_type RENAME TO idx_w_uploads_type;
|
||||||
|
ALTER INDEX IF EXISTS idx_access_tokens_user_id RENAME TO idx_w_access_tokens_user_id;
|
||||||
|
ALTER INDEX IF EXISTS idx_task_executions_task_type RENAME TO idx_w_task_executions_task_type;
|
||||||
|
ALTER INDEX IF EXISTS idx_task_executions_status RENAME TO idx_w_task_executions_status;
|
||||||
|
ALTER INDEX IF EXISTS idx_task_executions_started_at RENAME TO idx_w_task_executions_started_at;
|
||||||
|
ALTER INDEX IF EXISTS idx_task_executions_created_at RENAME TO idx_w_task_executions_created_at;
|
||||||
|
ALTER INDEX IF EXISTS idx_templates_is_system RENAME TO idx_w_templates_is_system;
|
||||||
|
ALTER INDEX IF EXISTS idx_templates_created_at RENAME TO idx_w_templates_created_at;
|
||||||
|
ALTER INDEX IF EXISTS idx_templates_updated_at RENAME TO idx_w_templates_updated_at;
|
||||||
|
ALTER INDEX IF EXISTS idx_schedules_is_active RENAME TO idx_w_schedules_is_active;
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
ALTER INDEX IF EXISTS idx_w_schedules_is_active RENAME TO idx_schedules_is_active;
|
||||||
|
ALTER INDEX IF EXISTS idx_w_templates_updated_at RENAME TO idx_templates_updated_at;
|
||||||
|
ALTER INDEX IF EXISTS idx_w_templates_created_at RENAME TO idx_templates_created_at;
|
||||||
|
ALTER INDEX IF EXISTS idx_w_templates_is_system RENAME TO idx_templates_is_system;
|
||||||
|
ALTER INDEX IF EXISTS idx_w_task_executions_created_at RENAME TO idx_task_executions_created_at;
|
||||||
|
ALTER INDEX IF EXISTS idx_w_task_executions_started_at RENAME TO idx_task_executions_started_at;
|
||||||
|
ALTER INDEX IF EXISTS idx_w_task_executions_status RENAME TO idx_task_executions_status;
|
||||||
|
ALTER INDEX IF EXISTS idx_w_task_executions_task_type RENAME TO idx_task_executions_task_type;
|
||||||
|
ALTER INDEX IF EXISTS idx_w_access_tokens_user_id RENAME TO idx_access_tokens_user_id;
|
||||||
|
ALTER INDEX IF EXISTS idx_w_uploads_type RENAME TO idx_uploads_type;
|
||||||
|
ALTER INDEX IF EXISTS idx_w_uploads_hash RENAME TO idx_uploads_hash;
|
||||||
|
ALTER INDEX IF EXISTS idx_w_uploads_file_path RENAME TO idx_uploads_file_path;
|
||||||
|
ALTER INDEX IF EXISTS idx_w_uploads_user_id RENAME TO idx_uploads_user_id;
|
||||||
|
ALTER INDEX IF EXISTS idx_w_external_accounts_source_external RENAME TO idx_external_accounts_source_external;
|
||||||
|
ALTER INDEX IF EXISTS idx_w_external_accounts_user_id RENAME TO idx_external_accounts_user_id;
|
||||||
|
ALTER INDEX IF EXISTS idx_w_external_accounts_auth_source_id RENAME TO idx_external_accounts_auth_source_id;
|
||||||
|
ALTER INDEX IF EXISTS idx_w_auth_sources_is_active RENAME TO idx_auth_sources_is_active;
|
||||||
|
ALTER INDEX IF EXISTS idx_w_users_created_at RENAME TO idx_users_created_at;
|
||||||
|
ALTER INDEX IF EXISTS idx_w_users_last_login_at RENAME TO idx_users_last_login_at;
|
||||||
|
ALTER INDEX IF EXISTS idx_w_users_is_active RENAME TO idx_users_is_active;
|
||||||
|
ALTER INDEX IF EXISTS idx_w_users_email RENAME TO idx_users_email;
|
||||||
|
|
||||||
|
ALTER TABLE w_schedules RENAME TO schedules;
|
||||||
|
ALTER TABLE w_templates RENAME TO templates;
|
||||||
|
ALTER TABLE w_task_executions RENAME TO task_executions;
|
||||||
|
ALTER TABLE w_access_tokens RENAME TO access_tokens;
|
||||||
|
ALTER TABLE w_uploads RENAME TO uploads;
|
||||||
|
ALTER TABLE w_system_configs RENAME TO system_configs;
|
||||||
|
ALTER TABLE w_external_accounts RENAME TO external_accounts;
|
||||||
|
ALTER TABLE w_auth_sources RENAME TO auth_sources;
|
||||||
|
ALTER TABLE w_users RENAME TO users;
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
-- +goose Up
|
||||||
|
ALTER TABLE users RENAME TO w_users;
|
||||||
|
ALTER TABLE auth_sources RENAME TO w_auth_sources;
|
||||||
|
ALTER TABLE external_accounts RENAME TO w_external_accounts;
|
||||||
|
ALTER TABLE system_configs RENAME TO w_system_configs;
|
||||||
|
ALTER TABLE uploads RENAME TO w_uploads;
|
||||||
|
ALTER TABLE access_tokens RENAME TO w_access_tokens;
|
||||||
|
ALTER TABLE task_executions RENAME TO w_task_executions;
|
||||||
|
ALTER TABLE templates RENAME TO w_templates;
|
||||||
|
ALTER TABLE schedules RENAME TO w_schedules;
|
||||||
|
|
||||||
|
-- Drop and Recreate SQLite indexes
|
||||||
|
DROP INDEX IF EXISTS idx_users_email;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_w_users_email ON w_users (email);
|
||||||
|
DROP INDEX IF EXISTS idx_users_is_active;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_w_users_is_active ON w_users (is_active);
|
||||||
|
DROP INDEX IF EXISTS idx_users_last_login_at;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_w_users_last_login_at ON w_users (last_login_at);
|
||||||
|
DROP INDEX IF EXISTS idx_users_created_at;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_w_users_created_at ON w_users (created_at);
|
||||||
|
|
||||||
|
DROP INDEX IF EXISTS idx_auth_sources_is_active;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_w_auth_sources_is_active ON w_auth_sources (is_active);
|
||||||
|
|
||||||
|
DROP INDEX IF EXISTS idx_external_accounts_auth_source_id;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_w_external_accounts_auth_source_id ON w_external_accounts (auth_source_id);
|
||||||
|
DROP INDEX IF EXISTS idx_external_accounts_user_id;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_w_external_accounts_user_id ON w_external_accounts (user_id);
|
||||||
|
DROP INDEX IF EXISTS idx_external_accounts_source_external;
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_w_external_accounts_source_external ON w_external_accounts (auth_source_id, external_id);
|
||||||
|
|
||||||
|
DROP INDEX IF EXISTS idx_uploads_user_id;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_w_uploads_user_id ON w_uploads (user_id);
|
||||||
|
DROP INDEX IF EXISTS idx_uploads_file_path;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_w_uploads_file_path ON w_uploads (file_path);
|
||||||
|
DROP INDEX IF EXISTS idx_uploads_hash;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_w_uploads_hash ON w_uploads (hash);
|
||||||
|
DROP INDEX IF EXISTS idx_uploads_type;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_w_uploads_type ON w_uploads (type);
|
||||||
|
|
||||||
|
DROP INDEX IF EXISTS idx_access_tokens_user_id;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_w_access_tokens_user_id ON w_access_tokens (user_id);
|
||||||
|
|
||||||
|
DROP INDEX IF EXISTS idx_task_executions_task_type;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_w_task_executions_task_type ON w_task_executions (task_type);
|
||||||
|
DROP INDEX IF EXISTS idx_task_executions_status;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_w_task_executions_status ON w_task_executions (status);
|
||||||
|
DROP INDEX IF EXISTS idx_task_executions_started_at;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_w_task_executions_started_at ON w_task_executions (started_at);
|
||||||
|
DROP INDEX IF EXISTS idx_task_executions_created_at;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_w_task_executions_created_at ON w_task_executions (created_at);
|
||||||
|
|
||||||
|
DROP INDEX IF EXISTS idx_templates_is_system;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_w_templates_is_system ON w_templates (is_system);
|
||||||
|
DROP INDEX IF EXISTS idx_templates_created_at;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_w_templates_created_at ON w_templates (created_at);
|
||||||
|
DROP INDEX IF EXISTS idx_templates_updated_at;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_w_templates_updated_at ON w_templates (updated_at);
|
||||||
|
|
||||||
|
DROP INDEX IF EXISTS idx_schedules_is_active;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_w_schedules_is_active ON w_schedules (is_active);
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
ALTER TABLE w_schedules RENAME TO schedules;
|
||||||
|
ALTER TABLE w_templates RENAME TO templates;
|
||||||
|
ALTER TABLE w_task_executions RENAME TO task_executions;
|
||||||
|
ALTER TABLE w_access_tokens RENAME TO access_tokens;
|
||||||
|
ALTER TABLE w_uploads RENAME TO uploads;
|
||||||
|
ALTER TABLE w_system_configs RENAME TO system_configs;
|
||||||
|
ALTER TABLE w_external_accounts RENAME TO external_accounts;
|
||||||
|
ALTER TABLE w_auth_sources RENAME TO auth_sources;
|
||||||
|
ALTER TABLE w_users RENAME TO users;
|
||||||
|
|
||||||
|
-- Revert indexes
|
||||||
|
DROP INDEX IF EXISTS idx_w_users_email;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_users_email ON users (email);
|
||||||
|
DROP INDEX IF EXISTS idx_w_users_is_active;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_users_is_active ON users (is_active);
|
||||||
|
DROP INDEX IF EXISTS idx_w_users_last_login_at;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_users_last_login_at ON users (last_login_at);
|
||||||
|
DROP INDEX IF EXISTS idx_w_users_created_at;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_users_created_at ON users (created_at);
|
||||||
|
|
||||||
|
DROP INDEX IF EXISTS idx_w_auth_sources_is_active;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_auth_sources_is_active ON auth_sources (is_active);
|
||||||
|
|
||||||
|
DROP INDEX IF EXISTS idx_w_external_accounts_auth_source_id;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_external_accounts_auth_source_id ON external_accounts (auth_source_id);
|
||||||
|
DROP INDEX IF EXISTS idx_w_external_accounts_user_id;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_external_accounts_user_id ON external_accounts (user_id);
|
||||||
|
DROP INDEX IF EXISTS idx_w_external_accounts_source_external;
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_external_accounts_source_external ON external_accounts (auth_source_id, external_id);
|
||||||
|
|
||||||
|
DROP INDEX IF EXISTS idx_w_uploads_user_id;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_uploads_user_id ON uploads (user_id);
|
||||||
|
DROP INDEX IF EXISTS idx_w_uploads_file_path;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_uploads_file_path ON uploads (file_path);
|
||||||
|
DROP INDEX IF EXISTS idx_w_uploads_hash;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_uploads_hash ON uploads (hash);
|
||||||
|
DROP INDEX IF EXISTS idx_w_uploads_type;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_uploads_type ON uploads (type);
|
||||||
|
|
||||||
|
DROP INDEX IF EXISTS idx_w_access_tokens_user_id;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_access_tokens_user_id ON access_tokens (user_id);
|
||||||
|
|
||||||
|
DROP INDEX IF EXISTS idx_w_task_executions_task_type;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_task_executions_task_type ON task_executions (task_type);
|
||||||
|
DROP INDEX IF EXISTS idx_w_task_executions_status;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_task_executions_status ON task_executions (status);
|
||||||
|
DROP INDEX IF EXISTS idx_w_task_executions_started_at;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_task_executions_started_at ON task_executions (started_at);
|
||||||
|
DROP INDEX IF EXISTS idx_w_task_executions_created_at;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_task_executions_created_at ON task_executions (created_at);
|
||||||
|
|
||||||
|
DROP INDEX IF EXISTS idx_w_templates_is_system;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_templates_is_system ON templates (is_system);
|
||||||
|
DROP INDEX IF EXISTS idx_w_templates_created_at;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_templates_created_at ON templates (created_at);
|
||||||
|
DROP INDEX IF EXISTS idx_w_templates_updated_at;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_templates_updated_at ON templates (updated_at);
|
||||||
|
|
||||||
|
DROP INDEX IF EXISTS idx_w_schedules_is_active;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_schedules_is_active ON schedules (is_active);
|
||||||
@@ -35,15 +35,15 @@ func TestMigrateInitializesSQLiteDatabase(t *testing.T) {
|
|||||||
Migrate()
|
Migrate()
|
||||||
|
|
||||||
var systemConfigCount int64
|
var systemConfigCount int64
|
||||||
if err := sqliteDB.Table("system_configs").Count(&systemConfigCount).Error; err != nil {
|
if err := sqliteDB.Table("w_system_configs").Count(&systemConfigCount).Error; err != nil {
|
||||||
t.Fatalf("Migrate() count system_configs error = %v", err)
|
t.Fatalf("Migrate() count w_system_configs error = %v", err)
|
||||||
}
|
}
|
||||||
if systemConfigCount != 23 {
|
if systemConfigCount != 23 {
|
||||||
t.Errorf("Migrate() system_configs count = %d, want %d", systemConfigCount, 23)
|
t.Errorf("Migrate() w_system_configs count = %d, want %d", systemConfigCount, 23)
|
||||||
}
|
}
|
||||||
|
|
||||||
var adminCount int64
|
var adminCount int64
|
||||||
if err := sqliteDB.Table("users").Where("username = ?", "admin").Count(&adminCount).Error; err != nil {
|
if err := sqliteDB.Table("w_users").Where("username = ?", "admin").Count(&adminCount).Error; err != nil {
|
||||||
t.Fatalf("Migrate() count admin user error = %v", err)
|
t.Fatalf("Migrate() count admin user error = %v", err)
|
||||||
}
|
}
|
||||||
if adminCount != 1 {
|
if adminCount != 1 {
|
||||||
@@ -51,7 +51,7 @@ func TestMigrateInitializesSQLiteDatabase(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var templateCount int64
|
var templateCount int64
|
||||||
if err := sqliteDB.Table("templates").Count(&templateCount).Error; err != nil {
|
if err := sqliteDB.Table("w_templates").Count(&templateCount).Error; err != nil {
|
||||||
t.Fatalf("Migrate() count templates error = %v", err)
|
t.Fatalf("Migrate() count templates error = %v", err)
|
||||||
}
|
}
|
||||||
if templateCount != 2 {
|
if templateCount != 2 {
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ type AccessToken struct {
|
|||||||
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
|
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TableName 表名
|
||||||
|
func (AccessToken) TableName() string {
|
||||||
|
return "w_access_tokens"
|
||||||
|
}
|
||||||
|
|
||||||
// GenerateTokenString 生成加密安全的随机 Token 值
|
// GenerateTokenString 生成加密安全的随机 Token 值
|
||||||
func GenerateTokenString() (string, error) {
|
func GenerateTokenString() (string, error) {
|
||||||
bytes := make([]byte, tokenByteLength)
|
bytes := make([]byte, tokenByteLength)
|
||||||
|
|||||||
@@ -38,6 +38,11 @@ type AuthSource struct {
|
|||||||
ClientSecretConfigured bool `json:"client_secret_configured" gorm:"-"`
|
ClientSecretConfigured bool `json:"client_secret_configured" gorm:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TableName 表名
|
||||||
|
func (AuthSource) TableName() string {
|
||||||
|
return "w_auth_sources"
|
||||||
|
}
|
||||||
|
|
||||||
// ExternalAccount 外部账号绑定实体
|
// ExternalAccount 外部账号绑定实体
|
||||||
type ExternalAccount struct {
|
type ExternalAccount struct {
|
||||||
ID uint64 `json:"id" gorm:"primaryKey"`
|
ID uint64 `json:"id" gorm:"primaryKey"`
|
||||||
@@ -50,6 +55,11 @@ type ExternalAccount struct {
|
|||||||
UpdatedAt time.Time `json:"updated_at"`
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TableName 表名
|
||||||
|
func (ExternalAccount) TableName() string {
|
||||||
|
return "w_external_accounts"
|
||||||
|
}
|
||||||
|
|
||||||
// ExternalAccountView 外部帐号绑定视图(脱敏展示用)
|
// ExternalAccountView 外部帐号绑定视图(脱敏展示用)
|
||||||
type ExternalAccountView struct {
|
type ExternalAccountView struct {
|
||||||
ID uint64 `json:"id"`
|
ID uint64 `json:"id"`
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ type Schedule struct {
|
|||||||
|
|
||||||
// TableName 表名
|
// TableName 表名
|
||||||
func (Schedule) TableName() string {
|
func (Schedule) TableName() string {
|
||||||
return "schedules"
|
return "w_schedules"
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateSchedule 创建定时任务
|
// CreateSchedule 创建定时任务
|
||||||
|
|||||||
@@ -68,6 +68,11 @@ type SystemConfig struct {
|
|||||||
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
|
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TableName 表名
|
||||||
|
func (SystemConfig) TableName() string {
|
||||||
|
return "w_system_configs"
|
||||||
|
}
|
||||||
|
|
||||||
// GetByKey 通过 key 查询配置(带 Redis 缓存)
|
// GetByKey 通过 key 查询配置(带 Redis 缓存)
|
||||||
func (sc *SystemConfig) GetByKey(ctx context.Context, key string) error {
|
func (sc *SystemConfig) GetByKey(ctx context.Context, key string) error {
|
||||||
if db.Redis != nil {
|
if db.Redis != nil {
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ type TaskExecution struct {
|
|||||||
|
|
||||||
// TableName 表名
|
// TableName 表名
|
||||||
func (TaskExecution) TableName() string {
|
func (TaskExecution) TableName() string {
|
||||||
return "task_executions"
|
return "w_task_executions"
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateTaskExecution 创建任务执行记录
|
// CreateTaskExecution 创建任务执行记录
|
||||||
|
|||||||
@@ -338,5 +338,5 @@ func TestListTaskExecutionsDefaultPaging(t *testing.T) {
|
|||||||
|
|
||||||
func TestTaskExecutionTableName(t *testing.T) {
|
func TestTaskExecutionTableName(t *testing.T) {
|
||||||
execution := TaskExecution{}
|
execution := TaskExecution{}
|
||||||
assert.Equal(t, "task_executions", execution.TableName())
|
assert.Equal(t, "w_task_executions", execution.TableName())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,11 @@ type Template struct {
|
|||||||
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime;index"`
|
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime;index"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TableName 表名
|
||||||
|
func (Template) TableName() string {
|
||||||
|
return "w_templates"
|
||||||
|
}
|
||||||
|
|
||||||
// Normalize 规范化模板字段
|
// Normalize 规范化模板字段
|
||||||
func (t *Template) Normalize() {
|
func (t *Template) Normalize() {
|
||||||
t.Key = strings.TrimSpace(t.Key)
|
t.Key = strings.TrimSpace(t.Key)
|
||||||
|
|||||||
@@ -47,3 +47,8 @@ type Upload struct {
|
|||||||
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
|
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
|
||||||
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
|
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TableName 表名
|
||||||
|
func (Upload) TableName() string {
|
||||||
|
return "w_uploads"
|
||||||
|
}
|
||||||
|
|||||||
@@ -62,6 +62,11 @@ type User struct {
|
|||||||
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime;index"`
|
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime;index"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TableName 表名
|
||||||
|
func (User) TableName() string {
|
||||||
|
return "w_users"
|
||||||
|
}
|
||||||
|
|
||||||
// SetPassword 设置明文密码
|
// SetPassword 设置明文密码
|
||||||
func (u *User) SetPassword(password string) error {
|
func (u *User) SetPassword(password string) error {
|
||||||
u.Password = password
|
u.Password = password
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ CREATE DATABASE IF NOT EXISTS wavelet;
|
|||||||
|
|
||||||
USE wavelet;
|
USE wavelet;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS user_access_logs
|
CREATE TABLE IF NOT EXISTS w_user_access_logs
|
||||||
(
|
(
|
||||||
id UInt64,
|
id UInt64,
|
||||||
user_id UInt64,
|
user_id UInt64,
|
||||||
|
|||||||
Reference in New Issue
Block a user