forked from go-gorm/gorm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix remove index for sqlite and postgres
- Loading branch information
Showing
8 changed files
with
29 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,7 @@ func TestIndexes(t *testing.T) { | |
if err := db.Model(&Email{}).AddIndex("idx_email_email_and_user_id", "user_id", "email").Error; err != nil { | ||
t.Errorf("Got error when tried to create index: %+v", err) | ||
} | ||
|
||
if err := db.Model(&Email{}).RemoveIndex("idx_email_email_and_user_id").Error; err != nil { | ||
t.Errorf("Got error when tried to remove index: %+v", err) | ||
} | ||
|
@@ -76,8 +77,15 @@ func TestIndexes(t *testing.T) { | |
t.Errorf("Got error when tried to create index: %+v", err) | ||
} | ||
|
||
fmt.Println(db.Save(&User{Name: "unique_indexes", Emails: []Email{{Email: "[email protected]"}, {Email: "[email protected]"}, {Email: "[email protected]"}}}).Error) | ||
if db.Debug().Save(&User{Name: "unique_indexes", Emails: []Email{{Email: "[email protected]"}, {Email: "[email protected]"}, {Email: "[email protected]"}}}).Error == nil { | ||
if db.Save(&User{Name: "unique_indexes", Emails: []Email{{Email: "[email protected]"}, {Email: "[email protected]"}, {Email: "[email protected]"}}}).Error == nil { | ||
t.Errorf("Should get to create duplicate record when having unique index") | ||
} | ||
|
||
if err := db.Model(&Email{}).RemoveIndex("idx_email_email_and_user_id").Error; err != nil { | ||
t.Errorf("Got error when tried to remove index: %+v", err) | ||
} | ||
|
||
if db.Save(&User{Name: "unique_indexes", Emails: []Email{{Email: "[email protected]"}, {Email: "[email protected]"}}}).Error != nil { | ||
t.Errorf("Should be able to create duplicated emails after remove unique index") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters