Skip to content

Conversation

@goldmedal
Copy link
Collaborator

@goldmedal goldmedal commented Sep 22, 2025

Summary by CodeRabbit

  • New Features

    • Added end-to-end support for Microsoft SQL Server (MSSQL) data sources in dbt profile conversion.
    • Recognizes “sqlserver” profiles and maps MSSQL-specific settings (server/host, port, database, user, password, TDS version, driver, and additional options).
    • Container-aware host handling improves reliability when running inside containers.
    • Enhanced profile parsing to accept the “server” field and more flexible numeric port values.
  • Tests

    • Added comprehensive tests for MSSQL profile conversion and validation, including kwargs and TDS handling.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 22, 2025

Walkthrough

Adds MSSQL support to the dbt conversion pipeline: new WrenMSSQLDataSource type with validation and type mapping, profiles model adds Server field, profiles analyzer parses server and improves port parsing, converter emits mssql WrenDataSource (container-aware host handling), and tests validate MSSQL profile conversion.

Changes

Cohort / File(s) Summary of Changes
MSSQL data source implementation
wren-launcher/commands/dbt/data_source.go
Introduces WrenMSSQLDataSource (fields: database, host, port, user, password, tds_version, driver, kwargs); implements GetType(), Validate(), MapType(); adds convertToMSSQLDataSource and routes "sqlserver" in convertConnectionToDataSource.
Converter integration
wren-launcher/commands/dbt/converter.go
Adds MSSQL handling in ConvertDbtProjectCore; builds WrenDataSource JSON with type "mssql" and properties; applies handleLocalhostForContainer when UsedByContainer is true.
Profiles model support
wren-launcher/commands/dbt/profiles.go
Adds Server string field (yaml/json tags) to DbtConnection for MSSQL.
Profiles analyzer parsing
wren-launcher/commands/dbt/profiles_analyzer.go
Parses "server" into DbtConnection.Server; expands port parsing (int64/string via strconv.Atoi); includes "server" in known fields.
Tests
wren-launcher/commands/dbt/data_source_test.go
Adds TestFromMssqlProfiles covering MSSQL fields and kwargs; introduces Validator interface (Validate() error) for tests; adds validation test helper (duplicated definition in diff).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as Caller
  participant PA as ProfilesAnalyzer
  participant DS as DataSource Converter
  participant C as Converter
  participant O as Output

  U->>PA: Provide dbt profiles (includes server/host, port, etc.)
  PA->>PA: Parse connection (server/host, port parsing)
  PA-->>DS: DbtConnection (type=sqlserver, fields)
  DS->>DS: convertToMSSQLDataSource()
  DS-->>C: WrenMSSQLDataSource
  C->>C: Build WrenDataSource JSON (type="mssql")
  alt Used by container
    C->>C: handleLocalhostForContainer(host)
  end
  C-->>O: WrenDataSource {host, port, database, user, password, tds_version, driver, kwargs}

  note over DS,C: New MSSQL path and properties population
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

launcher

Suggested reviewers

  • wwwy3y3
  • douenergy

Poem

I twitch my ears at ports that sing,
From server burrows, packets spring.
MSSQL carrots neatly lined,
TDS trails, securely signed.
Containers hop—hosts rearranged—
A warren mapped, connections changed.
Thump! The schema’s now aligned. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "feat(wren-launcher) support MSSQL data source for dbt-tools" clearly and concisely summarizes the primary change (adding MSSQL data source support to the wren-launcher dbt flow), follows conventional commit style, and matches the file-level changes in the diff such as new WrenMSSQLDataSource, profiles handling, and converter updates. It is specific, directly related to the changeset, and readable for teammates scanning history.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@goldmedal goldmedal requested a review from douenergy September 22, 2025 07:11
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (5)
wren-launcher/commands/dbt/profiles_analyzer.go (1)

109-114: Port parsing: handles int64 and numeric strings

Nice robustness improvement. Consider trimming whitespace before Atoi to tolerate " 1433 ".

Example:

s := strings.TrimSpace(v)
if i, err := strconv.Atoi(s); err == nil { return i }
wren-launcher/commands/dbt/data_source_test.go (2)

223-288: Add a validation assertion to the MSSQL test

Test covers fields well. Also assert Validate passes to catch future regressions.

   if ds.Kwargs["TrustServerCertificate"] != "YES" {
     t.Errorf("Expected TrustServerCertificate 'YES', got '%s'", ds.Kwargs["TrustServerCertificate"])
   }
+  if err := ds.Validate(); err != nil {
+    t.Errorf("Validation failed: %v", err)
+  }
 }

830-857: Deduplicate test utilities

Validator and testDataSourceValidation are useful; consider moving to a shared test helper (e.g., data_source_test_helpers.go) to reuse across tests.

wren-launcher/commands/dbt/converter.go (1)

157-176: MSSQL JSON emission looks right; consider parity with MySQL for container host mapping

Host remapping for containers mirrors Postgres. Apply the same pattern to MySQL for consistency when UsedByContainer = true.

wren-launcher/commands/dbt/data_source.go (1)

410-434: Password requirement may be too strict

Other sources don’t require password in Validate. If integrated/AD auth is later supported, failing on empty password will block valid configs. Consider warning at connect-time or gating by auth mode instead of hard fail here.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5b312ff and 5a2985a.

📒 Files selected for processing (5)
  • wren-launcher/commands/dbt/converter.go (1 hunks)
  • wren-launcher/commands/dbt/data_source.go (4 hunks)
  • wren-launcher/commands/dbt/data_source_test.go (2 hunks)
  • wren-launcher/commands/dbt/profiles.go (1 hunks)
  • wren-launcher/commands/dbt/profiles_analyzer.go (3 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: goldmedal
PR: Canner/WrenAI#1887
File: wren-launcher/commands/dbt/data_source.go:273-276
Timestamp: 2025-08-13T05:17:30.180Z
Learning: In the Wren AI codebase, there's an intentional distinction between dbt connection types and Wren AI data source types: dbt uses "sqlserver" as the connection type, while Wren AI expects "mssql" as the data source type. The conversion layer in convertConnectionToDataSource() correctly matches "sqlserver" from dbt profiles and the WrenMSSQLDataSource.GetType() method correctly returns "mssql" for Wren AI compatibility.
📚 Learning: 2025-08-13T05:17:30.180Z
Learnt from: goldmedal
PR: Canner/WrenAI#1887
File: wren-launcher/commands/dbt/data_source.go:273-276
Timestamp: 2025-08-13T05:17:30.180Z
Learning: In the Wren AI codebase, there's an intentional distinction between dbt connection types and Wren AI data source types: dbt uses "sqlserver" as the connection type, while Wren AI expects "mssql" as the data source type. The conversion layer in convertConnectionToDataSource() correctly matches "sqlserver" from dbt profiles and the WrenMSSQLDataSource.GetType() method correctly returns "mssql" for Wren AI compatibility.

Applied to files:

  • wren-launcher/commands/dbt/profiles.go
  • wren-launcher/commands/dbt/converter.go
  • wren-launcher/commands/dbt/data_source.go
  • wren-launcher/commands/dbt/data_source_test.go
📚 Learning: 2025-07-09T02:43:20.433Z
Learnt from: goldmedal
PR: Canner/WrenAI#1827
File: wren-launcher/commands/dbt/data_source.go:50-53
Timestamp: 2025-07-09T02:43:20.433Z
Learning: In wren-launcher/commands/dbt/data_source.go, when encountering unsupported database types in convertConnectionToDataSource function, the user prefers to log a warning and continue processing instead of failing. The function should return nil, nil to allow processing to continue.

Applied to files:

  • wren-launcher/commands/dbt/converter.go
  • wren-launcher/commands/dbt/data_source.go
🧬 Code graph analysis (3)
wren-launcher/commands/dbt/converter.go (1)
wren-launcher/commands/dbt/data_source.go (1)
  • WrenMSSQLDataSource (395-404)
wren-launcher/commands/dbt/data_source.go (1)
wren-launcher/commands/dbt/profiles.go (1)
  • DbtConnection (16-44)
wren-launcher/commands/dbt/data_source_test.go (2)
wren-launcher/commands/dbt/profiles.go (3)
  • DbtProfiles (4-7)
  • DbtProfile (10-13)
  • DbtConnection (16-44)
wren-launcher/commands/dbt/data_source.go (2)
  • FromDbtProfiles (63-85)
  • WrenMSSQLDataSource (395-404)
🔇 Additional comments (7)
wren-launcher/commands/dbt/profiles.go (1)

19-19: MSSQL: clarify server vs host precedence and fallback

Good addition. Please document and enforce precedence (prefer Server for MSSQL, else fall back to Host). This avoids empty host when users put only host. See converter change below for host fallback.

wren-launcher/commands/dbt/profiles_analyzer.go (3)

8-8: Import of strconv is appropriate

Needed for flexible numeric parsing. LGTM.


153-153: Server extraction for MSSQL

Populating DbtConnection.Server is correct and aligns with dbt-sqlserver profiles.


160-160: Keep server in knownFields

Prevents leakage into Additional. LGTM.

wren-launcher/commands/dbt/data_source.go (3)

17-33: Type constants

Useful consolidation for mappings. LGTM.


94-96: Recognize dbt 'sqlserver' and route to MSSQL

Matches our convention (dbt: sqlserver → Wren: mssql). Good.


395-404: MSSQL data source shape

Fields align with converter output; Kwargs allows extensibility. LGTM.

@douenergy douenergy merged commit 7423967 into Canner:main Sep 22, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants