From 2fd18aa1b3a31d96425dfc309bf316dde1453491 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 4 Aug 2021 13:16:13 +0800 Subject: [PATCH] =?UTF-8?q?<-=20=E4=B8=8D=E5=88=9B=E5=BB=BA=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dialects/mssql.go | 3 +++ dialects/mysql.go | 3 +++ dialects/oracle.go | 6 +++--- dialects/postgres.go | 4 ++++ dialects/sqlite3.go | 4 ++++ schemas/column.go | 5 +++++ 6 files changed, 22 insertions(+), 3 deletions(-) diff --git a/dialects/mssql.go b/dialects/mssql.go index 0eeb1bcd..f5c7d893 100644 --- a/dialects/mssql.go +++ b/dialects/mssql.go @@ -629,6 +629,9 @@ func (db *mssql) CreateTableSQL(table *schemas.Table, tableName string) ([]strin for _, colName := range table.ColumnsSeq() { col := table.GetColumn(colName) + if !col.Creatable() { // ignore <- tag column + continue + } s, _ := ColumnString(db, col, col.IsPrimaryKey && len(pkList) == 1) sql += s sql = strings.TrimSpace(sql) diff --git a/dialects/mysql.go b/dialects/mysql.go index 21128527..551777b2 100644 --- a/dialects/mysql.go +++ b/dialects/mysql.go @@ -641,6 +641,9 @@ func (db *mysql) CreateTableSQL(table *schemas.Table, tableName string) ([]strin for _, colName := range table.ColumnsSeq() { col := table.GetColumn(colName) + if !col.Creatable() { // ignore <- tag column + continue + } s, _ := ColumnString(db, col, col.IsPrimaryKey && len(pkList) == 1) sql += s sql = strings.TrimSpace(sql) diff --git a/dialects/oracle.go b/dialects/oracle.go index 11a6653b..00a66aab 100644 --- a/dialects/oracle.go +++ b/dialects/oracle.go @@ -612,9 +612,9 @@ func (db *oracle) CreateTableSQL(table *schemas.Table, tableName string) ([]stri for _, colName := range table.ColumnsSeq() { col := table.GetColumn(colName) - /*if col.IsPrimaryKey && len(pkList) == 1 { - sql += col.String(b.dialect) - } else {*/ + if !col.Creatable() { // ignore <- tag column + continue + } s, _ := ColumnString(db, col, false) sql += s // } diff --git a/dialects/postgres.go b/dialects/postgres.go index 96ebfc85..5485ad3e 100644 --- a/dialects/postgres.go +++ b/dialects/postgres.go @@ -981,6 +981,10 @@ func (db *postgres) CreateTableSQL(table *schemas.Table, tableName string) ([]st for _, colName := range table.ColumnsSeq() { col := table.GetColumn(colName) + if !col.Creatable() { // ignore <- tag column + continue + } + s, _ := ColumnString(db, col, col.IsPrimaryKey && len(pkList) == 1) sql += s sql = strings.TrimSpace(sql) diff --git a/dialects/sqlite3.go b/dialects/sqlite3.go index ac17fd92..1c586abe 100644 --- a/dialects/sqlite3.go +++ b/dialects/sqlite3.go @@ -301,6 +301,10 @@ func (db *sqlite3) CreateTableSQL(table *schemas.Table, tableName string) ([]str for _, colName := range table.ColumnsSeq() { col := table.GetColumn(colName) + if !col.Creatable() { // ignore <- tag column + continue + } + s, _ := ColumnString(db, col, col.IsPrimaryKey && len(pkList) == 1) sql += s sql = strings.TrimSpace(sql) diff --git a/schemas/column.go b/schemas/column.go index 4bbb6c2d..25a69034 100644 --- a/schemas/column.go +++ b/schemas/column.go @@ -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 func (col *Column) ValueOf(bean interface{}) (*reflect.Value, error) { dataStruct := reflect.Indirect(reflect.ValueOf(bean))