alpha
This commit is contained in:
parent
a6461a9a0e
commit
a45ddf13d5
2 changed files with 22 additions and 5 deletions
|
@ -3,6 +3,7 @@ server:
|
||||||
database:
|
database:
|
||||||
driver: sqlite
|
driver: sqlite
|
||||||
dsn: otpm.sqlite
|
dsn: otpm.sqlite
|
||||||
|
skip_migration: false
|
||||||
port: 8080
|
port: 8080
|
||||||
|
|
||||||
auth:
|
auth:
|
||||||
|
|
|
@ -37,12 +37,28 @@ func InitDB() (*sqlx.DB, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func MigrateDB(db *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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue