Skip to content

Conversation

@goldmedal
Copy link
Collaborator

@goldmedal goldmedal commented Aug 13, 2025

Summary by CodeRabbit

  • New Features

    • Added Microsoft SQL Server (MSSQL) support for dbt profile conversion, producing MSSQL data sources with sensible defaults (port, driver, TDS version, TrustServerCertificate).
    • Recognizes a "server" field and accepts textual port values when parsing dbt profiles.
    • Improved validation for MSSQL connection settings and adjusted host handling for containerized usage.
  • Tests

    • Added tests covering MSSQL profile conversion and default connection parameters.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 13, 2025

Walkthrough

Adds Microsoft SQL Server (sqlserver/MSSQL) support across DBT parsing, conversion, and tests: new WrenMSSQLDataSource type, conversion/mapping logic, profiles parsing for server and flexible port handling, container-aware host transformation, and a unit test verifying defaults and kwargs.

Changes

Cohort / File(s) Summary
MSSQL data source implementation
wren-launcher/commands/dbt/data_source.go
Introduces WrenMSSQLDataSource struct and methods (GetType, Validate, MapType); adds convertToMSSQLDataSource with defaults (port "1433", tds_version "8.0", Driver "ODBC Driver 18 for SQL Server", Kwargs with TrustServerCertificate: "YES"); expands SQL type constants and mapping; imports strconv.
DBT converter integration
wren-launcher/commands/dbt/converter.go
Adds branch handling WrenMSSQLDataSource in ConvertDbtProjectCore; applies handleLocalhostForContainer to host when opts.UsedByContainer is true; emits wren-datasource.json as before.
Profiles model update
wren-launcher/commands/dbt/profiles.go
Adds Server string field to DbtConnection with yaml:"server,omitempty" json:"server,omitempty".
Profiles parsing update
wren-launcher/commands/dbt/profiles_analyzer.go
Parses server into DbtConnection.Server; expands getInt to accept int, float64, int64, and string (uses strconv.Atoi); adds server to known fields to avoid capturing it as Additional.
Tests
wren-launcher/commands/dbt/data_source_test.go
Adds TestFromMssqlProfiles asserting conversion of a sqlserver profile yields a single WrenMSSQLDataSource with expected Host, Port "1433", Database, User, Password, TdsVersion "8.0", Driver and Kwargs["TrustServerCertificate"] == "YES".

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Dev as Developer (input)
  participant From as FromDbtProfiles
  participant Analyzer as ProfilesAnalyzer
  participant Converter
  participant WrenDS as WrenMSSQLDataSource
  participant Out as wren-datasource.json

  Dev->>From: provide dbt profiles (type: sqlserver)
  From->>Analyzer: parse connection map
  Analyzer-->>From: DbtConnection (Host, Server, Port, ...)
  From->>Converter: convertConnectionToDataSource(conn)
  Converter->>Converter: select "sqlserver" branch
  alt opts.UsedByContainer == true
    Converter->>WrenDS: host = handleLocalhostForContainer(conn.Server)
  else
    Converter->>WrenDS: host = conn.Server
  end
  Converter->>WrenDS: set port (default 1433), tds_version, driver, kwargs
  Converter->>Out: write wren-datasource.json
  Out-->>Dev: datasource file emitted
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • wwwy3y3
  • douenergy
  • onlyjackfrost

Poem

I hop through code with nimble paws,
I add a bridge with careful laws.
MSSQL joins the queue,
Ports and TDS set true.
A rabbit cheers — the pipeline claws. 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 48b7287 and 856ac3e.

📒 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 (1 hunks)
  • wren-launcher/commands/dbt/profiles.go (1 hunks)
  • wren-launcher/commands/dbt/profiles_analyzer.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • wren-launcher/commands/dbt/profiles.go
  • wren-launcher/commands/dbt/data_source_test.go
  • wren-launcher/commands/dbt/profiles_analyzer.go
  • wren-launcher/commands/dbt/converter.go
🧰 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/data_source.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/data_source.go
🧬 Code graph analysis (1)
wren-launcher/commands/dbt/data_source.go (1)
wren-launcher/commands/dbt/profiles.go (1)
  • DbtConnection (16-43)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: fmt-and-test
  • GitHub Check: lint
  • GitHub Check: Analyze (go)
🔇 Additional comments (4)
wren-launcher/commands/dbt/data_source.go (4)

14-29: Type constants addition looks good

Covers all types referenced by mappers; consistent naming.


91-92: Correct bridge: dbt "sqlserver" → Wren "mssql"

Matches dbt’s connection type while Wren GetType() returns "mssql" per convention.


129-133: Sane default for MSSQL port

Defaulting to 1433 when unset is correct.


313-337: Password requirement is correct; no alt-auth support present Validate() enforcing a non-empty Password is appropriate since the codebase contains no AAD/SSPI/access-token or other alternative authentication paths.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/dbt-mssql

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbit ignore or @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbit summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbit or @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 3

🧹 Nitpick comments (4)
wren-launcher/commands/dbt/profiles.go (1)

19-19: Add MSSQL server field: LGTM, consider clarifying precedence with Host.

The addition of Server aligns with dbt-sqlserver’s configuration. Downstream, ensure MSSQL uses Server but gracefully falls back to Host if Server is empty to handle misconfigured profiles. I'll propose the fallback change in convertToMSSQLDataSource.

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

196-261: MSSQL profile conversion test: solid coverage of defaults and field mapping.

This verifies Server→Host mapping, default MSSQL settings, and the shape of the data source. Consider adding:

  • Validation tests for MSSQL (e.g., non-numeric port, missing host, missing password).
  • Type mapping tests (e.g., tinyint, datetimeoffset) to pin behavior.

I can draft these tests if helpful.

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

142-161: MSSQL export: verify expected JSON contract for port and consider instance-name localhost handling.

  • The MSSQL port is emitted as a string, while Postgres emits an integer. If the consumer of wren-datasource.json differentiates these types, confirm the "mssql" port must be a string. If not mandated, consider normalizing the type to minimize schema drift.
  • For server values like "localhost\SQLEXPRESS" or "(local)", the simple equality check in handleLocalhostForContainer won’t rewrite localhost. Suggest enhancing it to handle instance suffixes and aliases.

If acceptable, update handleLocalhostForContainer to handle instance names:

func handleLocalhostForContainer(host string) string {
  base := host
  instance := ""
  if idx := strings.Index(host, `\`); idx != -1 {
    base = host[:idx]
    instance = host[idx:] // includes backslash
  }
  if base == "." || strings.EqualFold(base, "(local)") {
    base = "localhost"
  }
  if base == "localhost" || base == "127.0.0.1" {
    return "host.docker.internal" + instance
  }
  return host
}
wren-launcher/commands/dbt/data_source.go (1)

272-296: Validation inconsistency: MSSQL requires password, Postgres does not.

If Wren allows password-less connections (e.g., integrated auth, env-injected credentials), requiring Password here but not for Postgres is inconsistent and may block valid configurations. Decide one policy and apply consistently.

Options:

  • Allow empty Password for MSSQL (align with Postgres).
  • Require Password across both MSSQL and Postgres.

Do you want a follow-up patch either way?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a34ad63 and ccafac5.

📒 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 (1 hunks)
  • wren-launcher/commands/dbt/profiles.go (1 hunks)
  • wren-launcher/commands/dbt/profiles_analyzer.go (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 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/data_source_test.go (2)
wren-launcher/commands/dbt/profiles.go (3)
  • DbtProfiles (4-7)
  • DbtProfile (10-13)
  • DbtConnection (16-40)
wren-launcher/commands/dbt/data_source.go (2)
  • FromDbtProfiles (59-81)
  • WrenMSSQLDataSource (257-266)
wren-launcher/commands/dbt/converter.go (1)
wren-launcher/commands/dbt/data_source.go (1)
  • WrenMSSQLDataSource (257-266)
wren-launcher/commands/dbt/data_source.go (1)
wren-launcher/commands/dbt/profiles.go (1)
  • DbtConnection (16-40)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (3)
wren-launcher/commands/dbt/data_source.go (3)

6-6: Import strconv: LGTM.

Needed for port conversions in MSSQL paths.


14-29: Type constants: LGTM.

The expanded set covers MSSQL mappings well and improves consistency across MapType implementations.


90-92: Add 'sqlserver' support in converter: aligns with prior preference to skip unsupported types.

The new case integrates cleanly. The default branch continues to warn and skip unsupported types, matching the user preference noted in prior learnings.

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: 1

♻️ Duplicate comments (2)
wren-launcher/commands/dbt/data_source.go (2)

118-141: MSSQL DS construction: sensible defaults + host fallback (good).
Defaulting port to 1433, TDS 8.0, the ODBC 18 driver, and TrustServerCertificate are pragmatic. The host fallback to conn.Host when Server is empty addresses earlier feedback.

Please verify that downstream consumers expect TrustServerCertificate to be a string ("YES"/"NO") rather than a boolean. Run:

#!/bin/bash
set -e
echo "Search TrustServerCertificate usage and Kwargs consumption:"
rg -nI 'TrustServerCertificate' -A 3
rg -nI 'Kwargs' -A 5 | sed -n '1,200p'
echo
echo "Search for WrenMSSQLDataSource consumer code paths:"
rg -nI 'WrenMSSQLDataSource' -A 20

303-339: Correct MSSQL type mappings: tinyint is numeric; time is time-of-day.

  • tinyint (0–255) should not map to boolean.
  • time should not map to interval; fall back to the original type until a dedicated mapping exists.

Apply this diff:

 func (ds *WrenMSSQLDataSource) MapType(sourceType string) string {
   // This method is not used in WrenMSSQLDataSource, but required by DataSource interface
   switch strings.ToLower(sourceType) {
@@
-  case "bit", "tinyint":
-    return booleanType
+  case "bit":
+    return booleanType
+  case "tinyint":
+    return smallintType
@@
-  case "time":
-    return intervalType
+  case "time":
+    // No dedicated Wren type for time-of-day; keep original
+    return strings.ToLower(sourceType)
   case "datetimeoffset":
     return timestamptzType
   case "json":
     return jsonType
   default:
     return strings.ToLower(sourceType)
   }
 }

I can add/extend unit tests to cover:

  • MapType("tinyint") -> smallintType
  • MapType("time") -> "time"
  • Host fallback when Server is empty
    Would you like me to draft those tests?
🧹 Nitpick comments (2)
wren-launcher/commands/dbt/data_source.go (2)

90-91: Also accept “mssql” alias in addition to “sqlserver”.
Some profiles/plugins use “mssql”. Recognizing both improves resilience without behavior change.

Apply this diff:

-  case "sqlserver":
+  case "sqlserver", "mssql":
     return convertToMSSQLDataSource(conn)

277-301: Validation is solid; minor hardening: trim whitespace.
Guard against accidental whitespace-only values without mutating state.

Apply this diff:

 func (ds *WrenMSSQLDataSource) Validate() error {
-  if ds.Host == "" {
+  if strings.TrimSpace(ds.Host) == "" {
     return fmt.Errorf("host cannot be empty")
   }
-  if ds.Database == "" {
+  if strings.TrimSpace(ds.Database) == "" {
     return fmt.Errorf("database cannot be empty")
   }
-  if ds.User == "" {
+  if strings.TrimSpace(ds.User) == "" {
     return fmt.Errorf("user cannot be empty")
   }
-  if ds.Port == "" {
+  if strings.TrimSpace(ds.Port) == "" {
     return fmt.Errorf("port must be specified")
   }
   port, err := strconv.Atoi(ds.Port)
@@
-  if ds.Password == "" {
+  if strings.TrimSpace(ds.Password) == "" {
     return fmt.Errorf("password cannot be empty")
   }
   return nil
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ccafac5 and 48b7287.

📒 Files selected for processing (2)
  • wren-launcher/commands/dbt/data_source.go (4 hunks)
  • wren-launcher/commands/dbt/profiles_analyzer.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • wren-launcher/commands/dbt/profiles_analyzer.go
🧰 Additional context used
🧠 Learnings (2)
📚 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/data_source.go
📚 Learning: 2025-07-09T02:43:07.560Z
Learnt from: goldmedal
PR: Canner/WrenAI#1827
File: wren-launcher/commands/dbt/data_source.go:154-156
Timestamp: 2025-07-09T02:43:07.560Z
Learning: In the WrenAI codebase, the MapType methods for data sources should return the original type name for unknown types, rather than a default fallback like "string". This maintains consistency across all data source implementations.

Applied to files:

  • wren-launcher/commands/dbt/data_source.go
🧬 Code Graph Analysis (1)
wren-launcher/commands/dbt/data_source.go (1)
wren-launcher/commands/dbt/profiles.go (1)
  • DbtConnection (16-40)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: fmt-and-test
  • GitHub Check: lint
  • GitHub Check: Analyze (go)
🔇 Additional comments (3)
wren-launcher/commands/dbt/data_source.go (3)

6-6: Import of strconv is appropriate for port handling.
Used for Port string conversion and validation; no issues spotted.


14-28: Type constants look consistent and broadly useful.
Centralized constants align with existing mappings and support MSSQL additions.


262-271: WrenMSSQLDataSource struct looks correct.
JSON field names and types match construction and validation; no structural issues noted.

@goldmedal goldmedal requested a review from wwwy3y3 August 14, 2025 02:16
@goldmedal goldmedal merged commit 02bb00b into main Sep 22, 2025
13 checks passed
@goldmedal goldmedal deleted the chore/dbt-mssql branch September 22, 2025 02:47
goldmedal added a commit that referenced this pull request Sep 22, 2025
@goldmedal goldmedal restored the chore/dbt-mssql branch September 22, 2025 02:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants