Repository: fal-ai/dbt-fal

Issue:
Support sqlserver
Add support for MS sqlserver


Discussion:

Resolving patch:
diff --git a/projects/adapter/src/dbt/adapters/fal_experimental/adapter_support.py b/projects/adapter/src/dbt/adapters/fal_experimental/adapter_support.py
--- a/projects/adapter/src/dbt/adapters/fal_experimental/adapter_support.py
+++ b/projects/adapter/src/dbt/adapters/fal_experimental/adapter_support.py
@@ -14,6 +14,7 @@
 
 _SQLALCHEMY_DIALECTS = {
     "redshift": "redshift+psycopg2",
+    "sqlserver": "mssql+pyodbc",
 }
 
 
@@ -35,6 +36,10 @@ def _get_alchemy_engine(adapter: BaseAdapter, connection: Connection) -> Any:
         sqlalchemy_kwargs["creator"] = lambda *args, **kwargs: connection.handle
         url = _SQLALCHEMY_DIALECTS.get(adapter_type, adapter_type) + "://"
         url = format_url(url)
+    elif adapter_type == "sqlserver":
+        sqlalchemy_kwargs["creator"] = lambda *args, **kwargs: connection.handle
+        url = _SQLALCHEMY_DIALECTS.get(adapter_type, adapter_type) + "://"
+        url = format_url(url)
     else:
         message = (
             f"dbt-fal does not support {adapter_type} adapter. ",


Test patch:
diff --git a/.github/workflows/test_integration_adapter.yml b/.github/workflows/test_integration_adapter.yml
--- a/.github/workflows/test_integration_adapter.yml
+++ b/.github/workflows/test_integration_adapter.yml
@@ -32,6 +32,7 @@ jobs:
           - snowflake
           - redshift
           - trino
+          # - sqlserver # does not support dbt 1.4 yet
         dbt_version:
           - "1.4.*"
         python:
@@ -68,6 +69,22 @@ jobs:
         if: contains(fromJSON('["trino"]'), matrix.profile)
         run: docker-compose up -d
 
+      - name: Setup sqlserver dependencies
+        if: contains(fromJSON('["sqlserver"]'), matrix.profile)
+        run: |
+          sudo apt install unixodbc-dev
+          sudo curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
+          curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list > prod.list
+          sudo cp prod.list /etc/apt/sources.list.d/mssql-release.list
+          sudo apt update
+          sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18
+
+      - name: Start sqlserver
+        working-directory: fal/projects/adapter/integration_tests/configs/sqlserver
+        if: contains(fromJSON('["sqlserver"]'), matrix.profile)
+        run: |
+          docker-compose up -d
+
       - name: Setup latest dependencies
         working-directory: fal/projects/adapter/integration_tests
         run: |
diff --git a/projects/adapter/integration_tests/configs/sqlserver/docker-compose.yml b/projects/adapter/integration_tests/configs/sqlserver/docker-compose.yml
new file mode 100644
--- /dev/null
+++ b/projects/adapter/integration_tests/configs/sqlserver/docker-compose.yml
@@ -0,0 +1,11 @@
+version: '3.9'
+
+services:
+  sqlserver:
+    image: mcr.microsoft.com/mssql/server:2022-latest
+    container_name: fal_sql_server
+    environment:
+      ACCEPT_EULA: Y
+      MSSQL_SA_PASSWORD: strongPassword1@
+    ports:
+      - 1433:1433
diff --git a/projects/adapter/integration_tests/features/steps/fal_adapter_steps.py b/projects/adapter/integration_tests/features/steps/fal_adapter_steps.py
--- a/projects/adapter/integration_tests/features/steps/fal_adapter_steps.py
+++ b/projects/adapter/integration_tests/features/steps/fal_adapter_steps.py
@@ -140,6 +140,7 @@ def _get_profile(context) -> str:
         "duckdb",
         "athena",
         "trino",
+        "sqlserver"
     ]
     profile = context.config.userdata.get("profile", "postgres")
     if profile not in available_profiles:
diff --git a/projects/adapter/integration_tests/profiles/sqlserver/profiles.yml b/projects/adapter/integration_tests/profiles/sqlserver/profiles.yml
new file mode 100644
--- /dev/null
+++ b/projects/adapter/integration_tests/profiles/sqlserver/profiles.yml
@@ -0,0 +1,25 @@
+config:
+  send_anonymous_usage_stats: False
+
+fal_test:
+  target: staging
+  outputs:
+    staging:
+      type: fal
+      db_profile: db
+    prod:
+      type: fal
+      db_profile: db
+      host: "{{ env_var('FAL_HOST') }}"
+      key_secret: "{{ env_var('FAL_KEY_SECRET') }}"
+      key_id: "{{ env_var('FAL_KEY_ID') }}"
+    db:
+      type: sqlserver
+      driver: 'ODBC Driver 18 for SQL Server'
+      server: localhost
+      port: 1433
+      database: tempdb
+      schema: dbo
+      user: sa
+      password: strongPassword1@
+      trust_cert: true