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

MS SQL Server support #3080

Merged
merged 14 commits into from
May 6, 2024
Merged
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ COPY go.sum .
RUN go mod download && go mod verify

COPY . .
RUN CGO_ENABLED=1 CGO_CFLAGS="-D_LARGEFILE64_SOURCE" GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags="-w -s -X 'github.com/nuts-foundation/nuts-node/core.GitCommit=${GIT_COMMIT}' -X 'github.com/nuts-foundation/nuts-node/core.GitBranch=${GIT_BRANCH}' -X 'github.com/nuts-foundation/nuts-node/core.GitVersion=${GIT_VERSION}'" -o /opt/nuts/nuts
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags="-w -s -X 'github.com/nuts-foundation/nuts-node/core.GitCommit=${GIT_COMMIT}' -X 'github.com/nuts-foundation/nuts-node/core.GitBranch=${GIT_BRANCH}' -X 'github.com/nuts-foundation/nuts-node/core.GitVersion=${GIT_VERSION}'" -o /opt/nuts/nuts

# alpine
FROM alpine:3.19.1
Expand Down
13 changes: 6 additions & 7 deletions docs/pages/deployment/storage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,20 @@ SQL database

By default, storage SQLite will be used in a file called ``sqlite.db`` in the configured data directory.
This can be overridden by configuring a connection string in ``storage.sql.connection``.
Other supported SQL databases are Postgres and MySQL.
Other supported SQL databases are Postgres, MySQL and Microsoft SQL Server.

Connection strings must be in the following format:

.. code-block:: none

protocol://username:password@host:port/database_name?options

See the `dbmate documentation <https://github.com/amacneil/dbmate?tab=readme-ov-file#connecting-to-the-database>`_ for more information.
Refer to the documentation of the driver for the database you are using for the correct connection string format:

Examples:

