relspecgo

package module
v1.0.44 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

README

RelSpec

Release CI Integration Tests Go Version License

Bidirectional database schema conversion, validation, and templating tool.

RelSpec

Install

go install -v git.warky.dev/wdevs/relspecgo/cmd/relspec@latest

Supported Formats

Direction Formats
Readers bun dbml dctx drawdb drizzle gorm graphql json mssql pgsql prisma sqldir sqlite typeorm yaml
Writers bun dbml dctx drawdb drizzle gorm graphql json mssql pgsql prisma sqlexec sqlite template typeorm yaml

Commands

convert — Schema conversion
# PostgreSQL → GORM models
relspec convert --from pgsql --from-conn "postgres://user:pass@localhost/mydb" \
                --to gorm --to-path models/ --package models

# DBML → PostgreSQL DDL
relspec convert --from dbml --from-path schema.dbml --to pgsql --to-path schema.sql

# PostgreSQL → SQLite (auto flattens schemas)
relspec convert --from pgsql --from-conn "postgres://..." --to sqlite --to-path schema.sql

# Multiple input files merged
relspec convert --from json --from-list "a.json,b.json" --to yaml --to-path merged.yaml
merge — Additive schema merge (never modifies existing items)
# Merge two JSON schemas
relspec merge --target json --target-path base.json \
              --source json --source-path additions.json \
              --output json --output-path merged.json

# Merge PostgreSQL into JSON, skipping tables
relspec merge --target json --target-path current.json \
              --source pgsql --source-conn "postgres://user:pass@localhost/db" \
              --output json --output-path updated.json \
              --skip-tables "audit_log,temp_tables"

Skip flags: --skip-relations --skip-views --skip-domains --skip-enums --skip-sequences

inspect — Schema validation / linting
# Validate PostgreSQL database
relspec inspect --from pgsql --from-conn "postgres://user:pass@localhost/mydb"

# Validate DBML with custom rules
relspec inspect --from dbml --from-path schema.dbml --rules .relspec-rules.yaml

# JSON report output
relspec inspect --from json --from-path db.json --output-format json --output report.json

# Filter to specific schema
relspec inspect --from pgsql --from-conn "..." --schema public

Rules: naming conventions, PK/FK standards, missing indexes, reserved keywords, circular dependencies.

diff — Schema comparison
relspec diff --from pgsql --from-conn "postgres://localhost/db1" \
             --to pgsql --to-conn "postgres://localhost/db2"
templ — Custom template rendering
# Render database schema to Markdown docs
relspec templ --from pgsql --from-conn "postgres://user:pass@localhost/db" \
              --template docs.tmpl --output schema-docs.md

# One TypeScript file per table
relspec templ --from dbml --from-path schema.dbml \
              --template ts-model.tmpl --mode table \
              --output ./models/ --filename-pattern "{{.Name | toCamelCase}}.ts"

Modes: database (default) · schema · table · script

Template functions: string utils (toCamelCase, toSnakeCase, pluralize, …), type converters (sqlToGo, sqlToTypeScript, …), filters, loop helpers, safe access.

edit — Interactive TUI editor
# Edit DBML schema interactively
relspec edit --from dbml --from-path schema.dbml --to dbml --to-path schema.dbml

# Edit live PostgreSQL database
relspec edit --from pgsql --from-conn "postgres://user:pass@localhost/mydb" \
             --to pgsql --to-conn "postgres://user:pass@localhost/mydb"

Development

Prerequisites: Go 1.24.0+

make build     # → build/relspec
make test      # race detection + coverage
make lint      # requires golangci-lint
make coverage  # → coverage.html
make install   # → $GOPATH/bin

Project Structure

cmd/relspec/          CLI commands
pkg/readers/          Input format readers
pkg/writers/          Output format writers
pkg/inspector/        Schema validation
pkg/diff/             Schema comparison
pkg/merge/            Schema merging
pkg/models/           Internal data models
pkg/transform/        Transformation logic
pkg/pgsql/            PostgreSQL utilities

Contributing

  1. Register or sign in with GitHub at git.warky.dev
  2. Clone the repository: git clone https://git.warky.dev/wdevs/relspecgo.git
  3. Create a feature branch: git checkout -b feature/your-feature-name
  4. Commit your changes and push the branch
  5. Open a pull request with a description of the new feature or fix

For questions or discussion, join the Discord: discord.gg/74rcTujp25warkyhein

Documentation

Overview

Package relspecgo provides bidirectional conversion between database schema formats.

RelSpec is a comprehensive database schema tool that reads, writes, and transforms database schemas across multiple formats including live databases, ORM models, schema definition languages, and data interchange formats.

