Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
nfjBill committed Feb 18, 2022
1 parent 30d5a5f commit 80a6f88
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
14 changes: 13 additions & 1 deletion dm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ type User struct {
Birthday time.Time
}

type Per struct {
gorm.Model
Key string `gorm:"index:key,unique"`
Name string `gorm:"index:name"`
Age int
Content dmSchema.Clob `gorm:"size:1024000"`
Birthday time.Time
}

func TestAutoMigrate(t *testing.T) {
var err error

Expand All @@ -50,6 +59,9 @@ func TestAutoMigrate(t *testing.T) {
err = Table().AutoMigrate(&User{})
err = Table().AutoMigrate(&User{})
err = Table().AutoMigrate(&User{})
err = Table().AutoMigrate(&Per{})
err = Table().AutoMigrate(&Per{})
err = Table().AutoMigrate(&Per{})

if err != nil {
fmt.Printf("Error: failed to AutoMigrate: %v\n", err)
Expand All @@ -59,7 +71,7 @@ func TestAutoMigrate(t *testing.T) {

func TestCreate(t *testing.T) {
err := Table(&User{Key: "1", Name: "Jinzhu", Age: 18, Content: "asdfdasfasdfasdfj手机卡是点击", Birthday: time.Now()}).Create()
_ = Table(&User{Key: "2", Name: "Jinzhu", Age: 19, Content: "bbb", Birthday: time.Now()}).Create()
_ = Table(&User{Key: "2", Name: "Jinzhu1", Age: 19, Content: "bbb", Birthday: time.Now()}).Create()
_ = Table(&User{Key: "3", Name: "Jinzhu2", Age: 20, Content: "ccc", Birthday: time.Now()}).Create()

if err != nil {
Expand Down
11 changes: 5 additions & 6 deletions migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ type BuildIndexOptionsInterface interface {
}

func (m Migrator) CurrentDatabase() (name string) {
m.DB.Raw(
fmt.Sprintf(`SELECT ORA_DATABASE_NAME as "Current Database" FROM %s`, m.Dialector.(Dialector).DummyTableName()),
).Row().Scan(&name)
m.DB.Raw("SELECT SYS_CONTEXT ('userenv', 'current_schema') FROM DUAL").Row().Scan(&name)
return
}

Expand Down Expand Up @@ -342,9 +340,10 @@ func (m Migrator) HasIndex(value interface{}, name string) bool {
}

return m.DB.Raw(
"SELECT COUNT(*) FROM USER_INDEXES WHERE TABLE_NAME = ? AND INDEX_NAME = ?",
m.Migrator.DB.NamingStrategy.TableName(stmt.Table),
m.Migrator.DB.NamingStrategy.IndexName(stmt.Table, name),
fmt.Sprintf(`SELECT COUNT(*) FROM USER_INDEXES WHERE TABLE_NAME = ('%s') AND INDEX_NAME = ('%s')`,
m.Migrator.DB.NamingStrategy.TableName(stmt.Table),
m.Migrator.DB.NamingStrategy.IndexName(stmt.Table, name),
),
).Row().Scan(&count)
})

Expand Down

0 comments on commit 80a6f88

Please sign in to comment.