fix: Add a configuration that can set the table prefix. There is no prefix by default (#432)

* fix: Add a configuration that can set the table prefix. There is no prefix by default

* fix: Add a configuration that can set the table prefix. There is no prefix by default
This commit is contained in:
hanpeng 2022-01-20 13:50:20 +08:00 committed by GitHub
parent a111fd672c
commit c3fb48f473
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View File

@ -6,6 +6,7 @@ copyrequestbody = true
driverName = mysql
dataSourceName = root:123456@tcp(localhost:3306)/
dbName = casdoor
tableNamePrefix=
showSql = false
redisEndpoint =
defaultStorageProvider =

View File

@ -17,6 +17,7 @@ package object
import (
"fmt"
"runtime"
"xorm.io/core"
"github.com/astaxie/beego"
"github.com/casbin/casdoor/conf"
@ -113,6 +114,10 @@ func (a *Adapter) createTable() {
showSql, _ := beego.AppConfig.Bool("showSql")
a.Engine.ShowSQL(showSql)
tableNamePrefix := beego.AppConfig.String("tableNamePrefix")
tbMapper := core.NewPrefixMapper(core.SnakeMapper{}, tableNamePrefix)
a.Engine.SetTableMapper(tbMapper)
err := a.Engine.Sync2(new(Organization))
if err != nil {
panic(err)