Features

  • Read from 15+ formats: PostgreSQL, SQLite, DBML, GORM, Prisma, Drizzle, and more
  • Write to 15+ formats: SQL, ORM models, schema definitions, JSON/YAML
  • Interactive TUI editor for visual schema management
  • Schema diff and merge capabilities
  • Format-agnostic intermediate representation

Architecture

RelSpec uses a hub-and-spoke architecture with models.Database as the central type:

Input Format → Reader → models.Database → Writer → Output Format

This allows any supported input format to be converted to any supported output format without requiring N² conversion implementations.

Key Packages

  • pkg/models: Core data structures (Database, Schema, Table, Column, etc.)
  • pkg/readers: Input format readers (dbml, pgsql, gorm, etc.)
  • pkg/writers: Output format writers (dbml, pgsql, gorm, etc.)
  • pkg/ui: Interactive terminal UI for schema editing
  • pkg/diff: Schema comparison and difference detection
  • pkg/merge: Schema merging utilities
  • pkg/transform: Validation and normalization

Installation

go install git.warky.dev/wdevs/relspecgo/cmd/relspec@latest

Usage

Command-line conversion:

relspec convert --from dbml --from-path schema.dbml \
                --to gorm --to-path ./models

Interactive editor:

relspec edit --from pgsql --from-conn "postgres://..." \
             --to dbml --to-path schema.dbml

Schema comparison:

relspec diff --source-type pgsql --source-conn "postgres://..." \
             --target-type dbml --target-path schema.dbml

Merge schemas:

relspec merge --target schema1.dbml --sources schema2.dbml,schema3.dbml

Supported Formats

Input/Output Formats:

  • dbml: Database Markup Language
  • dctx: DCTX schema files
  • drawdb: DrawDB JSON format
  • graphql: GraphQL schema definition
  • json: JSON schema representation
  • yaml: YAML schema representation
  • gorm: Go GORM models
  • bun: Go Bun models
  • drizzle: TypeScript Drizzle ORM
  • prisma: Prisma schema language
  • typeorm: TypeScript TypeORM entities
  • pgsql: PostgreSQL (live DB or SQL)
  • sqlite: SQLite (database file or SQL)

Library Usage

RelSpec can be used as a Go library:

import (
    "git.warky.dev/wdevs/relspecgo/pkg/models"
    "git.warky.dev/wdevs/relspecgo/pkg/readers/dbml"
    "git.warky.dev/wdevs/relspecgo/pkg/writers/gorm"
)

// Read DBML
reader := dbml.NewReader(&readers.ReaderOptions{
    FilePath: "schema.dbml",
})
db, err := reader.ReadDatabase()

// Write GORM models
writer := gorm.NewWriter(&writers.WriterOptions{
    OutputPath:  "./models",
    PackageName: "models",
})
err = writer.WriteDatabase(db)

Documentation

Full documentation available at: https://git.warky.dev/wdevs/relspecgo

API documentation: go doc git.warky.dev/wdevs/relspecgo/...

License

See LICENSE file in the repository root.

Directories

Path Synopsis
cmd
relspec command
bun
pkg
commontypes
Package commontypes provides shared type definitions used across multiple packages.
Package commontypes provides shared type definitions used across multiple packages.
diff
Package diff provides utilities for comparing database schemas and identifying differences.
Package diff provides utilities for comparing database schemas and identifying differences.
inspector
Package inspector provides database introspection capabilities for live databases.
Package inspector provides database introspection capabilities for live databases.
merge
Package merge provides utilities for merging database schemas.
Package merge provides utilities for merging database schemas.
models
Package models provides the core data structures for representing database schemas.
Package models provides the core data structures for representing database schemas.
pgsql
Package pgsql provides PostgreSQL-specific utilities and helpers.
Package pgsql provides PostgreSQL-specific utilities and helpers.
readers
Package readers provides interfaces and implementations for reading database schemas from various input formats and data sources.
Package readers provides interfaces and implementations for reading database schemas from various input formats and data sources.
reflectutil
Package reflectutil provides reflection utilities for analyzing Go code structures.
Package reflectutil provides reflection utilities for analyzing Go code structures.
transform
Package transform provides validation and transformation utilities for database models.
Package transform provides validation and transformation utilities for database models.
ui
Package ui provides an interactive terminal user interface (TUI) for editing database schemas.
Package ui provides an interactive terminal user interface (TUI) for editing database schemas.
writers
Package writers provides interfaces and implementations for writing database schemas to various output formats and destinations.
Package writers provides interfaces and implementations for writing database schemas to various output formats and destinations.
tests

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL