Skip to content

Commit ef2b882

Browse files
committed
Add Copilot instructions for dbt-sqlserver adapter
1 parent f9b5ec1 commit ef2b882

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

.github/copilot-instructions.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Copilot instructions — dbt-sqlserver
2+
3+
Purpose
4+
- Quickly orient AI coding agents to the structure, conventions, and workflows required to make safe, useful changes to the dbt-sqlserver adapter.
5+
- Focuses on concrete, discoverable facts: major entry points, test/run commands, files to edit for common changes, and CI/development quirks.
6+
7+
Big picture (keep in mind)
8+
- This repository implements a dbt adapter for Microsoft SQL Server / Azure SQL. Core adapter code is under `dbt/adapters/sqlserver/` and is built on top of `dbt.adapters.fabric` (`FabricAdapter`).
9+
- Key responsibilities:
10+
- Connection & auth: `sqlserver_connections.py` (pyodbc + AAD support; extends FabricConnectionManager)
11+
- Credentials: `sqlserver_credentials.py` (dataclass, inherits FabricCredentials)
12+
- Adapter surface: `sqlserver_adapter.py` (exports `ConnectionManager`, `Column`, `Relation`, constraint rendering, date function, and incremental strategies)
13+
- Relation policies and limits: `relation_configs/policies.py` and `sqlserver_relation.py` (identifier length enforcement — max 127 chars)
14+
- SQL helper macros & materializations: `dbt/include/sqlserver/macros/…` and `dbt/include/sqlserver/materializations/…` (use these as canonical SQL patterns)
15+
16+
Concrete code patterns & examples
17+
- Adapter subclass pattern: `SQLServerAdapter(FabricAdapter)` sets class attributes to concrete implementations. To add new surface behavior, add/override methods in `sqlserver_adapter.py` and supply new classes for `ConnectionManager`, `Column`, or `Relation`.
18+
- Connection/auth extension: `sqlserver_connections.py` merges Fabric's `AZURE_AUTH_FUNCTIONS` and adds `"serviceprincipal"` and `"msi"` keys. To add new auth types, provide a function that returns an `azure.core.credentials.AccessToken` and register it in `AZURE_AUTH_FUNCTIONS`.
19+
- Constraints: `render_model_constraint` produces SQL like `add constraint {name} unique nonclustered(col1,col2)` — note the adapter intentionally uses nonclustered constraints.
20+
- Limits and pagination: `SQLServerRelation.render_limited()` uses SQL Server `TOP` and special aliasing for `limit == 0`.
21+
- Versioning: adapter version is declared in `dbt/adapters/sqlserver/__version__.py``sqlserver_connections` uses it to set `APP` in the connection string.
22+
23+
Tests & CI (how to run locally and what CI does)
24+
- Install dev/test deps: `pip install -r dev_requirements.txt` (CI runs this step).
25+
- Unit tests: `make unit` or `pytest -n auto -ra -v tests/unit`.
26+
- Functional tests: `make functional` or:
27+
- Example: `pytest -ra -v tests/functional --profile "ci_sql_server"`
28+
- Functional tests select dbt profile via `--profile` (see `tests/conftest.py` for profiles: `ci_sql_server`, `ci_azure_*`, `user`, `user_azure`)
29+
- CI sets environment variables such as `DBT_TEST_USER_1`, `SQLSERVER_TEST_DRIVER` (see `.github/workflows/integration-tests-sqlserver.yml`).
30+
- Local SQL Server for functional testing: `make server` (uses `docker-compose.yml` and `devops/server.Dockerfile`) or `docker compose up -d`.
31+
- 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/*`.
32+
33+
Development environment & onboarding
34+
- Recommended Python version for development: Python 3.10 (the project examples use 3.10.7). A common bootstrapping flow uses `pyenv`:
35+
- `pyenv install 3.10.7`
36+
- `pyenv virtualenv 3.10.7 dbt-sqlserver`
37+
- `pyenv activate dbt-sqlserver`
38+
- 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`).
39+
- A devcontainer is provided (since v1.7.2) for a consistent development environment — look for `.devcontainer` in the repo when onboarding.
40+
41+
Test environment file
42+
- Functional tests expect a `test.env` file in the repo root. Create it from the sample: `cp test.env.sample test.env`.
43+
- Functional tests require three test users for grants-related tests. Ensure these environment variables are set in `test.env` or your environment:
44+
- `DBT_TEST_USER_1`
45+
- `DBT_TEST_USER_2`
46+
- `DBT_TEST_USER_3`
47+
48+
Releasing a new version
49+
- To cut a release: bump the version in `dbt/adapters/sqlserver/__version__.py`, create a git tag named `v<version>`, and push it to GitHub. The `release-version` workflow will publish the package to PyPI.
50+
51+
Project conventions and gotchas
52+
- Many classes use Python dataclasses (credentials, relation policies) — follow that style for new small value types.
53+
- String length limit: identifiers are limited to 127 chars (`MAX_CHARACTERS_IN_IDENTIFIER` in `relation_configs/policies.py`). Tests and runtime enforce this in `sqlserver_relation.py`.
54+
- SQL is generated with explicit SQL Server semantics (e.g., uses `TOP`, nonclustered constraints, `CAST(... as datetimeoffset)` for time filters). Prefer existing macros in `dbt/include/sqlserver/macros` when creating SQL.
55+
- Authentication modes: `authentication` in credentials can be `sql`, `serviceprincipal`, `msi` or Fabric-provided options (see `sqlserver_connections.py` and tests). When adding auth modes, add tests under `tests/functional` and `tests/unit/adapters/mssql`.
56+
- Logging/debug: connection-level logs use logger name `sqlserver` (see `sqlserver_connections.py`). Use these logs when debugging connection/auth issues.
57+
58+
Where to change common features
59+
- To change connection behavior or add a new driver tweak: edit `dbt/adapters/sqlserver/sqlserver_connections.py` and corresponding unit tests in `tests/unit/adapters/mssql`.
60+
- To add adapter-level behavior: edit `dbt/adapters/sqlserver/sqlserver_adapter.py` and add tests under `tests/functional/adapter/dbt`.
61+
- To expose or change macros/materializations: update files under `dbt/include/sqlserver/macro*` and `materializations/*`.
62+
63+
Quick checklist for a typical change
64+
- Add/modify implementation in `dbt/adapters/sqlserver/*`.
65+
- Add unit tests in `tests/unit` and functional tests in `tests/functional` (pick proper profile).
66+
- Run `make dev` to install test deps and enable pre-commit, run `make unit` and `make functional` locally where possible.
67+
- If the change impacts connection images or CI, update `devops/Dockerfile*`, `docker-compose.yml`, and `.github/workflows/*` accordingly.
68+
69+
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.

0 commit comments

Comments
 (0)