From a45ddf13d5f06d9a9b497637643471123fd6ce95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CxHuPo=E2=80=9D?= <7513325+vrocwang@users.noreply.github.com> Date: Fri, 23 May 2025 14:15:48 +0800 Subject: [PATCH] alpha --- config.yaml | 3 ++- database/database.go | 24 ++++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/config.yaml b/config.yaml index f411f36..7ab9dcb 100644 --- a/config.yaml +++ b/config.yaml @@ -3,6 +3,7 @@ server: database: driver: sqlite dsn: otpm.sqlite + skip_migration: false port: 8080 auth: @@ -11,4 +12,4 @@ auth: wechat: appid: "wx57d1033974eb5250" - secret: "be494c2a81df685a40b9a74e1736b15d" + secret: "be494c2a81df685a40b9a74e1736b15d" \ No newline at end of file diff --git a/database/database.go b/database/database.go index be8aa03..bad6d8f 100644 --- a/database/database.go +++ b/database/database.go @@ -37,12 +37,28 @@ func InitDB() (*sqlx.DB, error) { } func MigrateDB(db *sqlx.DB) error { - if _, err := db.Exec(userTable); err != nil { - return fmt.Errorf("failed to create user migration: %w", err) + // 检查是否需要执行迁移 + skipMigration := viper.GetBool("database.skip_migration") + if skipMigration { + log.Println("Skipping database migration as configured") + return nil } - if _, err := db.Exec(otpTable); err != nil { - return fmt.Errorf("failed to create otp migration: %w", err) + // 执行用户表迁移 + if _, err := db.Exec(userTable); err != nil { + log.Printf("Warning: failed to create user migration: %v", err) + // 继续执行,不返回错误 + } else { + log.Println("User table migration completed successfully") } + + // 执行OTP表迁移 + if _, err := db.Exec(otpTable); err != nil { + log.Printf("Warning: failed to create otp migration: %v", err) + // 继续执行,不返回错误 + } else { + log.Println("OTP table migration completed successfully") + } + return nil }