dzwvip / oracle

gorm-oracle godror
Other
21 stars 10 forks source link

Should every migratior.HasTable's stmt has Schema? #6

Closed jiarung closed 1 year ago

jiarung commented 1 year ago

Since RunWIthValue supports the condition with stms.Schema == nil, which means such schema doesn't exist or the statement is illegal. (blame me if I am wrong) Then if we don't check the schema does exist, then we have a panic for a non-exist schema without any prompts.

So may we convert the HasTable's first condition from

...
   53         if strings.Contains(stmt.Schema.Table, ".") {
   54             ownertable := strings.Split(stmt.Schema.Table, ".")
   55             return m.DB.Raw("SELECT COUNT(*) FROM ALL_TABLES WHERE OWNER = ?  and  TABLE_NAME = ?", ownertable[0], ownertable[1]).Row().Scan(&count)
   56         } else {
...

to

...
   53         if stmt.Schema != nil && strings.Contains(stmt.Schema.Table, ".") {
   54             ownertable := strings.Split(stmt.Schema.Table, ".")
   55             return m.DB.Raw("SELECT COUNT(*) FROM ALL_TABLES WHERE OWNER = ?  and  TABLE_NAME = ?", ownertable[0], ownertable[1]).Row().Scan(&count)
   56         } else {
...

Thanks!

dzwvip commented 1 year ago

fixed