-
-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
table names cannot be specified after automatic migration is disabled #162
Comments
@tangyang9464 @closetool @sagilio |
@OldSmokeGun Because the adapter gives the user the right to create the table, customize table name and even table structure will be based on the functions provided by gorm itself. You can customize the table name like this
|
@tangyang9464 Thanks for your answer, but don't you think this limits user only can use the gormadapter.CasbinRule type? Why can't the user's own structure and table name be passed in like the NewAdapterByDBWithCustomTable function? This is extremely scalable for users |
@OldSmokeGun |
As you can see, the NewAdapterWithoutAutoMigrate function uses defaultTableName, and its value is casbin_rule, which means that even if I use a custom structure when migrating, its table name must be casbin_rule, otherwise, how does the adapter know to use which table If there are multiple casbins in a system, this will create conflicts |
@OldSmokeGun Got it. Fix later. |
@tangyang9464 Thanks for your contribution! |
use TurnOffAutoMigrate is Fail, As follows db, err := gorm.Open(mysql.Open("root:ddd@tcp(127.0.0.1:3306)/test"), &gorm.Config{})
gormadapter.TurnOffAutoMigrate(db)
a, err := gormadapter.NewAdapterByDBWithCustomTable(db, nil, "casbin_rule") someone like me? CREATE TABLE `dsc_casbin_rule` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'key',
`ptype` varchar(100) DEFAULT NULL,
`v0` varchar(100) DEFAULT NULL,
`v1` varchar(100) DEFAULT NULL,
`v2` varchar(100) DEFAULT NULL,
`v3` varchar(100) DEFAULT NULL,
`v4` varchar(100) DEFAULT NULL,
`v5` varchar(100) DEFAULT NULL,
`v6` varchar(25) DEFAULT NULL,
`v7` varchar(25) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_casbin_rule` (`ptype`,`v0`,`v1`,`v2`,`v3`),
UNIQUE KEY `idx_dsc_casbin_rule` (`ptype`,`v0`,`v1`,`v2`,`v3`,`v4`,`v5`,`v6`,`v7`) # it is automatically generated
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='casbin rule';
|
@Lee-0x00 db = gormadapter.TurnOffAutoMigrate(db) |
@tangyang9464 this usage is not natural and can easily cause confusion. A call on |
Check it out later |
|
#160
This commit can indeed turn off the automatic migration, but it cannot specify a custom data table name
I try to make a commit, but I don't have the environment for unit testing, so I can't pass the test
Hope the NewAdapterWithoutAutoMigrate function can specify the data table name
The text was updated successfully, but these errors were encountered: