Skip to content

Commit

Permalink
Merge pull request #43 from ArtisanCloud/develop
Browse files Browse the repository at this point in the history
reface(database): model full table name
  • Loading branch information
Matrix-X authored Aug 24, 2022
2 parents 3096252 + 2542db7 commit 9d5a53d
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 19 deletions.
11 changes: 8 additions & 3 deletions authorization/rbac/models/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const TABLE_NAME_PERMISSION_MODULE = "rbac_permission_modules"

const PERMISSION_MODULE_UNIQUE_ID = "index_permission_module_id"

var TABLE_FULL_NAME_PERMISSION_MODULE string = "public.ac_" + TABLE_NAME_PERMISSION_MODULE

func NewPermissionModule(mapObject *object.Collection) *PermissionModule {

if mapObject == nil {
Expand All @@ -51,11 +53,14 @@ func NewPermissionModule(mapObject *object.Collection) *PermissionModule {

// 获取当前 Model 的数据库表名称
func (mdl *PermissionModule) GetTableName(needFull bool) string {
tableName := TABLE_NAME_PERMISSION_MODULE
if needFull {
tableName = "public." + tableName
return TABLE_FULL_NAME_PERMISSION_MODULE
} else {
return TABLE_NAME_PERMISSION_MODULE
}
return tableName
}
func (mdl *PermissionModule) SetTableFullName(tableName string) {
TABLE_FULL_NAME_PERMISSION_MODULE = tableName
}

func (mdl *PermissionModule) GetForeignKey() string {
Expand Down
11 changes: 8 additions & 3 deletions authorization/rbac/models/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const TABLE_NAME_PERMISSION = "rbac_permissions"

const PERMISSION_UNIQUE_ID = "index_permission_id"

var TABLE_FULL_NAME_PERMISSION string = "public.ac_" + TABLE_NAME_PERMISSION

const PERMISSION_TYPE_NORMAL int8 = 1
const PERMISSION_TYPE_MODULE int8 = 2

Expand All @@ -56,11 +58,14 @@ func NewPermission(mapObject *object.Collection) *Permission {

// 获取当前 Model 的数据库表名称
func (mdl *Permission) GetTableName(needFull bool) string {
tableName := TABLE_NAME_PERMISSION
if needFull {
tableName = "public." + tableName
return TABLE_FULL_NAME_PERMISSION
} else {
return TABLE_NAME_PERMISSION
}
return tableName
}
func (mdl *Permission) SetTableFullName(tableName string) {
TABLE_FULL_NAME_PERMISSION = tableName
}

func (mdl *Permission) GetForeignKey() string {
Expand Down
11 changes: 8 additions & 3 deletions authorization/rbac/models/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const TABLE_NAME_ROLE = "roles"

const ROLE_UNIQUE_ID = "index_role_id"

var TABLE_FULL_NAME_ROLE string = "public.ac_" + TABLE_NAME_ROLE

const ROLE_TYPE_ALL int8 = 0
const ROLE_TYPE_SYSTEM int8 = 1
const ROLE_TYPE_NORMAL int8 = 2
Expand Down Expand Up @@ -58,11 +60,14 @@ func NewRole(mapObject *object.Collection) *Role {

// 获取当前 Model 的数据库表名称
func (mdl *Role) GetTableName(needFull bool) string {
tableName := TABLE_NAME_ROLE
if needFull {
tableName = "public." + tableName
return TABLE_FULL_NAME_ROLE
} else {
return TABLE_NAME_ROLE
}
return tableName
}
func (mdl *Role) SetTableFullName(tableName string) {
TABLE_FULL_NAME_ROLE = tableName
}

func (mdl *Role) GetForeignKey() string {
Expand Down
10 changes: 10 additions & 0 deletions database/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (

const PAGE_DEFAULT_SIZE = 20

var TABLE_PREFIX string

type ModelInterface interface {
GetTableName(needFull bool) string
GetPowerModel() ModelInterface
Expand Down Expand Up @@ -280,6 +282,14 @@ func UpsertModelsOnUniqueID(db *gorm.DB, mdl interface{}, uniqueName string,
/**
* model methods
*/

func GetTableFullName(schema string, prefix string, tableName string) (fullName string) {

fullName = schema + "." + prefix + tableName

return fullName
}

func GetModelFields(model interface{}) (fields []string) {

// check if it has been loaded
Expand Down
2 changes: 1 addition & 1 deletion database/operationLog.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func NewPowerOperationLog(mapObject *object.Collection) *PowerOperationLog {
func (mdl *PowerOperationLog) GetTableName(needFull bool) string {
tableName := TABLE_NAME_OPERATION_LOG
if needFull {
tableName = "public." + tableName
tableName = "public.ac_" + tableName
}
return tableName
}
Expand Down
12 changes: 9 additions & 3 deletions database/tag/rTagToObject.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,22 @@ const TABLE_NAME_R_TAG_TO_OBJECT = "r_tag_to_object"

const R_TAG_TO_OJECT_UNIQUE_ID = "index_tag_to_object_id"

var TABLE_FULL_NAME_R_TAG_TO_OBJECT string = "public.ac_" + TABLE_NAME_R_TAG_TO_OBJECT

const R_TAG_TO_OJECT_FOREIGN_KEY = "taggable_object_id"
const R_TAG_TO_OJECT_OWNER_KEY = "taggable_owner_type"
const R_TAG_TO_OJECT_JOIN_KEY = "tag_id"

func (mdl *RTagToObject) GetTableName(needFull bool) string {
tableName := TABLE_NAME_R_TAG_TO_OBJECT
if needFull {
tableName = "public" + "." + tableName
return TABLE_FULL_NAME_R_TAG_TO_OBJECT
} else {
return TABLE_NAME_R_TAG_TO_OBJECT
}
return tableName
}

func (mdl *RTagToObject) SetTableFullName(tableName string) {
TABLE_FULL_NAME_R_TAG_TO_OBJECT = tableName
}

func (mdl *RTagToObject) GetForeignKey() string {
Expand Down
12 changes: 9 additions & 3 deletions database/tag/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const TABLE_NAME_TAG = "tags"

const TAG_UNIQUE_ID = "index_tag_id"

var TABLE_FULL_NAME_TAG string = "public.ac_" + TABLE_NAME_TAG

const TAG_TYPE_NORMAL int8 = 1
const TAG_TYPE_STAGE int8 = 2

Expand All @@ -57,11 +59,15 @@ func NewTag(mapObject *object.Collection) *Tag {

// 获取当前 Model 的数据库表名称
func (mdl *Tag) GetTableName(needFull bool) string {
tableName := TABLE_NAME_TAG
if needFull {
tableName = "public." + tableName
return TABLE_FULL_NAME_TAG
} else {
return TABLE_NAME_TAG
}
return tableName
}

func (mdl *Tag) SetTableFullName(tableName string) {
TABLE_FULL_NAME_TAG = tableName
}

func (mdl *Tag) GetForeignKey() string {
Expand Down
13 changes: 10 additions & 3 deletions database/tag/tagGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type TagGroup struct {
const TABLE_NAME_TAG_GROUP = "tag_groups"
const TAG_GROUP_UNIQUE_ID = "index_tag_group_id"

var TABLE_FULL_NAME_TAG_GROUP = "public.ac_" + TABLE_NAME_TAG_GROUP

const DEFAULT_OWNER_TYPE = "default"
const DEFAULT_GROUP_NAME = "默认组"

Expand Down Expand Up @@ -79,12 +81,17 @@ func GetDefaultTagGroup(db *gorm.DB) (defaultTagGroup *TagGroup, err error) {
return defaultTagGroup, err
}

// 获取当前 Model 的数据库表名称
func (mdl *TagGroup) GetTableName(needFull bool) string {
tableName := TABLE_NAME_TAG_GROUP
if needFull {
tableName = "public" + "." + tableName
return TABLE_FULL_NAME_TAG_GROUP
} else {
return TABLE_NAME_TAG_GROUP
}
return tableName
}

func (mdl *TagGroup) SetTableFullName(tableName string) {
TABLE_FULL_NAME_TAG_GROUP = tableName
}

func (mdl *TagGroup) GetComposedUniqueID() string {
Expand Down

0 comments on commit 9d5a53d

Please sign in to comment.