You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(sqlserver): add optional mssql-python connection backend and docs (#681)
Add support for selecting either the existing pyodbc backend or the new
mssql-python backend for SQL Server connections.
Keep pyodbc as the default backend for backward compatibility, while allowing
users to opt into mssql-python through the new backend configuration and
optional dependency extra.
Changes include:
- Add backend selection using a SQL Server backend enum
- Add lazy imports for optional backend dependencies
- Keep pyodbc as the default backend
- Add optional mssql-python dependency support
- Update pyodbc validation for missing, empty, and whitespace-only driver values
- Add authentication normalization and validation for SQL Server profile fields
- Add mssql-python connection-string handling for MSI and integrated authentication
- Add support for Active Directory access-token authentication
- Improve connection-string sanitization for logging
- Validate connection requirements and query timeout settings
- Expand unit tests for backend selection, authentication handling, and connection behavior
- Refactor integration tests to cover both pyodbc and mssql-python backends
- Add a dedicated mssql CI image and backend requirements table
- Update README and contributing docs for backend installation and development setup
- Add workflow_dispatch support for CI/CD Docker publishing
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+39Lines changed: 39 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,15 +32,52 @@ The functional tests require a running SQL Server instance. You can easily spin
32
32
make server
33
33
```
34
34
35
+
### Backend requirements at a glance
36
+
37
+
| Backend | Python package | Debian/Ubuntu system packages |
38
+
|---|---|---|
39
+
|`pyodbc`|`dbt-sqlserver[pyodbc]` or `pyodbc`|`unixodbc-dev` plus the Microsoft ODBC Driver for SQL Server |
40
+
|`mssql-python`|`dbt-sqlserver[mssql]` or `mssql-python`|`libltdl7`, `libkrb5-3`, `libgssapi-krb5-2`|
41
+
42
+
The default development flow uses the ODBC-based path, but the ODBC driver itself is now an optional dependency. If you want to develop or test that backend, install either the adapter extra or the driver itself before running tests.
43
+
44
+
```shell
45
+
pip install -U "dbt-sqlserver[pyodbc]"
46
+
# or
47
+
pip install -U pyodbc
48
+
```
49
+
50
+
If you want to develop or test the optional `mssql-python` backend instead, install either the adapter extra or the driver itself before running tests.
51
+
52
+
```shell
53
+
pip install -U "dbt-sqlserver[mssql]"
54
+
# or
55
+
pip install -U mssql-python
56
+
```
57
+
58
+
On Debian/Ubuntu-based environments, `mssql-python` may also require these system libraries:
This will use Docker Compose to spin up a local instance of SQL Server. Docker Compose is now bundled with Docker, so make sure to [install the latest version of Docker](https://docs.docker.com/get-docker/).
36
65
37
66
Next, tell our tests how they should connect to the local instance by creating a file called `test.env` in the root of the project.
38
67
You can use the provided `test.env.sample` as a base and if you started the server with `make server`, then this matches the instance running on your local machine.
39
68
69
+
If you are testing the optional `mssql-python` backend, also enable its backend setting in `test.env` so the adapter selects that implementation instead of the legacy driver-based one.
70
+
40
71
```shell
41
72
cp test.env.sample test.env
42
73
```
43
74
75
+
When using the optional `mssql-python` backend, update `test.env` with:
76
+
77
+
```shell
78
+
SQLSERVER_TEST_BACKEND=mssql-python
79
+
```
80
+
44
81
You can tweak the contents of this file to test against a different database.
45
82
46
83
Note that we need 3 users to be able to run tests related to the grants.
@@ -57,6 +94,8 @@ make unit
57
94
make functional
58
95
```
59
96
97
+
This remains the documented test procedure for both connection backends. When the `pyodbc` path is enabled, run the same commands after installing `dbt-sqlserver[pyodbc]` or `pyodbc`. When the `mssql-python` backend is enabled, run the same commands after installing `dbt-sqlserver[mssql]` or `mssql-python` and setting `SQLSERVER_TEST_BACKEND=mssql-python` in `test.env`.
98
+
60
99
## CI/CD
61
100
62
101
We use Docker images that have all the things we need to test the adapter in the CI/CD workflows.
-[Adapter documentation, usage and important notes](https://docs.getdbt.com/reference/resource-configs/mssql-configs)
14
14
15
15
Join us on the [dbt Slack](https://getdbt.slack.com/archives/CMRMDDQ9W) to ask questions, get help, or to discuss the project.
16
16
17
17
## Installation
18
18
19
-
This adapter requires the Microsoft ODBC driver to be installed:
19
+
The default install uses the `pyodbc` backend and includes the `pyodbc` dependency. If you want the optional `mssql-python` backend instead, install the `mssql` extra.
@@ -51,8 +98,6 @@ See [the changelog](CHANGELOG.md)
51
98
52
99
## Configuration
53
100
54
-
### Flags
55
-
56
101
- `dbt_sqlserver_use_default_schema_concat`: *(default: `false`)* Controls schema name generation when a [custom schema](https://docs.getdbt.com/docs/build/custom-schemas) is set on a model.
57
102
58
103
| Flag value | `custom_schema_name` | Result |
@@ -77,6 +122,31 @@ See [the changelog](CHANGELOG.md)
77
122
> **Note:** If you want to permanently customise schema generation and avoid any future changes, override the `sqlserver__generate_schema_name` macro directly in your project instead.
78
123
79
124
125
+
### `dbt_sqlserver_use_default_schema_concat`
126
+
127
+
*(default: `false`)* Controls schema name generation when a [custom schema](https://docs.getdbt.com/docs/build/custom-schemas) is set on a model.
When `false`, `custom_schema_name` is used as-is without being prefixed by `target.schema`.
137
+
When `true`, the adapter delegates to dbt-core's `default__generate_schema_name`.
138
+
139
+
```yaml
140
+
# dbt_project.yml
141
+
vars:
142
+
dbt_sqlserver_use_default_schema_concat: true
143
+
```
144
+
145
+
> **Note:** To permanently customise schema generation without a flag dependency, override the `sqlserver__generate_schema_name` macro directly in your project.
146
+
147
+
### `backend`
148
+
149
+
*(default: `pyodbc`)* Set to `mssql-python` in a profile target to use the `mssql-python` backend instead of `pyodbc`. The adapter fails if the required backend package (Python dependency), such as `pyodbc` or `mssql-python`, is not installed.
80
150
81
151
## Contributing
82
152
@@ -85,7 +155,7 @@ See [the changelog](CHANGELOG.md)
85
155
[](https://github.com/dbt-msft/dbt-sqlserver/actions/workflows/integration-tests-azure.yml)
86
156
87
157
This adapter is community-maintained.
88
-
You are welcome to contribute by creating issues, opening or reviewing pull requests or helping other users in Slack channel.
158
+
You are welcome to contribute by creating issues, opening or reviewing pull requests, or helping other users in the Slack channel.
89
159
If you're unsure how to get started, check out our [contributing guide](CONTRIBUTING.md).
0 commit comments