From 703862b68734b806c42cf8fc8d86fd248633f8aa Mon Sep 17 00:00:00 2001 From: Josh Markovic Date: Wed, 24 Jun 2026 19:58:04 +0000 Subject: [PATCH 1/7] feat: add SQL Server 2025 support Cover SQL Server 2025 in the integration-test matrix (pyodbc and mssql-python on Python 3.13 / ODBC Driver 18) and add it to the published server CI images. Rename the server Dockerfile build arg SQLServer_VERSION to MSSQL_VERSION to match the build-arg the workflow already passes; with the old name the matrix version was ignored and every image used the 2022 default. Document 2025 as a supported version and refresh the stale dbt-core 0.14 compatibility note to 1.10. --- .../workflows/integration-tests-sqlserver.yml | 14 ++++++++++++- .github/workflows/publish-docker.yml | 2 +- CHANGELOG.md | 1 + README.md | 20 ++++++++++++++++--- devops/server.Dockerfile | 4 ++-- 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/.github/workflows/integration-tests-sqlserver.yml b/.github/workflows/integration-tests-sqlserver.yml index c31c55f6a..62b9a2b21 100644 --- a/.github/workflows/integration-tests-sqlserver.yml +++ b/.github/workflows/integration-tests-sqlserver.yml @@ -82,7 +82,19 @@ jobs: sqlserver_version: "2019" msodbc_version: "17" collation: SQL_Latin1_General_CP1_CI_AS - # Add the case-sensitive collation only on the latest SQL Server + # SQL Server 2025 (newest): cover both backends on the latest + # Python and ODBC driver (18). + - backend: pyodbc + python_version: "3.13" + sqlserver_version: "2025" + msodbc_version: "18" + collation: SQL_Latin1_General_CP1_CI_AS + - backend: mssql-python + python_version: "3.13" + sqlserver_version: "2025" + msodbc_version: "18" + collation: SQL_Latin1_General_CP1_CI_AS + # Add the case-sensitive collation on the SQL Server 2022 baseline # and latest Python/backend rows. - backend: pyodbc python_version: "3.13" diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml index 0a7bdb8fd..ce9a1e9b1 100644 --- a/.github/workflows/publish-docker.yml +++ b/.github/workflows/publish-docker.yml @@ -44,7 +44,7 @@ jobs: publish-docker-server: strategy: matrix: - mssql_version: ["2017", "2019", "2022"] + mssql_version: ["2017", "2019", "2022", "2025"] runs-on: ubuntu-latest permissions: contents: read diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d6a2e9b4..9fe487b5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - Add `drop_unmanaged_indexes` config (`false` (default) / `warn` / `true`) for indexes dbt didn't create. - Validate cross-index config conflicts (multiple clustered indexes, clustered vs `as_columnstore`). - Document the minimum supported SQL Server version (2017). Partitioning, `XML_COMPRESSION` and ordered columnstore are not yet expressible in the `indexes` config. +- Add SQL Server 2025 to the integration-test matrix (pyodbc and `mssql-python` backends, ODBC Driver 18) and document it as a supported version. ### v1.10.0 diff --git a/README.md b/README.md index 34f25d944..5bf677052 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,24 @@ [dbt](https://www.getdbt.com) adapter for Microsoft SQL Server and Azure SQL services. -The adapter supports dbt-core 0.14 or newer and follows the same versioning scheme. -E.g. version 1.1.x of the adapter will be compatible with dbt-core 1.1.x. +The adapter supports dbt-core 1.10 or newer and follows the same versioning scheme. +E.g. version 1.10.x of the adapter will be compatible with dbt-core 1.10.x. -The minimum supported SQL Server version is SQL Server 2017. +## Supported SQL Server versions + +The adapter is tested against the following SQL Server versions: + +| SQL Server version | Supported | +|---|---| +| SQL Server 2017 | ✅ (minimum supported version) | +| SQL Server 2019 | ✅ | +| SQL Server 2022 | ✅ | +| SQL Server 2025 | ✅ | +| Azure SQL Database | ✅ | +| Azure SQL Managed Instance | ✅ | + +The minimum supported SQL Server version is SQL Server 2017; older versions are not supported. +SQL Server 2017, 2019, 2022, and 2025 are covered by the integration test suite, and Azure SQL services are tested separately. ## Documentation diff --git a/devops/server.Dockerfile b/devops/server.Dockerfile index d5743136d..a7a3fe082 100644 --- a/devops/server.Dockerfile +++ b/devops/server.Dockerfile @@ -1,5 +1,5 @@ -ARG SQLServer_VERSION="2022" -FROM mcr.microsoft.com/mssql/server:${SQLServer_VERSION}-latest +ARG MSSQL_VERSION="2022" +FROM mcr.microsoft.com/mssql/server:${MSSQL_VERSION}-latest ENV COLLATION="SQL_Latin1_General_CP1_CI_AS" From 391080c38043f277d530a70cab4a7c111222a053 Mon Sep 17 00:00:00 2001 From: Josh Markovic Date: Wed, 24 Jun 2026 19:58:04 +0000 Subject: [PATCH 2/7] docs: document the as_columnstore table config Explain that table materializations build a clustered columnstore index by default, and that as_columnstore: false is required for tables with (n)varchar(max)/LOB columns such as dbt store_failures audit tables. --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 5bf677052..155d02129 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,29 @@ flags: **Compatibility notes:** Enabling `dbt_sqlserver_use_dbt_transactions: true` may expose transaction-state assumptions hidden by autocommit-only mode. Explicit transaction macros may interact with dbt-managed transactions, and cleanup after failed DDL/DML may differ. Review pre/post hooks for in-transaction vs out-of-transaction semantics. +### `as_columnstore` + +*(default: `true`)* When building a table, the adapter creates a [clustered columnstore index](https://learn.microsoft.com/en-us/sql/relational-databases/indexes/columnstore-indexes-overview) (CCI) on it. Set `as_columnstore: false` to build a plain rowstore table instead. + +This matters for any table containing a `(n)varchar(max)` or other LOB column, because SQL Server does not allow those data types to participate in a columnstore index. The table build fails with: + +> Column '...' has a data type that cannot participate in a columnstore index. + +A common case is dbt's [test failure storage](https://docs.getdbt.com/reference/resource-configs/store_failures): the audit tables can contain `VARCHAR(MAX)` columns (dbt's `STRING` type maps to `VARCHAR(MAX)`), so disable the CCI on those resources: + +```yaml +# dbt_project.yml +data_tests: + +store_failures: true + +as_columnstore: false # avoids CCI on (n)varchar(max) audit columns +``` + +You can also set it per model: + +```sql +{{ config(materialized="table", as_columnstore=false) }} +``` + ## 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) From 7d8e90b0fa0f43cb6184aaf9500f6338763d3b78 Mon Sep 17 00:00:00 2001 From: Josh Markovic Date: Wed, 24 Jun 2026 19:58:04 +0000 Subject: [PATCH 3/7] test: keep empty audit table on passing store-failures run (#601) A passing test run with --store-failures must replace prior failures with an empty audit table rather than drop it. Adds a functional regression test for dbt-msft/dbt-sqlserver#601. --- .../mssql/test_store_failures_passing.py | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 tests/functional/adapter/mssql/test_store_failures_passing.py diff --git a/tests/functional/adapter/mssql/test_store_failures_passing.py b/tests/functional/adapter/mssql/test_store_failures_passing.py new file mode 100644 index 000000000..728e08a0d --- /dev/null +++ b/tests/functional/adapter/mssql/test_store_failures_passing.py @@ -0,0 +1,101 @@ +# flake8: noqa: E501 +"""Regression test for dbt-msft/dbt-sqlserver#601. + +With ``--store-failures``, a test that *passes* must leave behind an empty +audit relation, not drop it. dbt's contract: "A test's results will always +replace previous failures for the same test, even if that test results in no +failures." The SQL Server adapter was reported to ``DROP`` the audit table on a +passing test instead of replacing it with an empty table (Postgres creates the +empty table). + +This exercises the exact reported scenario: a passing test configured with +``store_failures`` materialized as a ``table``. It asserts the audit relation +exists, is a base table (not a view), is empty, and survives idempotent re-runs. +""" +import pytest + +from dbt.tests.util import run_dbt + +# the default audit schema (_dbt_test__audit) plus the test schema can exceed +# identifier limits; use a short suffix as the rest of the suite does. +TEST_AUDIT_SCHEMA_SUFFIX = "dbt_test__aud" + +model__chipmunks = """ +select 1 as id, 'alvin' as name +union all +select 2 as id, 'simon' as name +""" + +# returns zero rows -> the test passes +test__passing_601 = """ +{{ config(store_failures=true, store_failures_as='table') }} +select * from {{ ref('chipmunks') }} +where 1 = 2 +""" + + +class TestStoreFailuresPassingKeepsEmptyTable: + @pytest.fixture(scope="class") + def models(self): + return {"chipmunks.sql": model__chipmunks} + + @pytest.fixture(scope="class") + def tests(self): + return {"passing_601.sql": test__passing_601} + + @pytest.fixture(scope="class") + def project_config_update(self): + return { + "vars": {"dbt_sqlserver_use_default_schema_concat": True}, + "data_tests": {"+schema": TEST_AUDIT_SCHEMA_SUFFIX}, + } + + @pytest.fixture(scope="function", autouse=True) + def setup(self, project): + self.audit_schema = f"{project.test_schema}_{TEST_AUDIT_SCHEMA_SUFFIX}" + run_dbt(["run"]) + yield + with project.adapter.connection_named("__test"): + relation = project.adapter.Relation.create( + database=project.database, schema=self.audit_schema + ) + project.adapter.drop_schema(relation) + + def _assert_empty_audit_table(self, project): + # type_desc proves the relation exists AND is a user table (not a view). + # On the #601 bug the relation is dropped, so this returns no rows. + # Queried via sys catalog (lowercase column names) so it is safe under a + # case-sensitive database collation. + rows = project.run_sql( + f""" + select o.type_desc + from sys.objects o + join sys.schemas s on o.schema_id = s.schema_id + where s.name = '{self.audit_schema}' + and o.name = 'passing_601' + """, + fetch="all", + ) + assert len(rows) == 1 and rows[0][0] == "USER_TABLE", ( + f"audit relation [{self.audit_schema}].[passing_601] should be a user " + f"table that persists after a passing store-failures run, got: " + f"{[tuple(r) for r in rows]}" + ) + # and it must be empty (the failures were replaced with nothing) + count = project.run_sql( + f"select count(*) from [{self.audit_schema}].[passing_601]", + fetch="one", + ) + assert count[0] == 0, f"audit table should be empty, has {count[0]} rows" + + def test_passing_test_keeps_empty_audit_table(self, project): + results = run_dbt(["test", "--store-failures"], expect_pass=True) + assert len(results) == 1 + assert results[0].status == "pass" + assert results[0].failures == 0 + self._assert_empty_audit_table(project) + + # idempotency: a second run must still leave the empty table in place + results = run_dbt(["test", "--store-failures"], expect_pass=True) + assert results[0].status == "pass" + self._assert_empty_audit_table(project) From 66634a1c6f2e9b8638c7e0508f565520312feca1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 24 Jun 2026 20:30:43 +0000 Subject: [PATCH 4/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/functional/adapter/mssql/test_store_failures_passing.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/functional/adapter/mssql/test_store_failures_passing.py b/tests/functional/adapter/mssql/test_store_failures_passing.py index 728e08a0d..7aa44f180 100644 --- a/tests/functional/adapter/mssql/test_store_failures_passing.py +++ b/tests/functional/adapter/mssql/test_store_failures_passing.py @@ -12,6 +12,7 @@ ``store_failures`` materialized as a ``table``. It asserts the audit relation exists, is a base table (not a view), is empty, and survives idempotent re-runs. """ + import pytest from dbt.tests.util import run_dbt From c137d8053e7fcdc40aec19b08a1d8d599827861f Mon Sep 17 00:00:00 2001 From: joshmarkovic <52184130+joshmarkovic@users.noreply.github.com> Date: Wed, 24 Jun 2026 23:26:57 -0400 Subject: [PATCH 5/7] Update README.md Co-authored-by: Axell Padilla <68310020+axellpadilla@users.noreply.github.com> --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 155d02129..839130cc4 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,9 @@ The adapter is tested against the following SQL Server versions: | Azure SQL Managed Instance | ✅ | The minimum supported SQL Server version is SQL Server 2017; older versions are not supported. -SQL Server 2017, 2019, 2022, and 2025 are covered by the integration test suite, and Azure SQL services are tested separately. +## Supported SQL Server versions + +SQL Server 2017, 2019, 2022, and 2025 are covered by the integration test suite. Azure SQL Database and Azure SQL Managed Instance are not covered by the integration test suite, but are expected to be compatible. ## Documentation From ad899620908439470bd182095dfec68ed5a3c52e Mon Sep 17 00:00:00 2001 From: Josh Markovic Date: Thu, 25 Jun 2026 14:25:20 +0000 Subject: [PATCH 6/7] ci: promote SQL Server 2025 to baseline and fix README support section Addresses @axellpadilla's review on #721. - integration tests: make 2025 the matrix baseline, replacing 2022 as the latest tier. Keep 2017, 2019 and 2022 as single legacy rows so all four versions stay covered by CI. - README: remove the duplicate "Supported SQL Server versions" heading and the Azure SQL Database / Managed Instance rows that were marked tested. Azure is now described as not covered by CI but expected to be compatible. --- .../workflows/integration-tests-sqlserver.yml | 31 +++++++------------ README.md | 3 -- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/.github/workflows/integration-tests-sqlserver.yml b/.github/workflows/integration-tests-sqlserver.yml index 62b9a2b21..0aa6f2f34 100644 --- a/.github/workflows/integration-tests-sqlserver.yml +++ b/.github/workflows/integration-tests-sqlserver.yml @@ -43,31 +43,31 @@ jobs: matrix: python_version: ["3.10", "3.11", "3.12", "3.13"] backend: [pyodbc, mssql-python] - # Baseline on 2022 - sqlserver_version: ["2022"] + # Baseline on 2025 (newest) + sqlserver_version: ["2025"] msodbc_version: ["18"] collation: [SQL_Latin1_General_CP1_CI_AS] exclude: - backend: mssql-python python_version: "3.10" - sqlserver_version: "2022" + sqlserver_version: "2025" - backend: mssql-python python_version: "3.11" - sqlserver_version: "2022" + sqlserver_version: "2025" - backend: mssql-python python_version: "3.12" - sqlserver_version: "2022" + sqlserver_version: "2025" include: # Keep pyodbc on every supported Python version, but retain # SQL Server ODBC 17 coverage for the oldest and newest Python. - backend: pyodbc python_version: "3.10" - sqlserver_version: "2022" + sqlserver_version: "2025" msodbc_version: "17" collation: SQL_Latin1_General_CP1_CI_AS - backend: pyodbc python_version: "3.13" - sqlserver_version: "2022" + sqlserver_version: "2025" msodbc_version: "17" collation: SQL_Latin1_General_CP1_CI_AS # Older SQL Server versions stay on pyodbc only, with a single @@ -82,29 +82,22 @@ jobs: sqlserver_version: "2019" msodbc_version: "17" collation: SQL_Latin1_General_CP1_CI_AS - # SQL Server 2025 (newest): cover both backends on the latest - # Python and ODBC driver (18). - backend: pyodbc python_version: "3.13" - sqlserver_version: "2025" - msodbc_version: "18" - collation: SQL_Latin1_General_CP1_CI_AS - - backend: mssql-python - python_version: "3.13" - sqlserver_version: "2025" - msodbc_version: "18" + sqlserver_version: "2022" + msodbc_version: "17" collation: SQL_Latin1_General_CP1_CI_AS - # Add the case-sensitive collation on the SQL Server 2022 baseline + # Add the case-sensitive collation on the SQL Server 2025 baseline # and latest Python/backend rows. - backend: pyodbc python_version: "3.13" - sqlserver_version: "2022" + sqlserver_version: "2025" msodbc_version: "17" collation: SQL_Latin1_General_CP1_CS_AS # mssql-python stays on the latest Python only. - backend: mssql-python python_version: "3.13" - sqlserver_version: "2022" + sqlserver_version: "2025" msodbc_version: "18" collation: SQL_Latin1_General_CP1_CS_AS runs-on: ubuntu-latest diff --git a/README.md b/README.md index 7d3aba732..5ce591896 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,8 @@ The adapter is tested against the following SQL Server versions: | SQL Server 2019 | ✅ | | SQL Server 2022 | ✅ | | SQL Server 2025 | ✅ | -| Azure SQL Database | ✅ | -| Azure SQL Managed Instance | ✅ | The minimum supported SQL Server version is SQL Server 2017; older versions are not supported. -## Supported SQL Server versions SQL Server 2017, 2019, 2022, and 2025 are covered by the integration test suite. Azure SQL Database and Azure SQL Managed Instance are not covered by the integration test suite, but are expected to be compatible. From 8d9d883ae56f0bde6744bea40d8b523392c5a710 Mon Sep 17 00:00:00 2001 From: Josh Markovic Date: Sat, 27 Jun 2026 11:33:54 -0400 Subject: [PATCH 7/7] fix: gate 2019+ CREATE INDEX options on detected engine version The index feature emits OPTIMIZE_FOR_SEQUENTIAL_KEY and RESUMABLE (plus RESUMABLE's MAX_DURATION) unconditionally. These are only recognized on SQL Server 2019 (major 15)+, so on a genuine 2017 engine the CREATE INDEX fails with "is not a recognized CREATE INDEX option" (msg 155). This was masked until now: the server-2017/2019/2022 CI images were all built FROM ...:2022-latest because publish-docker passed build-arg MSSQL_VERSION while server.Dockerfile declared SQLServer_VERSION. This PR fixes that arg name, so the 2017 leg finally runs real 2017 and exposed the incompatibility. We support 2017 (Microsoft still does), so detect the engine major version and, when < 15, drop these options (with a warning) and build the index without them instead of failing. ONLINE is kept (recognized on 2017, edition-gated not version-gated). Behavior on 2019+ is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) --- CHANGELOG.md | 1 + .../sqlserver/macros/adapters/indexes.sql | 46 +++++++++++++++++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a83fb038..7e5479754 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ - Fix seed table ingestion of empty numeric cells by inlining `null` literals instead of binding parameters. [#425](https://github.com/dbt-msft/dbt-sqlserver/issues/425) - Guard `run_hooks` commit with `@@trancount` check for autocommit safety when running post-hooks. [#444](https://github.com/dbt-msft/dbt-sqlserver/issues/444) - Fix `columnstore IF EXISTS` guard to check `object_id('schema.table')` correctly. +- Gate the `optimize_for_sequential_key` and `resumable` index options on the detected engine version: they require SQL Server 2019+, so on 2017/2016 the index is now built without them (with a warning) instead of failing with "is not a recognized CREATE INDEX option". - Escape single quotes in `query_tag` before building `OPTION (LABEL)` clause. - Map Python `float` to SQL Server `float`, not `bigint`. - Set default port to `1433` (instead of Postgres `5432`) in `dbt init` profile template. diff --git a/dbt/include/sqlserver/macros/adapters/indexes.sql b/dbt/include/sqlserver/macros/adapters/indexes.sql index 72802eab2..464e04087 100644 --- a/dbt/include/sqlserver/macros/adapters/indexes.sql +++ b/dbt/include/sqlserver/macros/adapters/indexes.sql @@ -238,6 +238,20 @@ {% endmacro %} +{% macro sqlserver__server_major_version() -%} + {#- Detected engine major version: 13 = 2016, 14 = 2017, 15 = 2019, + 16 = 2022, 17 = 2025. parsename() on the always-4-part productversion + works on every supported release, unlike + SERVERPROPERTY('ProductMajorVersion') which is 2014+ only. Returns none + outside an executing context (e.g. parse time). -#} + {%- if not execute -%}{{ return(none) }}{%- endif -%} + {%- set result = run_query( + "select cast(parsename(cast(serverproperty('productversion') as varchar(128)), 4) as int) as major_version" + ) -%} + {{ return(result.columns[0].values()[0]) }} +{%- endmacro %} + + {% macro sqlserver__get_create_index_sql(relation, index_dict) -%} {%- set index_config = adapter.parse_index(index_dict) -%} {%- set index_name = index_config.render(relation) -%} @@ -274,6 +288,30 @@ {% if index_config.where -%} where {{ index_config.where }} {% endif %} + {#- optimize_for_sequential_key, RESUMABLE and RESUMABLE's MAX_DURATION are + CREATE INDEX options that SQL Server only recognizes on 2019 (major 15) + and newer. This adapter still supports 2017/2016, so on older engines + they are dropped (with a warning) and the index is built without them, + rather than failing with "is not a recognized CREATE INDEX option". + ONLINE is intentionally kept: it is recognized on 2017 (edition-gated, + not version-gated). The server version is only queried when one of these + options is actually requested, so the common path adds no round-trip. -#} + {%- set v2019_only_build_options = ['resumable', 'max_duration'] -%} + {%- set _build_options = index_config.build_options or {} -%} + {%- set _wants_v2019_option = index_config.optimize_for_sequential_key + or _build_options.get('resumable') or _build_options.get('max_duration') -%} + {%- set drop_v2019_options = false -%} + {%- if _wants_v2019_option -%} + {%- set _major = sqlserver__server_major_version() -%} + {%- if _major is not none and _major < 15 -%} + {%- set drop_v2019_options = true -%} + {%- do log( + "Index [" ~ index_name ~ "] on " ~ relation ~ ": optimize_for_sequential_key" + ~ " / resumable require SQL Server 2019 (15.x) or newer; building the index" + ~ " without them on detected major version " ~ _major ~ ".", info=true + ) -%} + {%- endif -%} + {%- endif -%} {%- set with_options = [] -%} {%- if index_config.data_compression -%} {%- do with_options.append('data_compression = ' ~ index_config.data_compression | upper) -%} @@ -287,14 +325,16 @@ {%- if index_config.ignore_dup_key -%} {%- do with_options.append('ignore_dup_key = on') -%} {%- endif -%} - {%- if index_config.optimize_for_sequential_key -%} + {%- if index_config.optimize_for_sequential_key and not drop_v2019_options -%} {%- do with_options.append('optimize_for_sequential_key = on') -%} {%- endif -%} {%- if index_config.sort_in_tempdb -%} {%- do with_options.append('sort_in_tempdb = on') -%} {%- endif -%} - {%- for option_key, option_value in (index_config.build_options or {}).items() -%} - {%- if option_value is sameas true -%} + {%- for option_key, option_value in _build_options.items() -%} + {%- if drop_v2019_options and option_key in v2019_only_build_options -%} + {#- skipped: not recognized before SQL Server 2019 -#} + {%- elif option_value is sameas true -%} {%- do with_options.append(option_key ~ ' = on') -%} {%- elif option_value is sameas false -%} {%- do with_options.append(option_key ~ ' = off') -%}