- Postgres: ``postgres://user:password@localhost:5432/dbname?sslmode=disable``
- MySql: ``mysql://user:password@localhost:3306/dbname?charset=utf8mb4&parseTime=True&loc=Local``
- SQLite: ``sqlite:file:/some/path/sqlite.db?_journal_mode=WAL&_foreign_keys=on``
- Postgres `github.com/jackc/pgx <https://github.com/jackc/pgx?tab=readme-ov-file#example-usage>`_ (e.g. ``postgres://user:password@localhost:5432/dbname?sslmode=disable``)
- MySql: `github.com/go-sql-driver/mysql <https://github.com/go-sql-driver/mysql?tab=readme-ov-file#dsn-data-source-name>`_ (e.g. ``mysql://user:password@localhost:3306/dbname?charset=utf8mb4&parseTime=True&loc=Local``)
- MS SQL Server: `github.com/microsoft/go-mssqldb <https://github.com/microsoft/go-mssqldb>`_
- SQLite (e.g. ``sqlite:file:/some/path/sqlite.db?_pragma=foreign_keys(1)&journal_mode(WAL)``)

Private Keys
************
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/oauth-flow/rfc021/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
This test can be executed against multiple SQL databases.
It's executed (by running `./run-test.sh`) on all supported databases (postgres, sqlite, mysql) by default.
To perform the test on a specific database, run `./do-test.sh <database>` where `<database>` is one of the supported databases (postgres, sqlite, mysql).
It's executed (by running `./run-test.sh`) on all supported databases (postgres, sqlite, mysql, sqlserver) by default.
To perform the test on a specific database, run `./do-test.sh <database>` where `<database>` is one of the supported databases (postgres, sqlite, mysql, sqlserver).
4 changes: 4 additions & 0 deletions e2e-tests/oauth-flow/rfc021/mysql.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
services:
nodeA-backend:
depends_on:
- db
environment:
NUTS_STORAGE_SQL_CONNECTION: mysql://root:root@db:3306/node_a?charset=utf8mb4&parseTime=True&loc=Local
nodeB-backend:
depends_on:
- db
environment:
NUTS_STORAGE_SQL_CONNECTION: mysql://root:root@db:3306/node_b?charset=utf8mb4&parseTime=True&loc=Local
db:
Expand Down
4 changes: 4 additions & 0 deletions e2e-tests/oauth-flow/rfc021/postgres.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
services:
nodeA-backend:
depends_on:
- db
environment:
NUTS_STORAGE_SQL_CONNECTION: postgres://postgres:postgres@db:5432/node_a?sslmode=disable
nodeB-backend:
depends_on:
- db
environment:
NUTS_STORAGE_SQL_CONNECTION: postgres://postgres:postgres@db:5432/node_b?sslmode=disable
db:
Expand Down
3 changes: 2 additions & 1 deletion e2e-tests/oauth-flow/rfc021/run-test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
./do-test.sh postgres
./do-test.sh mysql
./do-test.sh sqlite
./do-test.sh sqlite
./do-test.sh sqlserver
4 changes: 4 additions & 0 deletions e2e-tests/oauth-flow/rfc021/sqlserver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
function createDB {
$1 exec db /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'MyStrong(!)Password' -Q "CREATE DATABASE node_a; CREATE DATABASE node_b;"
}
27 changes: 27 additions & 0 deletions e2e-tests/oauth-flow/rfc021/sqlserver.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
services:
nodeA-backend:
depends_on:
- db
environment:
NUTS_STORAGE_SQL_CONNECTION: sqlserver://sa:MyStrong(!)Password@db:1433/node_a?sslmode=disable
nodeB-backend:
depends_on:
- db
environment:
NUTS_STORAGE_SQL_CONNECTION: sqlserver://sa:MyStrong(!)Password@db:1433/node_b?sslmode=disable
db:
# image: mcr.microsoft.com/azure-sql-edge:latest <-- "The sqlcmd utility is not included in the ARM64 version of the SQL Edge container" - https://github.com/microsoft/mssql-docker/issues/734
image: mcr.microsoft.com/mssql/server:2022-latest
restart: always
ports:
- "1433:1433"
environment:
MSSQL_USER: SA
MSSQL_SA_PASSWORD: MyStrong(!)Password
ACCEPT_EULA: Y
healthcheck:
test:
["CMD", "/opt/mssql-tools/bin/sqlcmd", "-U", "sa", "-P", "MyStrong(!)Password", "-Q", "SELECT 1"]
interval: 2s
timeout: 5s
retries: 10
53 changes: 29 additions & 24 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ go 1.22
require (
github.com/PaesslerAG/jsonpath v0.1.2-0.20230323094847-3484786d6f97
github.com/alicebob/miniredis/v2 v2.32.1
github.com/amacneil/dbmate/v2 v2.15.0
github.com/avast/retry-go/v4 v4.6.0
github.com/cbroglie/mustache v1.4.0
github.com/chromedp/chromedp v0.9.5
github.com/dlclark/regexp2 v1.11.0
github.com/glebarez/sqlite v1.11.0
github.com/go-redis/redismock/v9 v9.2.0
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/goodsign/monday v1.0.2
github.com/google/uuid v1.6.0
Expand All @@ -31,6 +32,7 @@ require (
// check the oapi-codegen tool version in the makefile when upgrading the runtime
github.com/oapi-codegen/runtime v1.1.1
github.com/piprate/json-gold v0.5.1-0.20230111113000-6ddbe6e6f19f
github.com/pressly/goose/v3 v3.20.0
github.com/privacybydesign/irmago v0.15.2
github.com/prometheus/client_golang v1.19.0
github.com/prometheus/client_model v0.6.1
Expand All @@ -51,10 +53,14 @@ require (
google.golang.org/protobuf v1.34.0
gopkg.in/Regis24GmbH/go-phonetics.v2 v2.0.3
gopkg.in/yaml.v3 v3.0.1
gorm.io/driver/mysql v1.5.6
gorm.io/driver/postgres v1.5.7
gorm.io/driver/sqlserver v1.5.2
schneider.vip/problem v1.9.1
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/PaesslerAG/gval v1.2.2 // indirect
github.com/alexandrevicenzi/go-sse v1.6.0 // indirect
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
Expand All @@ -79,9 +85,11 @@ require (
github.com/fatih/structs v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/fxamacker/cbor v1.5.1 // indirect
github.com/glebarez/go-sqlite v1.21.2 // indirect
github.com/go-chi/chi/v5 v5.0.10 // indirect
github.com/go-co-op/gocron v1.28.3 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-jose/go-jose/v4 v4.0.1 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/go-redsync/redsync/v4 v4.13.0 // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
Expand All @@ -91,6 +99,9 @@ require (
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/flatbuffers v24.3.25+incompatible // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
Expand All @@ -101,7 +112,12 @@ require (
github.com/hashicorp/go-sockaddr v1.0.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.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.5.5 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/labstack/gommon v0.4.2 // indirect
Expand All @@ -110,12 +126,12 @@ require (
github.com/lestrrat-go/httprc v1.0.5 // indirect
github.com/lestrrat-go/iter v1.0.2 // indirect
github.com/lestrrat-go/option v1.0.1 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-sqlite3 v1.14.22 // indirect
github.com/mfridman/interpolate v0.0.2 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/microsoft/go-mssqldb v1.7.0 // indirect
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect
github.com/minio/highwayhash v1.0.2 // indirect
github.com/minio/sha256-simd v0.1.1 // indirect
Expand All @@ -130,16 +146,19 @@ require (
github.com/nats-io/jwt/v2 v2.5.5 // indirect
github.com/nats-io/nkeys v0.4.7 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/nightlyone/lockfile v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
github.com/privacybydesign/gabi v0.0.0-20221212095008-68a086907750 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/segmentio/asm v1.2.0 // indirect
github.com/sethvargo/go-retry v0.2.4 // indirect
github.com/shengdoushi/base58 v1.0.0 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/sietseringers/go-sse v0.0.0-20200801161811-e2cf2c63ca50 // indirect
Expand All @@ -155,33 +174,19 @@ require (
github.com/x-cray/logrus-prefixed-formatter v0.5.2 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/yuin/gopher-lua v1.1.1 // indirect
go.opencensus.io v0.24.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be // indirect
gopkg.in/Regis24GmbH/go-diacritics.v2 v2.0.3 // indirect
gorm.io/driver/sqlite v1.5.5
gorm.io/gorm v1.25.10
modernc.org/libc v1.49.3 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.8.0 // indirect
modernc.org/sqlite v1.29.8 // indirect
rsc.io/qr v0.2.0 // indirect
)

require (
github.com/go-redis/redismock/v9 v9.2.0
gorm.io/driver/mysql v1.5.6
gorm.io/driver/postgres v1.5.7
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/go-jose/go-jose/v4 v4.0.1 // 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.5.4 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/microsoft/go-mssqldb v1.6.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/sync v0.7.0 // indirect
gorm.io/driver/sqlserver v1.5.2 // indirect
)
Loading
Loading