diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9a6f6c6..624571e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -131,17 +131,15 @@ jobs: services: mssql: - image: mcmoe/mssqldocker:latest + image: mcr.microsoft.com/mssql/server:2022-latest env: + TZ: Asia/Shanghai ACCEPT_EULA: Y - SA_PASSWORD: LoremIpsum86 - MSSQL_DB: gorm - MSSQL_USER: gorm - MSSQL_PASSWORD: LoremIpsum86 + MSSQL_SA_PASSWORD: LoremIpsum86 ports: - 9930:1433 options: >- - --health-cmd="/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P LoremIpsum86 -l 30 -Q \"SELECT 1\" || exit 1" + --health-cmd="/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P ${MSSQL_SA_PASSWORD} -N -C -l 30 -Q \"SELECT 1\" || exit 1" --health-start-period 10s --health-interval 10s --health-timeout 5s @@ -163,4 +161,4 @@ jobs: key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('tests/go.mod') }} - name: Tests - run: GORM_DIALECT=sqlserver GORM_DSN="sqlserver://gorm:LoremIpsum86@localhost:9930?database=gorm" ./test_all.sh + run: GORM_DIALECT=sqlserver GORM_DSN="sqlserver://sa:LoremIpsum86@localhost:9930?database=master" ./test_all.sh diff --git a/binuuid.go b/binuuid.go index 97503c8..349da00 100644 --- a/binuuid.go +++ b/binuuid.go @@ -25,6 +25,11 @@ func NewBinUUIDv4() BinUUID { return BinUUID(uuid.Must(uuid.NewRandom())) } +// NewNilBinUUID generates a nil uuid. +func NewNilBinUUID() BinUUID { + return BinUUID(uuid.Nil) +} + // BinUUIDFromString returns the BinUUID representation of the specified uuidStr. func BinUUIDFromString(uuidStr string) BinUUID { return BinUUID(uuid.MustParse(uuidStr)) diff --git a/binuuid_test.go b/binuuid_test.go index c1b38b5..d39804f 100644 --- a/binuuid_test.go +++ b/binuuid_test.go @@ -92,7 +92,7 @@ func TestBinUUID(t *testing.T) { AssertEqual(t, user2.UserUUID.IsNil(), false) AssertEqual(t, user2.UserUUID.IsEmpty(), false) tx = DB.Model(&user2).Updates( - map[string]interface{}{"user_uuid": nil}, + map[string]interface{}{"user_uuid": datatypes.NewNilBinUUID()}, ) AssertEqual(t, tx.Error, nil) AssertEqual(t, user2.UserUUID.IsNil(), true) @@ -171,9 +171,11 @@ func TestBinUUIDPtr(t *testing.T) { user1 := users[0] AssertEqual(t, user1.UserUUID.IsNilPtr(), false) AssertEqual(t, user1.UserUUID.IsEmptyPtr(), false) - tx := DB.Model(&user1).Updates(map[string]interface{}{"user_uuid": nil}) + tx := DB.Model(&user1).Updates(map[string]interface{}{ + "user_uuid": datatypes.NewNilBinUUID(), + }) AssertEqual(t, tx.Error, nil) - AssertEqual(t, user1.UserUUID.IsNilPtr(), true) + AssertEqual(t, user1.UserUUID.IsNil(), true) AssertEqual(t, user1.UserUUID.IsEmptyPtr(), true) } } diff --git a/test_all.sh b/test_all.sh index 4bf5a16..ad4bcc1 100755 --- a/test_all.sh +++ b/test_all.sh @@ -1,6 +1,6 @@ #!/bin/bash -e -dialects=("postgres" "postgres_simple" "mysql" "mssql" "sqlite") +dialects=("postgres" "postgres_simple" "mysql" "sqlserver" "sqlite") for dialect in "${dialects[@]}" ; do if [ "$GORM_DIALECT" = "" ] || [ "$GORM_DIALECT" = "${dialect}" ] diff --git a/url_test.go b/url_test.go index ec6402a..b7c4841 100644 --- a/url_test.go +++ b/url_test.go @@ -38,7 +38,9 @@ func TestURL(t *testing.T) { DB.Create(&f2) result := StructWithURL{} - if err := DB.First(&result, "file_name = ? AND storage = ?", "FLocal1", + if err := DB.First( + &result, "file_name = ? AND storage LIKE ?", + "FLocal1", datatypes.URL{ Scheme: "file", Path: "/tmp/f1", @@ -48,7 +50,9 @@ func TestURL(t *testing.T) { AssertEqual(t, uf1.String(), result.Storage.String()) result = StructWithURL{} - if err := DB.First(&result, "file_name = ? AND storage = ?", "FRemote2", + if err := DB.First( + &result, "file_name = ? AND storage LIKE ?", + "FRemote2", datatypes.URL{ Scheme: "sftp", User: url.UserPassword("user", "pwd"), @@ -66,7 +70,9 @@ func TestURL(t *testing.T) { AssertEqual(t, us, result.Storage.String()) result = StructWithURL{} - if err := DB.First(&result, "file_name = ? AND storage = ?", "FRemote2", + if err := DB.First( + &result, "file_name = ? AND storage LIKE ?", + "FRemote2", datatypes.URL{ Scheme: "sftp", Opaque: "//user:pwd@127.0.0.1/f2", @@ -78,7 +84,9 @@ func TestURL(t *testing.T) { AssertEqual(t, us, result.Storage.String()) result = StructWithURL{} - if err := DB.First(&result, "file_name = ? AND storage = ?", "FRemote2", + if err := DB.First( + &result, "file_name = ? AND storage LIKE ?", + "FRemote2", datatypes.URL{ Scheme: "sftp", User: url.User("user"), diff --git a/uuid.go b/uuid.go index 119efef..deafaac 100644 --- a/uuid.go +++ b/uuid.go @@ -35,7 +35,7 @@ func (UUID) GormDBDataType(db *gorm.DB, field *schema.Field) string { case "postgres": return "UUID" case "sqlserver": - return "NVARCHAR" + return "NVARCHAR(128)" case "sqlite": return "TEXT" default: