Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
二次元的罪恶王冠
beego
提交
9ccd58bf
B
beego
项目概览
二次元的罪恶王冠
/
beego
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
beego
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
9ccd58bf
编写于
9月 07, 2020
作者:
M
Ming Deng
提交者:
GitHub
9月 07, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4211 from flycash/adt/all
allow users to ignore some table when run orm commands
上级
b86cf22f
0f50b07a
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
59 addition
and
1 deletion
+59
-1
pkg/client/orm/cmd.go
pkg/client/orm/cmd.go
+6
-0
pkg/client/orm/models.go
pkg/client/orm/models.go
+1
-1
pkg/client/orm/models_utils.go
pkg/client/orm/models_utils.go
+12
-0
pkg/client/orm/models_utils_test.go
pkg/client/orm/models_utils_test.go
+35
-0
pkg/client/orm/types.go
pkg/client/orm/types.go
+5
-0
未找到文件。
pkg/client/orm/cmd.go
浏览文件 @
9ccd58bf
...
...
@@ -142,6 +142,12 @@ func (d *commandSyncDb) Run() error {
}
for
i
,
mi
:=
range
modelCache
.
allOrdered
()
{
if
!
isApplicableTableForDB
(
mi
.
addrField
,
d
.
al
.
Name
)
{
fmt
.
Printf
(
"table `%s` is not applicable to database '%s'
\n
"
,
mi
.
table
,
d
.
al
.
Name
)
continue
}
if
tables
[
mi
.
table
]
{
if
!
d
.
noInfo
{
fmt
.
Printf
(
"table `%s` already exists, skip
\n
"
,
mi
.
table
)
...
...
pkg/client/orm/models.go
浏览文件 @
9ccd58bf
...
...
@@ -414,7 +414,7 @@ func (mc *_modelCache) getDbDropSQL(al *alias) (queries []string, err error) {
for
_
,
mi
:=
range
modelCache
.
allOrdered
()
{
queries
=
append
(
queries
,
fmt
.
Sprintf
(
`DROP TABLE IF EXISTS %s%s%s`
,
Q
,
mi
.
table
,
Q
))
}
return
queries
,
nil
return
queries
,
nil
}
//getDbCreateSQL get database scheme creation sql queries
...
...
pkg/client/orm/models_utils.go
浏览文件 @
9ccd58bf
...
...
@@ -107,6 +107,18 @@ func getTableUnique(val reflect.Value) [][]string {
return
nil
}
// get whether the table needs to be created for the database alias
func
isApplicableTableForDB
(
val
reflect
.
Value
,
db
string
)
bool
{
fun
:=
val
.
MethodByName
(
"IsApplicableTableForDB"
)
if
fun
.
IsValid
()
{
vals
:=
fun
.
Call
([]
reflect
.
Value
{
reflect
.
ValueOf
(
db
)})
if
len
(
vals
)
>
0
&&
vals
[
0
]
.
Kind
()
==
reflect
.
Bool
{
return
vals
[
0
]
.
Bool
()
}
}
return
true
}
// get snaked column name
func
getColumnName
(
ft
int
,
addrField
reflect
.
Value
,
sf
reflect
.
StructField
,
col
string
)
string
{
column
:=
col
...
...
pkg/client/orm/models_utils_test.go
0 → 100644
浏览文件 @
9ccd58bf
// Copyright 2020
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package
orm
import
(
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
type
NotApplicableModel
struct
{
Id
int
}
func
(
n
*
NotApplicableModel
)
IsApplicableTableForDB
(
db
string
)
bool
{
return
db
==
"default"
}
func
Test_IsApplicableTableForDB
(
t
*
testing
.
T
)
{
assert
.
False
(
t
,
isApplicableTableForDB
(
reflect
.
ValueOf
(
&
NotApplicableModel
{}),
"defa"
))
assert
.
True
(
t
,
isApplicableTableForDB
(
reflect
.
ValueOf
(
&
NotApplicableModel
{}),
"default"
))
}
pkg/client/orm/types.go
浏览文件 @
9ccd58bf
...
...
@@ -75,6 +75,11 @@ type TableUniqueI interface {
TableUnique
()
[][]
string
}
// IsApplicableTableForDB if return false, we won't create table to this db
type
IsApplicableTableForDB
interface
{
IsApplicableTableForDB
(
db
string
)
bool
}
// Driver define database driver
type
Driver
interface
{
Name
()
string
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录