Skip to content

Commit eac2853

Browse files
authored
feat: add-mssql-support (#56)
* fix: tests and refactoring, add justfile instead of makefile * chore: add tiberius dependency for MSSQL support * feat: add Mssql variant to DbType enum and config validation * feat: add MSSQL domain adapter with tiberius ping and sqlpackage backup/restore * feat: install sqlpackage in Docker base and prod stages * feat: add MSSQL service to docker-compose and config examples * fix: log backup errors instead of silently discarding them * fix: use dotnet-install.sh instead of Microsoft apt feed (SHA1 key rejected by Debian Trixie) * fix: add /TrustServerCertificate:true to sqlpackage commands for self-signed certs * fix: use connection string with TrustServerCertificate for sqlpackage * fix: use user database in MSSQL config example (system databases cannot be exported) * feat: add seed-mssql task and seed script * fix: docker-compose.yml
1 parent a4bbb37 commit eac2853

21 files changed

Lines changed: 577 additions & 23 deletions

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33
/src/data/
44

55
.DS_Store
6-
.env
6+
.env
7+
8+
.claude
9+
/docs

Cargo.lock

Lines changed: 122 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ rand = "0.9.2"
3535
bytes = "1.11.0"
3636
async-stream = "0.3.6"
3737
uuid = { version = "1.20.0", features = ["v4"] }
38-
tokio-util = "0.7.18"
38+
tokio-util = { version = "0.7.18", features = ["compat"] }
39+
tiberius = { version = "0.12", default-features = false, features = ["rustls", "chrono"] }
3940
aws-config = "1.8.13"
4041
aws-sdk-s3 = { version = "1.122.0", features = ["behavior-version-latest"] }
4142
async-compression = { version = "0.4.37", features = ["tokio", "gzip"] }

databases.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@
101101
"port": 3050,
102102
"host": "db-firebird",
103103
"generated_id": "16706124-ff7e-4c97-8c83-0adeff214681"
104+
},
105+
{
106+
"name": "Test database 13 - MysSQL",
107+
"database": "myappdb",
108+
"type": "mssql",
109+
"username": "sa",
110+
"password": "Portabase!Strong1",
111+
"port": 1433,
112+
"host": "db-mssql",
113+
"generated_id": "16706125-ff7e-4c97-8c83-0adeff214682"
104114
}
105115
]
106116
}

databases.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,14 @@ port = 3050
100100
host = "db-firebird"
101101
generated_id = "16706124-ff7e-4c97-8c83-0adeff214681"
102102

103+
[[databases]]
104+
name = "Test database 13 - MSSQL"
105+
database = "myappdb"
106+
type = "mssql"
107+
username = "sa"
108+
password = "Portabase!Strong1"
109+
port = 1433
110+
host = "db-mssql"
111+
generated_id = "16706125-ff7e-4c97-8c83-0adeff214682"
112+
103113

docker-compose.databases.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,24 @@ services:
159159
networks:
160160
- portabase
161161

162+
db-mssql:
163+
container_name: db-mssql
164+
image: mcr.microsoft.com/azure-sql-edge:latest
165+
ports:
166+
- "1433:1433"
167+
environment:
168+
ACCEPT_EULA: "Y"
169+
MSSQL_SA_PASSWORD: "Portabase!Strong1"
170+
volumes:
171+
- mssql-data:/var/opt/mssql
172+
networks:
173+
- portabase
174+
healthcheck:
175+
test: ["CMD-SHELL", "cat /proc/net/tcp6 | grep -q '059901' || exit 1"]
176+
interval: 10s
177+
timeout: 5s
178+
retries: 20
179+
162180
volumes:
163181
postgres-data:
164182
mariadb-data:
@@ -171,6 +189,7 @@ volumes:
171189
valkey-data:
172190
valkey-data-auth:
173191
firebird-data:
192+
mssql-data:
174193

175194
networks:
176195
portabase:

docker/Dockerfile

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
2222
&& apt-get clean \
2323
&& rm -rf /var/lib/apt/lists/*
2424

25+
ENV DOTNET_ROOT=/usr/local/dotnet
26+
RUN curl -sSL https://dot.net/v1/dotnet-install.sh -o /tmp/dotnet-install.sh \
27+
&& chmod +x /tmp/dotnet-install.sh \
28+
&& /tmp/dotnet-install.sh --channel 8.0 --install-dir /usr/local/dotnet \
29+
&& rm /tmp/dotnet-install.sh \
30+
&& /usr/local/dotnet/dotnet tool install --global microsoft.sqlpackage
31+
32+
ENV PATH="$PATH:/usr/local/dotnet:/root/.dotnet/tools"
33+
34+
RUN ARCH=$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/') \
35+
&& curl -sSL "https://github.com/microsoft/go-sqlcmd/releases/latest/download/sqlcmd-linux-${ARCH}.tar.bz2" \
36+
| tar -xjf - -C /usr/local/bin sqlcmd \
37+
&& chmod +x /usr/local/bin/sqlcmd
38+
2539
ARG TARGETARCH
2640

2741
# =========================
@@ -97,12 +111,18 @@ RUN apt-get update && apt-get install -y \
97111
libreadline8 \
98112
libncurses6 \
99113
zlib1g \
114+
curl \
100115
mariadb-client \
101116
sqlite3 \
102117
redis-tools \
103118
valkey \
104119
&& rm -rf /var/lib/apt/lists/*
105120

121+
ENV DOTNET_ROOT=/usr/local/dotnet
122+
RUN curl -sSL https://dot.net/v1/dotnet-install.sh -o /tmp/dotnet-install.sh \
123+
&& chmod +x /tmp/dotnet-install.sh \
124+
&& /tmp/dotnet-install.sh --channel 8.0 --runtime dotnet --install-dir /usr/local/dotnet \
125+
&& rm /tmp/dotnet-install.sh
106126

107127
WORKDIR /app
108128

@@ -113,8 +133,9 @@ RUN chmod +x /entrypoint.sh
113133

114134
COPY --from=base /usr/lib/postgresql/ /usr/lib/postgresql/
115135
COPY --from=base /usr/local/mongodb/bin/ /usr/local/mongodb/bin/
136+
COPY --from=base /root/.dotnet/tools/ /root/.dotnet/tools/
116137

117-
138+
ENV PATH="$PATH:/usr/local/dotnet:/root/.dotnet/tools"
118139
ENV APP_ENV=production
119140

120141
CMD ["/entrypoint.sh"]

justfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,17 @@ seed-firebird:
4545
echo "SELECT RDB\$RELATION_NAME FROM RDB\$RELATIONS WHERE RDB\$SYSTEM_FLAG = 0 AND RDB\$VIEW_BLR IS NULL;" \
4646
| docker exec -i db-firebird isql -user alice -password fake_password /var/lib/firebird/data/mirror.fdb
4747

48+
seed-mssql:
49+
echo "Seeding MSSQL..."
50+
docker exec -i rust-dev sqlcmd -S "db-mssql,1433" -U sa -P "$MSSQL_SA_PASSWORD" -N disable -i /app/scripts/mssql/seed.sql
51+
echo "Done"
52+
4853
seed-all:
4954
just seed-mongo
5055
just seed-mysql
5156
just seed-postgres
5257
just seed-postgres-1gb
5358
just seed-sqlite
5459
just seed-mongo
55-
just seed-firebird
60+
just seed-firebird
61+
just seed-mssql

0 commit comments

Comments
 (0)