From c3fb48f473edfd7e6e216a7a7ef3ebd68aaf33a0 Mon Sep 17 00:00:00 2001 From: hanpeng <36978417+hanpenggit@users.noreply.github.com> Date: Thu, 20 Jan 2022 13:50:20 +0800 Subject: [PATCH] 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 --- conf/app.conf | 1 + object/adapter.go | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/conf/app.conf b/conf/app.conf index f53c1ce8..1920d9d1 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -6,6 +6,7 @@ copyrequestbody = true driverName = mysql dataSourceName = root:123456@tcp(localhost:3306)/ dbName = casdoor +tableNamePrefix= showSql = false redisEndpoint = defaultStorageProvider = diff --git a/object/adapter.go b/object/adapter.go index f1160704..f5cc840c 100644 --- a/object/adapter.go +++ b/object/adapter.go @@ -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)