nightingale icon indicating copy to clipboard operation
nightingale copied to clipboard

[DB]配置项 TablePrefix 不生效

Open igotcha opened this issue 10 months ago • 2 comments

Your config.toml

[DB]
# postgres: host=%s port=%s user=%s dbname=%s password=%s sslmode=%s
# postgres: DSN="host=127.0.0.1 port=5432 user=root dbname=n9e_v6 password=1234 sslmode=disable"
DSN = "root:1234@tcp(127.0.0.1:3306)/n9e_v6?charset=utf8mb4&parseTime=True&loc=Local&allowNativePasswords=true"
# enable debug mode or not
Debug = false
# mysql postgres
DBType = "mysql"
# unit: s
MaxLifetime = 7200
# max open connections
MaxOpenConns = 150
# max idle connections
MaxIdleConns = 50
# table prefix
TablePrefix = "someprefix_"
# enable auto migrate or not
# EnableAutoMigrate = false

Relevant logs

2024-04-08 17:04:29.847451 ERROR ormx/ormx.go:66 /home/runner/work/nightingale/nightingale/models/common.go:21 Error 1146: Table 'n9e_v6.role_operation' doesn't exist
[0.254ms] [rows:0] SELECT count(*) FROM `role_operation` WHERE operation = '/alert-mutes/put' and role_name = 'Standard'
2024-04-08 17:04:29.847538 ERROR migrate/migrate.go:132 check role operation exists failed, Error 1146: Table 'n9e_v6.role_operation' doesn't exist
2024-04-08 17:04:29.847799 ERROR ormx/ormx.go:66 /home/runner/work/nightingale/nightingale/models/common.go:21 Error 1146: Table 'n9e_v6.role_operation' doesn't exist
[0.233ms] [rows:0] SELECT count(*) FROM `role_operation` WHERE operation = '/log/index-patterns' and role_name = 'Standard'
2024-04-08 17:04:29.847820 ERROR migrate/migrate.go:132 check role operation exists failed, Error 1146: Table 'n9e_v6.role_operation' doesn't exist
2024-04-08 17:04:29.848052 ERROR ormx/ormx.go:66 /home/runner/work/nightingale/nightingale/models/common.go:21 Error 1146: Table 'n9e_v6.role_operation' doesn't exist
[0.204ms] [rows:0] SELECT count(*) FROM `role_operation` WHERE operation = '/help/variable-configs' and role_name = 'Standard'
2024-04-08 17:04:29.848064 ERROR migrate/migrate.go:132 check role operation exists failed, Error 1146: Table 'n9e_v6.role_operation' doesn't exist
2024-04-08 17:04:29.848263 ERROR ormx/ormx.go:66 /home/runner/work/nightingale/nightingale/models/common.go:21 Error 1146: Table 'n9e_v6.role_operation' doesn't exist
[0.176ms] [rows:0] SELECT count(*) FROM `role_operation` WHERE operation = '/permissions' and role_name = 'Admin'
2024-04-08 17:04:29.848290 ERROR migrate/migrate.go:132 check role operation exists failed, Error 1146: Table 'n9e_v6.role_operation' doesn't exist
2024-04-08 17:04:29.848516 ERROR ormx/ormx.go:66 /home/runner/work/nightingale/nightingale/models/common.go:21 Error 1146: Table 'n9e_v6.role_operation' doesn't exist
[0.205ms] [rows:0] SELECT count(*) FROM `role_operation` WHERE operation = '/ibex-settings' and role_name = 'Standard'
2024-04-08 17:04:29.848543 ERROR migrate/migrate.go:132 check role operation exists failed, Error 1146: Table 'n9e_v6.role_operation' doesn't exist
2024-04-08 17:04:29.850073 ERROR ormx/ormx.go:66 /home/runner/work/nightingale/nightingale/models/user.go:227 Error 1146: Table 'n9e_v6.users' doesn't exist

System info

n9e 7.0.0-beta.2

Steps to reproduce

  1. 按 TablePrefix 建表: CREATE TABLE IF NOT EXISTS someprefix_user_group (
  2. 以 TablePrefix = "someprefix_" 启动 n9e
  3. 报错, 无法启动

Expected behavior

访问表名: someprefix_role_operation

Actual behavior

访问表名: role_operation

Additional info

按gorm的实现, 如果model定义了 TableName() 则优先使用, 导致 NamingStrategy 不生效

igotcha avatar Apr 08 '24 09:04 igotcha

https://github.com/ccfos/nightingale/compare/main...igotcha:nightingale:main 这样应该就可以了

igotcha avatar Apr 09 '24 03:04 igotcha

暂时还没人力调整这块哈

710leo avatar Apr 22 '24 02:04 710leo