diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e3ea1970..f94330de 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -123,7 +123,6 @@ jobs: run: GORM_ENABLE_CACHE=true GORM_DIALECT=postgres GORM_DSN="user=gorm password=gorm dbname=gorm host=localhost port=9920 sslmode=disable TimeZone=Asia/Shanghai" ./test.sh sqlserver: - needs: sqlite strategy: matrix: go: ['1.21'] diff --git a/gen.go b/gen.go deleted file mode 100644 index 3127d5d6..00000000 --- a/gen.go +++ /dev/null @@ -1,21 +0,0 @@ -package main - -import ( - "gorm.io/gen" - "gorm.io/gen/examples/dal" -) - -func generate() { - g := gen.NewGenerator(gen.Config{ - OutPath: "./dal/query", - Mode: gen.WithDefaultQuery, /*WithQueryInterface, WithoutContext*/ - - WithUnitTest: true, - }) - g.UseDB(dal.DB) - - g.ApplyBasic(Company{}, Language{}) // Associations - g.ApplyBasic(g.GenerateModel("user"), g.GenerateModelAs("account", "AccountInfo")) - - g.Execute() -} diff --git a/go.mod b/go.mod index 159394d4..8babbd53 100644 --- a/go.mod +++ b/go.mod @@ -3,33 +3,26 @@ module gorm.io/playground go 1.20 require ( - gorm.io/driver/mysql v1.5.2 - gorm.io/driver/postgres v1.5.2 - gorm.io/driver/sqlite v1.5.3 - gorm.io/driver/sqlserver v1.5.1 - gorm.io/gen v0.3.25 - gorm.io/gorm v1.25.4 + gorm.io/driver/mysql v1.5.6 + gorm.io/driver/postgres v1.5.7 + gorm.io/driver/sqlite v1.5.5 + gorm.io/driver/sqlserver v1.5.3 + gorm.io/gorm v1.25.10 ) require ( github.com/go-sql-driver/mysql v1.7.1 // indirect github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect github.com/golang-sql/sqlexp v0.1.0 // indirect + github.com/google/uuid v1.3.1 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect github.com/jackc/pgx/v5 v5.4.3 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/mattn/go-sqlite3 v1.14.17 // indirect - github.com/microsoft/go-mssqldb v1.5.0 // indirect - golang.org/x/crypto v0.14.0 // indirect - golang.org/x/mod v0.14.0 // indirect - golang.org/x/sys v0.14.0 // indirect - golang.org/x/text v0.13.0 // indirect - golang.org/x/tools v0.15.0 // indirect - gorm.io/datatypes v1.1.1-0.20230130040222-c43177d3cf8c // indirect - gorm.io/hints v1.1.0 // indirect - gorm.io/plugin/dbresolver v1.5.0 // indirect + github.com/microsoft/go-mssqldb v1.6.0 // indirect + golang.org/x/crypto v0.15.0 // indirect + golang.org/x/net v0.18.0 // indirect + golang.org/x/text v0.14.0 // indirect ) - -replace gorm.io/gorm => ./gorm diff --git a/main_test.go b/main_test.go index 60a388f7..ea4e5585 100644 --- a/main_test.go +++ b/main_test.go @@ -1,12 +1,15 @@ package main import ( + "errors" "testing" + + "gorm.io/gorm" ) // GORM_REPO: https://github.com/go-gorm/gorm.git // GORM_BRANCH: master -// TEST_DRIVERS: sqlite, mysql, postgres, sqlserver +// TEST_DRIVERS: sqlserver func TestGORM(t *testing.T) { user := User{Name: "jinzhu"} @@ -15,6 +18,21 @@ func TestGORM(t *testing.T) { var result User if err := DB.First(&result, user.ID).Error; err != nil { - t.Errorf("Failed, got error: %v", err) + if !errors.Is(err, gorm.ErrRecordNotFound) { + t.Errorf("Failed, got error: %v", err) + } + } +} + +func TestReMigrate(t *testing.T) { + // re-migrate existing table + u := &User{} + if !DB.Migrator().HasTable(u) { + if err := DB.AutoMigrate(u); err != nil { + t.Fatalf("Failed to auto migrate, but got error %v\n", err) + } + } + if err := DB.AutoMigrate(u); err != nil { + t.Fatalf("Failed to auto migrate, but got error %v\n", err) } } diff --git a/test.sh b/test.sh index 7df9088e..0d608a3f 100755 --- a/test.sh +++ b/test.sh @@ -1,6 +1,6 @@ #!/bin/bash -e -dialects=("sqlite" "mysql" "postgres" "sqlserver") +dialects=("sqlserver") if [ "$GORM_ENABLE_CACHE" = "" ] then