Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autoIncrementIncrement not work in postgres #756

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 18 additions & 6 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,25 @@ import (
// GORM_BRANCH: master
// TEST_DRIVERS: sqlite, mysql, postgres, sqlserver

func TestGORM(t *testing.T) {
user := User{Name: "jinzhu"}
type Book struct {
BookID int `gorm:"column:book_id;autoIncrement:true;autoIncrementIncrement:10"`
Name string `gorm:"column:name;type:varchar(255)"`
}

DB.Create(&user)
func TestGORM(t *testing.T) {
err := DB.AutoMigrate(&Book{})
if err != nil {
t.Error(err.Error())
}
var increment int
err = DB.Raw(`select increment from information_schema.sequences where sequence_name = 'books_book_id_seq'`).
Scan(&increment).Error
if err != nil {
t.Error(err.Error())
}

var result User
if err := DB.First(&result, user.ID).Error; err != nil {
t.Errorf("Failed, got error: %v", err)
// should be 10, but actually get 1
if increment != 10 {
t.Error("auto increment should be 10, but get", increment)
}
}
Loading