From acc527471502c81ccb42fe1ccd1946b71dad41c4 Mon Sep 17 00:00:00 2001 From: "Giau. Tran Minh" <12751435+giautm@users.noreply.github.com> Date: Thu, 25 Jan 2024 07:50:30 +0700 Subject: [PATCH] feat: support sqlserver (#29) --- .github/workflows/ci.yaml | 10 +- README.md | 3 +- go.mod | 10 +- go.sum | 109 ++++++++++++++++++ gormschema/gorm.go | 6 + gormschema/gorm_test.go | 16 +++ gormschema/testdata/postgresql_default | 4 +- gormschema/testdata/postgresql_no_fk | 4 +- gormschema/testdata/sqlserver_default | 11 ++ gormschema/testdata/sqlserver_no_fk | 4 + internal/testdata/atlas.hcl | 1 + internal/testdata/circularfks/atlas.hcl | 1 + ...{20231217181014.sql => 20240124161610.sql} | 4 +- .../circularfks/migrations/postgres/atlas.sum | 4 +- .../migrations/sqlserver/20240124160859.sql | 22 ++++ .../migrations/sqlserver/atlas.sum | 2 + internal/testdata/circularfks/models.go | 4 +- .../migrations/sqlserver/20240124151658.sql | 25 ++++ .../testdata/migrations/sqlserver/atlas.sum | 2 + main.go | 2 +- 20 files changed, 227 insertions(+), 17 deletions(-) create mode 100644 gormschema/testdata/sqlserver_default create mode 100644 gormschema/testdata/sqlserver_no_fk rename internal/testdata/circularfks/migrations/postgres/{20231217181014.sql => 20240124161610.sql} (91%) create mode 100644 internal/testdata/circularfks/migrations/sqlserver/20240124160859.sql create mode 100644 internal/testdata/circularfks/migrations/sqlserver/atlas.sum create mode 100644 internal/testdata/migrations/sqlserver/20240124151658.sql create mode 100644 internal/testdata/migrations/sqlserver/atlas.sum diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9e756ae..aad6033 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -29,7 +29,7 @@ jobs: integration-test: strategy: matrix: - dialect: [mysql, postgres, sqlite] + dialect: [mysql, postgres, sqlite, sqlserver] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -37,13 +37,19 @@ jobs: with: go-version-file: 'go.mod' - run: | - curl -sSf 'https://atlasgo.sh?test=1' | env ATLAS_DEBUG=true sh + curl -sSf 'https://atlasgo.sh?test=1' | sh + env: + ATLAS_DEBUG: true - working-directory: internal/testdata run: | atlas migrate diff --env gorm --var dialect=${{ matrix.dialect }} + env: + ATLAS_TOKEN: ${{ secrets.ATLAS_TOKEN }} - working-directory: internal/testdata/circularfks run: | atlas migrate diff --env gorm --var dialect=${{ matrix.dialect }} + env: + ATLAS_TOKEN: ${{ secrets.ATLAS_TOKEN }} - name: Verify migrations generated run: | status=$(git status --porcelain) diff --git a/README.md b/README.md index 9aa42ef..75983d1 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ data "external_schema" "gorm" { "ariga.io/atlas-provider-gorm", "load", "--path", "./path/to/models", - "--dialect", "mysql", // | postgres | sqlite + "--dialect", "mysql", // | postgres | sqlite | sqlserver ] } @@ -178,6 +178,7 @@ The provider supports the following databases: * MySQL * PostgreSQL * SQLite +* SQL Server ### License diff --git a/go.mod b/go.mod index 7e2f8b9..3e615cd 100644 --- a/go.mod +++ b/go.mod @@ -12,12 +12,14 @@ require ( gorm.io/driver/mysql v1.5.1 gorm.io/driver/postgres v1.5.2 gorm.io/driver/sqlite v1.5.2 - gorm.io/gorm v1.25.2-0.20230530020048-26663ab9bf55 + gorm.io/gorm v1.25.2-0.20230610234218-206613868439 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-sql-driver/mysql v1.7.0 // indirect + github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect + github.com/golang-sql/sqlexp v0.1.0 // 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.3.1 // indirect @@ -25,11 +27,13 @@ require ( github.com/jinzhu/now v1.1.5 // indirect github.com/kr/text v0.2.0 // indirect github.com/mattn/go-sqlite3 v1.14.17 // indirect + github.com/microsoft/go-mssqldb v1.6.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rogpeppe/go-internal v1.10.0 // indirect - golang.org/x/crypto v0.8.0 // indirect + golang.org/x/crypto v0.12.0 // indirect golang.org/x/mod v0.11.0 // indirect - golang.org/x/sys v0.9.0 // indirect + golang.org/x/sys v0.11.0 // indirect golang.org/x/text v0.13.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect + gorm.io/driver/sqlserver v1.5.2 // indirect ) diff --git a/go.sum b/go.sum index b36bfbd..cac1754 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,17 @@ ariga.io/atlas-go-sdk v0.2.3 h1:DpKruiJ9ElJcNhYxnQM9ddzupHXEYFH0Jx6ZcZ7lKYQ= ariga.io/atlas-go-sdk v0.2.3/go.mod h1:owkEEXw6jqne5KPVDfKsYB7cwMiMk3jtOiAAeKxS/yU= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0/go.mod h1:ON4tFdPTwRcgWEaVDrN3584Ef+b7GgSJaXxe5fW9t4M= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.1/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.1/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0/go.mod h1:OQeznEEkTZ9OrhHJoDD8ZDq51FHgXjqtP9z6bEwBq9U= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.1.2/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0/go.mod h1:okt5dMMTOFjX/aovMlrjvvXoPMBVSPzk9185BT0+eZM= +github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.0.0/go.mod h1:Q28U+75mpCaSCDowNEmhIo/rmgdkqmkmzI7N6TGR4UY= +github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v0.8.0/go.mod h1:cw4zVQgBby0Z5f2v0itn6se2dDP17nTjbZFXW5uPyHA= +github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0/go.mod h1:kgDmCTgBzIEPFElEF+FK0SdjAor06dRq2Go927dnQ6o= +github.com/AzureAD/microsoft-authentication-library-for-go v1.1.0/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= github.com/alecthomas/assert/v2 v2.1.0 h1:tbredtNcQnoSd3QBhQWI7QZ3XHOVkw1Moklp2ojoH/0= github.com/alecthomas/assert/v2 v2.1.0/go.mod h1:b/+1DI2Q6NckYi+3mXyH3wFb8qG37K/DuK80n7WefXA= github.com/alecthomas/kong v0.7.1 h1:azoTh0IOfwlAX3qN9sHWTxACE2oV8Bg2gAwBsMwDQY4= @@ -10,8 +22,22 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko= +github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= +github.com/golang-jwt/jwt/v4 v4.4.3/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA= +github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= +github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A= +github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= +github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= +github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= @@ -20,6 +46,12 @@ github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/ github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= github.com/jackc/pgx/v5 v5.3.1 h1:Fcr8QJ1ZeLi5zsPZqQeUZhNhxfkkKBOgJuYkJHoBOtU= github.com/jackc/pgx/v5 v5.3.1/go.mod h1:t3JDKnCBlYIc0ewLF0Q7B8MXmoIaBOZj/ic7iHozM/8= +github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs= +github.com/jcmturner/dnsutils/v2 v2.0.0/go.mod h1:b0TnjGOvI/n42bZa+hmXL+kFJZsFT7G4t3HTlQ184QM= +github.com/jcmturner/gofork v1.7.6/go.mod h1:1622LH6i/EZqLloHfE7IeZ0uEJwMSUyQ/nDd82IeqRo= +github.com/jcmturner/goidentity/v6 v6.0.1/go.mod h1:X1YW3bgtvwAXju7V3LCIMpY0Gbxyjn/mY9zx4tFonSg= +github.com/jcmturner/gokrb5/v8 v8.4.4/go.mod h1:1btQEpgT6k+unzCwX1KdWMEwPPkkgBtP+F6aCACiMrs= +github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= @@ -28,32 +60,105 @@ github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM= github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= +github.com/microsoft/go-mssqldb v1.6.0 h1:mM3gYdVwEPFrlg/Dvr2DNVEgYFG7L42l+dGc67NNNpc= +github.com/microsoft/go-mssqldb v1.6.0/go.mod h1:00mDtPbeQCRGC1HwOOR5K/gr30P1NcEG0vx6Kbv2aJU= +github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= +github.com/montanaflynn/stats v0.7.0/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= +github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= +golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ= golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE= +golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= +golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk= +golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s= golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.10.0 h1:tvDr/iQoUqNdohiYm0LmmKcBk+q86lb9EprIUFhHHGg= golang.org/x/tools v0.10.0/go.mod h1:UJwyiVBsOA2uwvK/e5OY3GTpDUJriEd+/YlqAwLPmyM= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= @@ -63,6 +168,10 @@ gorm.io/driver/postgres v1.5.2 h1:ytTDxxEv+MplXOfFe3Lzm7SjG09fcdb3Z/c056DTBx0= gorm.io/driver/postgres v1.5.2/go.mod h1:fmpX0m2I1PKuR7mKZiEluwrP3hbs+ps7JIGMUBpCgl8= gorm.io/driver/sqlite v1.5.2 h1:TpQ+/dqCY4uCigCFyrfnrJnrW9zjpelWVoEVNy5qJkc= gorm.io/driver/sqlite v1.5.2/go.mod h1:qxAuCol+2r6PannQDpOP1FP6ag3mKi4esLnB/jHed+4= +gorm.io/driver/sqlserver v1.5.2 h1:+o4RQ8w1ohPbADhFqDxeeZnSWjwOcBnxBckjTbcP4wk= +gorm.io/driver/sqlserver v1.5.2/go.mod h1:gaKF0MO0cfTq9Q3/XhkowSw4g6nIwHPGAs4hzKCmvBo= gorm.io/gorm v1.25.1/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= gorm.io/gorm v1.25.2-0.20230530020048-26663ab9bf55 h1:sC1Xj4TYrLqg1n3AN10w871An7wJM0gzgcm8jkIkECQ= gorm.io/gorm v1.25.2-0.20230530020048-26663ab9bf55/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= +gorm.io/gorm v1.25.2-0.20230610234218-206613868439 h1:LerZWOlV0e/6u9dEoVhe7Ehg+o7QvQKIxrI4Ccb2aV8= +gorm.io/gorm v1.25.2-0.20230610234218-206613868439/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= diff --git a/gormschema/gorm.go b/gormschema/gorm.go index 051100e..938ba14 100644 --- a/gormschema/gorm.go +++ b/gormschema/gorm.go @@ -10,6 +10,7 @@ import ( "gorm.io/driver/mysql" "gorm.io/driver/postgres" "gorm.io/driver/sqlite" + "gorm.io/driver/sqlserver" "gorm.io/gorm" gormig "gorm.io/gorm/migrator" ) @@ -68,6 +69,11 @@ func (l *Loader) Load(models ...any) (string, error) { DriverName: "recordriver", DSN: "gorm", }) + case "sqlserver": + di = sqlserver.New(sqlserver.Config{ + DriverName: "recordriver", + DSN: "gorm", + }) default: return "", fmt.Errorf("unsupported engine: %s", l.dialect) } diff --git a/gormschema/gorm_test.go b/gormschema/gorm_test.go index af209d2..bc92ee5 100644 --- a/gormschema/gorm_test.go +++ b/gormschema/gorm_test.go @@ -60,6 +60,22 @@ func TestMySQLConfig(t *testing.T) { requireEqualContent(t, sql, "testdata/mysql_no_fk") } +func TestSQLServerConfig(t *testing.T) { + resetSession() + l := New("sqlserver") + sql, err := l.Load(ckmodels.Location{}, ckmodels.Event{}, models.User{}, models.Pet{}) + require.NoError(t, err) + requireEqualContent(t, sql, "testdata/sqlserver_default") + resetSession() + l = New("sqlserver", WithConfig( + &gorm.Config{ + DisableForeignKeyConstraintWhenMigrating: true, + })) + sql, err = l.Load(ckmodels.Location{}, ckmodels.Event{}) + require.NoError(t, err) + requireEqualContent(t, sql, "testdata/sqlserver_no_fk") +} + func resetSession() { sess, ok := recordriver.Session("gorm") if ok { diff --git a/gormschema/testdata/postgresql_default b/gormschema/testdata/postgresql_default index 634ef99..7f30ad5 100644 --- a/gormschema/testdata/postgresql_default +++ b/gormschema/testdata/postgresql_default @@ -1,6 +1,6 @@ -CREATE TABLE "events" ("eventId" text,"locationId" varchar(191),PRIMARY KEY ("eventId")); +CREATE TABLE "events" ("eventId" varchar(191),"locationId" varchar(191),PRIMARY KEY ("eventId")); CREATE UNIQUE INDEX IF NOT EXISTS "idx_events_location_id" ON "events" ("locationId"); -CREATE TABLE "locations" ("locationId" text,"eventId" varchar(191),PRIMARY KEY ("locationId")); +CREATE TABLE "locations" ("locationId" varchar(191),"eventId" varchar(191),PRIMARY KEY ("locationId")); CREATE UNIQUE INDEX IF NOT EXISTS "idx_locations_event_id" ON "locations" ("eventId"); CREATE TABLE "users" ("id" bigserial,"created_at" timestamptz,"updated_at" timestamptz,"deleted_at" timestamptz,"name" text,PRIMARY KEY ("id")); CREATE INDEX IF NOT EXISTS "idx_users_deleted_at" ON "users" ("deleted_at"); diff --git a/gormschema/testdata/postgresql_no_fk b/gormschema/testdata/postgresql_no_fk index ebd90e8..61b2b73 100644 --- a/gormschema/testdata/postgresql_no_fk +++ b/gormschema/testdata/postgresql_no_fk @@ -1,4 +1,4 @@ -CREATE TABLE "events" ("eventId" text,"locationId" varchar(191),PRIMARY KEY ("eventId")); +CREATE TABLE "events" ("eventId" varchar(191),"locationId" varchar(191),PRIMARY KEY ("eventId")); CREATE UNIQUE INDEX IF NOT EXISTS "idx_events_location_id" ON "events" ("locationId"); -CREATE TABLE "locations" ("locationId" text,"eventId" varchar(191),PRIMARY KEY ("locationId")); +CREATE TABLE "locations" ("locationId" varchar(191),"eventId" varchar(191),PRIMARY KEY ("locationId")); CREATE UNIQUE INDEX IF NOT EXISTS "idx_locations_event_id" ON "locations" ("eventId"); diff --git a/gormschema/testdata/sqlserver_default b/gormschema/testdata/sqlserver_default new file mode 100644 index 0000000..2811bf2 --- /dev/null +++ b/gormschema/testdata/sqlserver_default @@ -0,0 +1,11 @@ +CREATE TABLE "events" ("eventId" nvarchar(191),"locationId" nvarchar(191),PRIMARY KEY ("eventId")); +CREATE UNIQUE INDEX "idx_events_location_id" ON "events"("locationId"); +CREATE TABLE "locations" ("locationId" nvarchar(191),"eventId" nvarchar(191),PRIMARY KEY ("locationId")); +CREATE UNIQUE INDEX "idx_locations_event_id" ON "locations"("eventId"); +CREATE TABLE "users" ("id" bigint IDENTITY(1,1),"created_at" datetimeoffset,"updated_at" datetimeoffset,"deleted_at" datetimeoffset,"name" nvarchar(MAX),PRIMARY KEY ("id")); +CREATE INDEX "idx_users_deleted_at" ON "users"("deleted_at"); +CREATE TABLE "pets" ("id" bigint IDENTITY(1,1),"created_at" datetimeoffset,"updated_at" datetimeoffset,"deleted_at" datetimeoffset,"name" nvarchar(MAX),"user_id" bigint,PRIMARY KEY ("id")); +CREATE INDEX "idx_pets_deleted_at" ON "pets"("deleted_at"); +ALTER TABLE "events" ADD CONSTRAINT "fk_locations_event" FOREIGN KEY ("locationId") REFERENCES "locations"("locationId"); +ALTER TABLE "locations" ADD CONSTRAINT "fk_events_location" FOREIGN KEY ("eventId") REFERENCES "events"("eventId"); +ALTER TABLE "pets" ADD CONSTRAINT "fk_users_pets" FOREIGN KEY ("user_id") REFERENCES "users"("id"); diff --git a/gormschema/testdata/sqlserver_no_fk b/gormschema/testdata/sqlserver_no_fk new file mode 100644 index 0000000..e5c04b4 --- /dev/null +++ b/gormschema/testdata/sqlserver_no_fk @@ -0,0 +1,4 @@ +CREATE TABLE "events" ("eventId" nvarchar(191),"locationId" nvarchar(191),PRIMARY KEY ("eventId")); +CREATE UNIQUE INDEX "idx_events_location_id" ON "events"("locationId"); +CREATE TABLE "locations" ("locationId" nvarchar(191),"eventId" nvarchar(191),PRIMARY KEY ("locationId")); +CREATE UNIQUE INDEX "idx_locations_event_id" ON "locations"("eventId"); diff --git a/internal/testdata/atlas.hcl b/internal/testdata/atlas.hcl index a9bd906..8b41291 100644 --- a/internal/testdata/atlas.hcl +++ b/internal/testdata/atlas.hcl @@ -6,6 +6,7 @@ locals { dev_url = { mysql = "docker://mysql/8/dev" postgres = "docker://postgres/15" + sqlserver = "docker://sqlserver/2022-latest" sqlite = "sqlite://file::memory:?cache=shared" }[var.dialect] } diff --git a/internal/testdata/circularfks/atlas.hcl b/internal/testdata/circularfks/atlas.hcl index ecebac0..8ea79c2 100644 --- a/internal/testdata/circularfks/atlas.hcl +++ b/internal/testdata/circularfks/atlas.hcl @@ -6,6 +6,7 @@ locals { dev_url = { mysql = "docker://mysql/8/dev" postgres = "docker://postgres/15" + sqlserver = "docker://sqlserver/2022-latest" sqlite = "sqlite://file::memory:?cache=shared" }[var.dialect] } diff --git a/internal/testdata/circularfks/migrations/postgres/20231217181014.sql b/internal/testdata/circularfks/migrations/postgres/20240124161610.sql similarity index 91% rename from internal/testdata/circularfks/migrations/postgres/20231217181014.sql rename to internal/testdata/circularfks/migrations/postgres/20240124161610.sql index c296cf1..8839e9f 100644 --- a/internal/testdata/circularfks/migrations/postgres/20231217181014.sql +++ b/internal/testdata/circularfks/migrations/postgres/20240124161610.sql @@ -1,6 +1,6 @@ -- Create "events" table CREATE TABLE "public"."events" ( - "eventId" text NOT NULL, + "eventId" character varying(191) NOT NULL, "locationId" character varying(191) NULL, PRIMARY KEY ("eventId") ); @@ -8,7 +8,7 @@ CREATE TABLE "public"."events" ( CREATE UNIQUE INDEX "idx_events_location_id" ON "public"."events" ("locationId"); -- Create "locations" table CREATE TABLE "public"."locations" ( - "locationId" text NOT NULL, + "locationId" character varying(191) NOT NULL, "eventId" character varying(191) NULL, PRIMARY KEY ("locationId") ); diff --git a/internal/testdata/circularfks/migrations/postgres/atlas.sum b/internal/testdata/circularfks/migrations/postgres/atlas.sum index 667ffb8..9343970 100644 --- a/internal/testdata/circularfks/migrations/postgres/atlas.sum +++ b/internal/testdata/circularfks/migrations/postgres/atlas.sum @@ -1,2 +1,2 @@ -h1:3XDCo8bjuE6yz76MYjtZ8OW7DuQ78ew5LcpegpW1dyg= -20231217181014.sql h1:jtRpW/I2EajKDjApxymFfSj8IPAsSYP6XS0AnyQjoCo= +h1:PnE3wSRiwknZRxInHsmdH7cC9eSfFiIqEApAn50VSyk= +20240124161610.sql h1:RRuQ49UyR6aH5yhk3dPz8Mfs0Xg49YLMfzRSCPUTjYs= diff --git a/internal/testdata/circularfks/migrations/sqlserver/20240124160859.sql b/internal/testdata/circularfks/migrations/sqlserver/20240124160859.sql new file mode 100644 index 0000000..661a979 --- /dev/null +++ b/internal/testdata/circularfks/migrations/sqlserver/20240124160859.sql @@ -0,0 +1,22 @@ +-- Create "events" table +CREATE TABLE [events] ( + [eventId] nvarchar(191) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [locationId] nvarchar(191) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + CONSTRAINT [PK_events] PRIMARY KEY CLUSTERED ([eventId] ASC) +); +-- Create index "idx_events_location_id" to table: "events" +CREATE UNIQUE NONCLUSTERED INDEX [idx_events_location_id] ON [events] ([locationId] ASC); +-- Create "locations" table +CREATE TABLE [locations] ( + [locationId] nvarchar(191) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [eventId] nvarchar(191) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + CONSTRAINT [PK_locations] PRIMARY KEY CLUSTERED ([locationId] ASC) +); +-- Create index "idx_locations_event_id" to table: "locations" +CREATE UNIQUE NONCLUSTERED INDEX [idx_locations_event_id] ON [locations] ([eventId] ASC); +-- Modify "events" table +ALTER TABLE [events] ADD + CONSTRAINT [fk_locations_event] FOREIGN KEY ([locationId]) REFERENCES [locations] ([locationId]) ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "locations" table +ALTER TABLE [locations] ADD + CONSTRAINT [fk_events_location] FOREIGN KEY ([eventId]) REFERENCES [events] ([eventId]) ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/internal/testdata/circularfks/migrations/sqlserver/atlas.sum b/internal/testdata/circularfks/migrations/sqlserver/atlas.sum new file mode 100644 index 0000000..3cc9059 --- /dev/null +++ b/internal/testdata/circularfks/migrations/sqlserver/atlas.sum @@ -0,0 +1,2 @@ +h1:OIdvgjiF5bL+tDJhx+SKoP8xJ4iiTIeq92iGkjWDhZo= +20240124160859.sql h1:DvrzggJ017G3x+M73mGBK/UyjhBBAje6bB34g5goNxI= diff --git a/internal/testdata/circularfks/models.go b/internal/testdata/circularfks/models.go index 60b7b29..526e0fc 100644 --- a/internal/testdata/circularfks/models.go +++ b/internal/testdata/circularfks/models.go @@ -1,13 +1,13 @@ package circularfks type Location struct { - LocationID string `gorm:"primaryKey;column:locationId;"` + LocationID string `gorm:"primaryKey;column:locationId;size:191"` EventID string `gorm:"uniqueIndex;column:eventId;size:191"` Event *Event `gorm:"foreignKey:locationId;references:locationId;OnUpdate:CASCADE,OnDelete:CASCADE"` } type Event struct { - EventID string `gorm:"primaryKey;column:eventId;"` + EventID string `gorm:"primaryKey;column:eventId;size:191"` LocationID string `gorm:"uniqueIndex;column:locationId;size:191"` Location *Location `gorm:"foreignKey:eventId;references:eventId;OnUpdate:CASCADE,OnDelete:CASCADE"` } diff --git a/internal/testdata/migrations/sqlserver/20240124151658.sql b/internal/testdata/migrations/sqlserver/20240124151658.sql new file mode 100644 index 0000000..f65153e --- /dev/null +++ b/internal/testdata/migrations/sqlserver/20240124151658.sql @@ -0,0 +1,25 @@ +-- Create "users" table +CREATE TABLE [users] ( + [id] bigint IDENTITY (1, 1) NOT NULL, + [created_at] datetimeoffset(7) NULL, + [updated_at] datetimeoffset(7) NULL, + [deleted_at] datetimeoffset(7) NULL, + [name] nvarchar(MAX) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + CONSTRAINT [PK_users] PRIMARY KEY CLUSTERED ([id] ASC) +); +-- Create index "idx_users_deleted_at" to table: "users" +CREATE NONCLUSTERED INDEX [idx_users_deleted_at] ON [users] ([deleted_at] ASC); +-- Create "pets" table +CREATE TABLE [pets] ( + [id] bigint IDENTITY (1, 1) NOT NULL, + [created_at] datetimeoffset(7) NULL, + [updated_at] datetimeoffset(7) NULL, + [deleted_at] datetimeoffset(7) NULL, + [name] nvarchar(MAX) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + [user_id] bigint NULL, + CONSTRAINT [PK_pets] PRIMARY KEY CLUSTERED ([id] ASC), + + CONSTRAINT [fk_users_pets] FOREIGN KEY ([user_id]) REFERENCES [users] ([id]) ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create index "idx_pets_deleted_at" to table: "pets" +CREATE NONCLUSTERED INDEX [idx_pets_deleted_at] ON [pets] ([deleted_at] ASC); diff --git a/internal/testdata/migrations/sqlserver/atlas.sum b/internal/testdata/migrations/sqlserver/atlas.sum new file mode 100644 index 0000000..3c8ecc8 --- /dev/null +++ b/internal/testdata/migrations/sqlserver/atlas.sum @@ -0,0 +1,2 @@ +h1:D/qN76qAIyjiECQhcjgiXOINHaEKedGPZKcjb+DTBc0= +20240124151658.sql h1:KaWALlql7BBV3oPVRT4rn+dvZaolhDmgbTgUPxIhauU= diff --git a/main.go b/main.go index 48ad468..5df0264 100644 --- a/main.go +++ b/main.go @@ -41,7 +41,7 @@ func main() { type LoadCmd struct { Path string `help:"path to schema package" required:""` Models []string `help:"Models to load"` - Dialect string `help:"dialect to use" enum:"mysql,sqlite,postgres" required:""` + Dialect string `help:"dialect to use" enum:"mysql,sqlite,postgres,sqlserver" required:""` out io.Writer }