Skip to content
This repository was archived by the owner on Sep 7, 2021. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions session_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,17 @@ func (session *Session) Sync2(beans ...interface{}) error {
if err != nil {
return err
}
tbName := engine.TableName(bean)
tbNameWithSchema := engine.TableName(tbName, true)
var tbName string
if len(session.statement.AltTableName) > 0 {
tbName = session.statement.AltTableName
} else {
tbName = engine.TableName(bean)
}
tbNameWithSchema := engine.tbNameWithSchema(tbName)

var oriTable *core.Table
for _, tb := range tables {
if strings.EqualFold(tb.Name, tbName) {
if strings.EqualFold(engine.tbNameWithSchema(tb.Name), engine.tbNameWithSchema(tbName)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why repeat engine.tbNameWithSchema(tbName)? Isn't that just the same as tbNameWithSchema from above?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tb.Name may have not schema but tbName may have or not.
tbNameWithSchema will check if tbname has schema, if not then add it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant this one:

254    ==>this tbNameWithSchema := engine.tbNameWithSchema(tbName)

vs.

258    if strings.EqualFold(engine.tbNameWithSchema(tb.Name), ==>this engine.tbNameWithSchema(tbName)) {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just know this after I merged. :(

oriTable = tb
break
}
Expand Down
25 changes: 25 additions & 0 deletions session_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,31 @@ func TestSyncTable(t *testing.T) {
assert.EqualValues(t, "sync_table1", tables[0].Name)
}

func TestSyncTable2(t *testing.T) {
assert.NoError(t, prepareEngine())

assert.NoError(t, testEngine.Table("sync_tablex").Sync2(new(SyncTable1)))

tables, err := testEngine.DBMetas()
assert.NoError(t, err)
assert.EqualValues(t, 1, len(tables))
assert.EqualValues(t, "sync_tablex", tables[0].Name)
assert.EqualValues(t, 3, len(tables[0].Columns()))

type SyncTable4 struct {
SyncTable1 `xorm:"extends"`
NewCol string
}

assert.NoError(t, testEngine.Table("sync_tablex").Sync2(new(SyncTable4)))
tables, err = testEngine.DBMetas()
assert.NoError(t, err)
assert.EqualValues(t, 1, len(tables))
assert.EqualValues(t, "sync_tablex", tables[0].Name)
assert.EqualValues(t, 4, len(tables[0].Columns()))
assert.EqualValues(t, colMapper.Obj2Table("NewCol"), tables[0].Columns()[3].Name)
}

func TestIsTableExist(t *testing.T) {
assert.NoError(t, prepareEngine())

Expand Down