Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
FROM mcr.microsoft.com/devcontainers/python:1-3.10-bookworm
FROM mcr.microsoft.com/devcontainers/python:3.11-trixie

RUN rm -f /etc/apt/sources.list.d/yarn.list \
/etc/apt/sources.list.d/yarn.sources \
/usr/share/keyrings/yarnkey.gpg \
/etc/apt/keyrings/yarn-archive-keyring.gpg
/etc/apt/keyrings/yarn-archive-keyring.gpg

COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
9 changes: 6 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"name": "Python 3",
"name": "DBT - SQL Server",
"build": {
"dockerfile": "Dockerfile"
},
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2.16.1": {}
"ghcr.io/devcontainers/features/docker-in-docker:2.16.1": {
"moby": false
}
},
"forwardPorts": [1433],
"postStartCommand": "/bin/bash ./.devcontainer/setup_odbc.sh & /bin/bash ./.devcontainer/setup_env.sh",
"postCreateCommand": "/bin/bash ./.devcontainer/setup_odbc.sh && /bin/bash ./.devcontainer/setup_env.sh",
"postStartCommand": "docker compose up -d",
"containerEnv": {
"SQLSERVER_TEST_DRIVER": "ODBC Driver 18 for SQL Server",
"SQLSERVER_TEST_HOST": "127.0.0.1",
Expand Down
14 changes: 9 additions & 5 deletions .devcontainer/setup_env.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
cp test.env.sample test.env
#!/bin/bash
set -euo pipefail

docker compose build
docker compose up -d

pip install -r dev_requirements.txt
if [ ! -f test.env ]; then
cp test.env.sample test.env
fi
export UV_VENV_CLEAR=1
uv venv .venv
uv pip install --python .venv/bin/python -r dev_requirements.txt
.venv/bin/pre-commit install
17 changes: 9 additions & 8 deletions .devcontainer/setup_odbc.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
sudo install -d -m 0755 /usr/share/keyrings
curl -fsSL https://packages.microsoft.com/keys/microsoft-rolling.asc | gpg --dearmor | sudo tee /usr/share/keyrings/microsoft-prod.gpg >/dev/null

#Download appropriate package for the OS version
#Choose only ONE of the following, corresponding to your OS version

#Debian 12
curl https://packages.microsoft.com/config/debian/12/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
#Debian 13 (trixie)
curl -fsSL https://packages.microsoft.com/config/debian/13/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list >/dev/null

sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18
sudo apt update
sudo ACCEPT_EULA=Y apt install -y msodbcsql18
# optional: for bcp and sqlcmd
sudo ACCEPT_EULA=Y apt-get install -y mssql-tools18
sudo ACCEPT_EULA=Y apt install -y mssql-tools18
echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
sudo apt-get install -y unixodbc-dev
sudo apt install -y unixodbc-dev
# optional: kerberos library for debian-slim distributions
sudo apt-get install -y libgssapi-krb5-2
sudo apt install -y libgssapi-krb5-2
12 changes: 6 additions & 6 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Concrete code patterns & examples
- Versioning: adapter version is declared in `dbt/adapters/sqlserver/__version__.py` — `sqlserver_connections` uses it to set `APP` in the connection string.

Tests & CI (how to run locally and what CI does)
- Install dev/test deps: `pip install -r dev_requirements.txt` (CI runs this step).
- Install dev/test deps locally with `make dev` or `uv venv .venv && uv pip install --python .venv/bin/python -r dev_requirements.txt`.
- Unit tests: `make unit` or `pytest -n auto -ra -v tests/unit`.
- Functional tests: `make functional` or:
- Example: `pytest -ra -v tests/functional --profile "ci_sql_server"`
Expand All @@ -36,10 +36,10 @@ Tests & CI (how to run locally and what CI does)
- CI images and behavior: workflows build and use GHCR images named like `ghcr.io/${{ github.repository }}:CI-<py>-msodbc18` and `server-<version>`; updating CI container logic requires editing `devops/*` and `.github/workflows/*`.

Development environment & onboarding
- Recommended Python version for development: Python 3.10 (the project examples use 3.10.7). A common bootstrapping flow uses `pyenv`:
- `pyenv install 3.10.7`
- `pyenv virtualenv 3.10.7 dbt-sqlserver`
- `pyenv activate dbt-sqlserver`
- Recommended Python version for development: Python 3.10.
- Preferred bootstrapping flow uses `uv` and a local `.venv`:
- `uv venv .venv`
- `uv pip install --python .venv/bin/python -r dev_requirements.txt`
- Install dev dependencies and enable pre-commit with `make dev`; run `make help` to list Makefile targets (e.g. `make unit`, `make functional`, `make server`).
- A devcontainer is provided (since v1.7.2) for a consistent development environment — look for `.devcontainer` in the repo when onboarding.

Expand Down Expand Up @@ -71,4 +71,4 @@ Quick checklist for a typical change
- Run `make dev` to install test deps and enable pre-commit, run `make unit` and `make functional` locally where possible.
- If the change impacts connection images or CI, update `devops/Dockerfile*`, `docker-compose.yml`, and `.github/workflows/*` accordingly.

If anything here is unclear or you need more detail on specific areas (auth flows, CI images, macros), find files or behavior you want expanded and iterate.
If anything here is unclear or you need more detail on specific areas (auth flows, CI images, macros), find files or behavior you want expanded and iterate.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_language_version:
python: python3.10
python: python3
repos:
- repo: 'https://github.com/pre-commit/pre-commit-hooks'
rev: v4.6.0
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
"python.testing.pytestEnabled": true,
"python-envs.defaultEnvManager": "ms-python.python:venv"
}
18 changes: 9 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
# Development of the adapter

Python 3.10 is used for developing the adapter. To get started, bootstrap your environment as follows:

Create a virtual environment, [pyenv](https://github.com/pyenv/pyenv) is used in the example:
Python 3.10 is used for developing the adapter. To get started, bootstrap your environment with `uv`:

```shell
pyenv install 3.10.7
pyenv virtualenv 3.10.7 dbt-sqlserver
pyenv activate dbt-sqlserver
uv venv .venv
uv pip install --python .venv/bin/python -r dev_requirements.txt
```

Install the development dependencies and pre-commit and get information about possible make commands:
This creates a local `.venv` in the workspace and installs the adapter in editable mode together with the development dependencies.

You can also use the repo bootstrap target, which performs the same setup and installs the pre-commit hooks:

```shell
make dev
make help
```

[Pre-commit](https://pre-commit.com/) helps us to maintain a consistent style and code quality across the entire project.
After running `make dev`, pre-commit will automatically validate your commits and fix any formatting issues whenever possible.
After running `make dev`, pre-commit will use the tools installed in `.venv` and automatically validate your commits whenever possible.

## Devcontainer

A devcontainer file has been added since 1.7.2 to simpify creating the development environment.
A devcontainer file has been added since 1.7.2 to simplify creating the development environment.
It installs `uv`, creates `.venv`, installs the development dependencies, and starts the local SQL Server container on startup.

## Testing

Expand Down
31 changes: 18 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
.DEFAULT_GOAL:=help
THREADS ?= auto
VENV ?= .venv
PYTHON ?= $(VENV)/bin/python
PRE_COMMIT ?= $(VENV)/bin/pre-commit
PYTEST ?= $(VENV)/bin/pytest

.PHONY: dev
dev: ## Installs adapter in develop mode along with development dependencies
@\
pip install -r dev_requirements.txt && pre-commit install
uv venv $(VENV) && uv pip install --python $(PYTHON) -r dev_requirements.txt && $(PRE_COMMIT) install

.PHONY: mypy
mypy: ## Runs mypy against staged changes for static type checking.
@\
pre-commit run --hook-stage manual mypy-check | grep -v "INFO"
$(PRE_COMMIT) run --hook-stage manual mypy-check | grep -v "INFO"

.PHONY: flake8
flake8: ## Runs flake8 against staged changes to enforce style guide.
@\
pre-commit run --hook-stage manual flake8-check | grep -v "INFO"
$(PRE_COMMIT) run --hook-stage manual flake8-check | grep -v "INFO"

.PHONY: black
black: ## Runs black against staged changes to enforce style guide.
@\
pre-commit run --hook-stage manual black-check -v | grep -v "INFO"
$(PRE_COMMIT) run --hook-stage manual black-check -v | grep -v "INFO"

.PHONY: lint
lint: ## Runs flake8 and mypy code checks against staged changes.
@\
pre-commit run flake8-check --hook-stage manual | grep -v "INFO"; \
pre-commit run mypy-check --hook-stage manual | grep -v "INFO"
$(PRE_COMMIT) run flake8-check --hook-stage manual | grep -v "INFO"; \
$(PRE_COMMIT) run mypy-check --hook-stage manual | grep -v "INFO"

.PHONY: all
all: ## Runs all checks against staged changes.
@\
pre-commit run -a
$(PRE_COMMIT) run -a

.PHONY: linecheck
linecheck: ## Checks for all Python lines 100 characters or more
Expand All @@ -39,20 +44,20 @@ linecheck: ## Checks for all Python lines 100 characters or more
.PHONY: unit
unit: ## Runs unit tests.
@\
pytest -n auto -ra -v tests/unit
$(PYTEST) -n auto -ra -v tests/unit

.PHONY: functional
functional: ## Runs functional tests.
@\
pytest -n auto -ra -v tests/functional
$(PYTEST) -n $(THREADS) -ra -v tests/functional

.PHONY: test
test: ## Runs unit tests and code checks against staged changes.
@\
pytest -n auto -ra -v tests/unit; \
pre-commit run black-check --hook-stage manual | grep -v "INFO"; \
pre-commit run flake8-check --hook-stage manual | grep -v "INFO"; \
pre-commit run mypy-check --hook-stage manual | grep -v "INFO"
$(PYTEST) -n auto -ra -v tests/unit; \
$(PRE_COMMIT) run black-check --hook-stage manual | grep -v "INFO"; \
$(PRE_COMMIT) run flake8-check --hook-stage manual | grep -v "INFO"; \
$(PRE_COMMIT) run mypy-check --hook-stage manual | grep -v "INFO"

.PHONY: server
server: ## Spins up a local MS SQL Server instance for development. Docker-compose is required.
Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,33 @@ pip install -U --pre dbt-sqlserver

See [the changelog](CHANGELOG.md)

## Configuration

### Flags

- `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.

| Flag value | `custom_schema_name` | Result |
|---|---|---|
| `false` (default, legacy) | *(none)* | `target.schema` |
| `false` (default, legacy) | `"reporting"` | `reporting` |
| `true` (dbt-core standard) | *(none)* | `target.schema` |
| `true` (dbt-core standard) | `"reporting"` | `target.schema_reporting` |

When `false` (the default), the adapter uses its legacy behaviour: `custom_schema_name` is used **as-is** without being prefixed by `target.schema`.
When `true`, the adapter delegates to dbt-core's `default__generate_schema_name`, which concatenates `target.schema` + `_` + `custom_schema_name`.

**Example usage in `dbt_project.yml`:**

```yaml
vars:
dbt_sqlserver_use_default_schema_concat: true # Enable standard schema concatenation
```

> **Note:** If you want to permanently customise schema generation and avoid any future deprecation of this flag, override the `sqlserver__generate_schema_name` macro directly in your project.



## Contributing

[![Unit tests](https://github.com/dbt-msft/dbt-sqlserver/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/dbt-msft/dbt-sqlserver/actions/workflows/unit-tests.yml)
Expand Down
2 changes: 1 addition & 1 deletion dbt/adapters/sqlserver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
adapter=SQLServerAdapter,
credentials=SQLServerCredentials,
include_path=sqlserver.PACKAGE_PATH,
dependencies=["fabric"],
dependencies=[],
)

__all__ = [
Expand Down
Loading
Loading