Files
Hein 466d657ea7
All checks were successful
CI / Test (1.24) (push) Successful in -23m27s
CI / Test (1.25) (push) Successful in -23m4s
CI / Lint (push) Successful in -24m57s
CI / Build (push) Successful in -25m15s
Integration Tests / Integration Tests (push) Successful in -25m42s
feat(mssql): add MSSQL writer for generating DDL from database schema
- Implement MSSQL writer to generate SQL scripts for creating schemas, tables, and constraints.
- Support for identity columns, indexes, and extended properties.
- Add tests for column definitions, table creation, primary keys, foreign keys, and comments.
- Include testing guide and sample schema for integration tests.
2026-02-07 16:09:27 +02:00
..

MSSQL Reader

Reads database schema from Microsoft SQL Server databases using a live connection.

Features

  • Live Connection: Connects to MSSQL databases using the Microsoft ODBC driver
  • Multi-Schema Support: Reads multiple schemas with full support for user-defined schemas
  • Comprehensive Metadata: Reads tables, columns, constraints, indexes, and extended properties
  • Type Mapping: Converts MSSQL types to canonical types for cross-database compatibility
  • Extended Properties: Extracts table and column descriptions from MS_Description
  • Identity Columns: Maps IDENTITY columns to AutoIncrement
  • Relationships: Derives relationships from foreign key constraints

Connection String Format

sqlserver://[user[:password]@][host][:port][?query]

Examples:

sqlserver://sa:password@localhost/dbname
sqlserver://user:pass@192.168.1.100:1433/production
sqlserver://localhost/testdb?encrypt=disable

Supported Constraints

  • Primary Keys
  • Foreign Keys (with ON DELETE and ON UPDATE actions)
  • Unique Constraints
  • Check Constraints

Type Mappings

MSSQL Type Canonical Type
INT int
BIGINT int64
SMALLINT int16
TINYINT int8
BIT bool
REAL float32
FLOAT float64
NUMERIC, DECIMAL decimal
NVARCHAR, VARCHAR string
DATETIME2 timestamp
DATETIMEOFFSET timestamptz
UNIQUEIDENTIFIER uuid
VARBINARY bytea
DATE date
TIME time

Usage

import "git.warky.dev/wdevs/relspecgo/pkg/readers/mssql"
import "git.warky.dev/wdevs/relspecgo/pkg/readers"

reader := mssql.NewReader(&readers.ReaderOptions{
    ConnectionString: "sqlserver://sa:password@localhost/mydb",
})

db, err := reader.ReadDatabase()
if err != nil {
    panic(err)
}

// Process schema...
for _, schema := range db.Schemas {
    fmt.Printf("Schema: %s\n", schema.Name)
    for _, table := range schema.Tables {
        fmt.Printf("  Table: %s\n", table.Name)
    }
}

Testing

Run tests with:

go test ./pkg/readers/mssql/...

For integration testing with a live MSSQL database:

docker-compose up -d mssql
go test -tags=integration ./pkg/readers/mssql/...
docker-compose down