<- 不创建数据库字段

This commit is contained in:
Lunny Xiao 2021-08-04 13:16:13 +08:00
parent f22b0cc369
commit 2fd18aa1b3
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
6 changed files with 22 additions and 3 deletions

View File

@ -629,6 +629,9 @@ func (db *mssql) CreateTableSQL(table *schemas.Table, tableName string) ([]strin
for _, colName := range table.ColumnsSeq() { for _, colName := range table.ColumnsSeq() {
col := table.GetColumn(colName) col := table.GetColumn(colName)
if !col.Creatable() { // ignore <- tag column
continue
}
s, _ := ColumnString(db, col, col.IsPrimaryKey && len(pkList) == 1) s, _ := ColumnString(db, col, col.IsPrimaryKey && len(pkList) == 1)
sql += s sql += s
sql = strings.TrimSpace(sql) sql = strings.TrimSpace(sql)

View File

@ -641,6 +641,9 @@ func (db *mysql) CreateTableSQL(table *schemas.Table, tableName string) ([]strin
for _, colName := range table.ColumnsSeq() { for _, colName := range table.ColumnsSeq() {
col := table.GetColumn(colName) col := table.GetColumn(colName)
if !col.Creatable() { // ignore <- tag column
continue
}
s, _ := ColumnString(db, col, col.IsPrimaryKey && len(pkList) == 1) s, _ := ColumnString(db, col, col.IsPrimaryKey && len(pkList) == 1)
sql += s sql += s
sql = strings.TrimSpace(sql) sql = strings.TrimSpace(sql)

View File

@ -612,9 +612,9 @@ func (db *oracle) CreateTableSQL(table *schemas.Table, tableName string) ([]stri
for _, colName := range table.ColumnsSeq() { for _, colName := range table.ColumnsSeq() {
col := table.GetColumn(colName) col := table.GetColumn(colName)
/*if col.IsPrimaryKey && len(pkList) == 1 { if !col.Creatable() { // ignore <- tag column
sql += col.String(b.dialect) continue
} else {*/ }
s, _ := ColumnString(db, col, false) s, _ := ColumnString(db, col, false)
sql += s sql += s
// } // }

View File

@ -981,6 +981,10 @@ func (db *postgres) CreateTableSQL(table *schemas.Table, tableName string) ([]st
for _, colName := range table.ColumnsSeq() { for _, colName := range table.ColumnsSeq() {
col := table.GetColumn(colName) col := table.GetColumn(colName)
if !col.Creatable() { // ignore <- tag column
continue
}
s, _ := ColumnString(db, col, col.IsPrimaryKey && len(pkList) == 1) s, _ := ColumnString(db, col, col.IsPrimaryKey && len(pkList) == 1)
sql += s sql += s
sql = strings.TrimSpace(sql) sql = strings.TrimSpace(sql)

View File

@ -301,6 +301,10 @@ func (db *sqlite3) CreateTableSQL(table *schemas.Table, tableName string) ([]str
for _, colName := range table.ColumnsSeq() { for _, colName := range table.ColumnsSeq() {
col := table.GetColumn(colName) col := table.GetColumn(colName)
if !col.Creatable() { // ignore <- tag column
continue
}
s, _ := ColumnString(db, col, col.IsPrimaryKey && len(pkList) == 1) s, _ := ColumnString(db, col, col.IsPrimaryKey && len(pkList) == 1)
sql += s sql += s
sql = strings.TrimSpace(sql) sql = strings.TrimSpace(sql)

View File

@ -74,6 +74,11 @@ func NewColumn(name, fieldName string, sqlType SQLType, len1, len2 int, nullable
} }
} }
// Creatable returns true if the column needs to be created when sync
func (col *Column) Creatable() bool {
return col.MapType != ONLYFROMDB
}
// ValueOf returns column's filed of struct's value // ValueOf returns column's filed of struct's value
func (col *Column) ValueOf(bean interface{}) (*reflect.Value, error) { func (col *Column) ValueOf(bean interface{}) (*reflect.Value, error) {
dataStruct := reflect.Indirect(reflect.ValueOf(bean)) dataStruct := reflect.Indirect(reflect.ValueOf(bean))