Skip to content

Commit ed96a86

Browse files
authored
Merge pull request #2103 from feitianbubu/pr/add-auto-migrate-config
feat: add autoMigrate config
2 parents 2bd804d + 41cfda9 commit ed96a86

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

server/config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ system:
8787
router-prefix: ""
8888
# 严格角色模式 打开后权限将会存在上下级关系
8989
use-strict-auth: false
90+
# 自动迁移数据库表结构,生产环境建议设为false,手动迁移
91+
auto-migrate: false
9092

9193
# captcha configuration
9294
captcha:

server/config/system.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ type System struct {
1111
UseRedis bool `mapstructure:"use-redis" json:"use-redis" yaml:"use-redis"` // 使用redis
1212
UseMongo bool `mapstructure:"use-mongo" json:"use-mongo" yaml:"use-mongo"` // 使用mongo
1313
UseStrictAuth bool `mapstructure:"use-strict-auth" json:"use-strict-auth" yaml:"use-strict-auth"` // 使用树形角色分配模式
14+
AutoMigrate bool `mapstructure:"auto-migrate" json:"auto-migrate" yaml:"auto-migrate"` // 自动迁移数据库表结构,生产环境建议设为false,手动迁移
1415
}

server/initialize/gorm.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ func Gorm() *gorm.DB {
3535
}
3636

3737
func RegisterTables() {
38+
if !global.GVA_CONFIG.System.AutoMigrate {
39+
global.GVA_LOG.Info("auto-migrate is disabled, skipping table registration")
40+
return
41+
}
42+
3843
db := global.GVA_DB
3944
err := db.AutoMigrate(
4045

0 commit comments

Comments
 (0)