docs: 📝 Update documentation
This commit is contained in:
320
README.md
320
README.md
@@ -6,264 +6,160 @@
|
|||||||
[](https://go.dev/dl/)
|
[](https://go.dev/dl/)
|
||||||
[](LICENSE)
|
[](LICENSE)
|
||||||
|
|
||||||
> Database Relations Specification Tool for Go
|
> Bidirectional database schema conversion, validation, and templating tool.
|
||||||
|
|
||||||
RelSpec is a comprehensive database relations management tool that reads, transforms, and writes database table specifications across multiple formats and ORMs.
|

|
||||||
|
|
||||||
## Overview
|
## Install
|
||||||
|
|
||||||
RelSpec provides bidirectional conversion, comparison, and validation of database specification formats, allowing you to:
|
|
||||||
- Inspect live databases and extract their structure
|
|
||||||
- Validate schemas against configurable rules and naming conventions
|
|
||||||
- Convert between different ORM models (GORM, Bun, etc.)
|
|
||||||
- Transform legacy schema definitions (Clarion DCTX, XML, JSON, etc.)
|
|
||||||
- Generate standardized specification files (JSON, YAML, etc.)
|
|
||||||
- Compare database schemas and track changes
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
### Readers (Input Formats)
|
|
||||||
|
|
||||||
RelSpec can read database schemas from multiple sources:
|
|
||||||
|
|
||||||
#### ORM Models
|
|
||||||
- [GORM](pkg/readers/gorm/README.md) - Go GORM model definitions
|
|
||||||
- [Bun](pkg/readers/bun/README.md) - Go Bun model definitions
|
|
||||||
- [Drizzle](pkg/readers/drizzle/README.md) - TypeScript Drizzle ORM schemas
|
|
||||||
- [Prisma](pkg/readers/prisma/README.md) - Prisma schema language
|
|
||||||
- [TypeORM](pkg/readers/typeorm/README.md) - TypeScript TypeORM entities
|
|
||||||
|
|
||||||
#### Database Inspection
|
|
||||||
- [PostgreSQL](pkg/readers/pgsql/README.md) - Direct PostgreSQL database introspection
|
|
||||||
- [SQLite](pkg/readers/sqlite/README.md) - Direct SQLite database introspection
|
|
||||||
|
|
||||||
#### Schema Formats
|
|
||||||
- [DBML](pkg/readers/dbml/README.md) - Database Markup Language (dbdiagram.io)
|
|
||||||
- [DCTX](pkg/readers/dctx/README.md) - Clarion database dictionary format
|
|
||||||
- [DrawDB](pkg/readers/drawdb/README.md) - DrawDB JSON format
|
|
||||||
- [GraphQL](pkg/readers/graphql/README.md) - GraphQL Schema Definition Language (SDL)
|
|
||||||
- [JSON](pkg/readers/json/README.md) - RelSpec canonical JSON format
|
|
||||||
- [YAML](pkg/readers/yaml/README.md) - RelSpec canonical YAML format
|
|
||||||
|
|
||||||
### Writers (Output Formats)
|
|
||||||
|
|
||||||
RelSpec can write database schemas to multiple formats:
|
|
||||||
|
|
||||||
#### ORM Models
|
|
||||||
- [GORM](pkg/writers/gorm/README.md) - Generate GORM-compatible Go structs
|
|
||||||
- [Bun](pkg/writers/bun/README.md) - Generate Bun-compatible Go structs
|
|
||||||
- [Drizzle](pkg/writers/drizzle/README.md) - Generate Drizzle ORM TypeScript schemas
|
|
||||||
- [Prisma](pkg/writers/prisma/README.md) - Generate Prisma schema files
|
|
||||||
- [TypeORM](pkg/writers/typeorm/README.md) - Generate TypeORM TypeScript entities
|
|
||||||
|
|
||||||
#### Database DDL
|
|
||||||
- [PostgreSQL](pkg/writers/pgsql/README.md) - PostgreSQL DDL (CREATE TABLE, etc.)
|
|
||||||
- [SQLite](pkg/writers/sqlite/README.md) - SQLite DDL with automatic schema flattening
|
|
||||||
|
|
||||||
#### Schema Formats
|
|
||||||
- [DBML](pkg/writers/dbml/README.md) - Database Markup Language
|
|
||||||
- [DCTX](pkg/writers/dctx/README.md) - Clarion database dictionary format
|
|
||||||
- [DrawDB](pkg/writers/drawdb/README.md) - DrawDB JSON format
|
|
||||||
- [GraphQL](pkg/writers/graphql/README.md) - GraphQL Schema Definition Language (SDL)
|
|
||||||
- [JSON](pkg/writers/json/README.md) - RelSpec canonical JSON format
|
|
||||||
- [YAML](pkg/writers/yaml/README.md) - RelSpec canonical YAML format
|
|
||||||
|
|
||||||
### Inspector (Schema Validation)
|
|
||||||
|
|
||||||
RelSpec includes a powerful schema validation and linting tool:
|
|
||||||
|
|
||||||
- [Inspector](pkg/inspector/README.md) - Validate database schemas against configurable rules
|
|
||||||
- Enforce naming conventions (snake_case, camelCase, custom patterns)
|
|
||||||
- Check primary key and foreign key standards
|
|
||||||
- Detect missing indexes on foreign keys
|
|
||||||
- Prevent use of SQL reserved keywords
|
|
||||||
- Ensure schema integrity (missing PKs, orphaned FKs, circular dependencies)
|
|
||||||
- Support for custom validation rules
|
|
||||||
- Multiple output formats (Markdown with colors, JSON)
|
|
||||||
- CI/CD integration ready
|
|
||||||
|
|
||||||
## Use of AI
|
|
||||||
[Rules and use of AI](./AI_USE.md)
|
|
||||||
|
|
||||||
## User Interface
|
|
||||||
|
|
||||||
RelSpec provides an interactive terminal-based user interface for managing and editing database schemas. The UI allows you to:
|
|
||||||
|
|
||||||
- **Browse Databases** - Navigate through your database structure with an intuitive menu system
|
|
||||||
- **Edit Schemas** - Create, modify, and organize database schemas
|
|
||||||
- **Manage Tables** - Add, update, or delete tables with full control over structure
|
|
||||||
- **Configure Columns** - Define column properties, data types, constraints, and relationships
|
|
||||||
- **Interactive Editing** - Real-time validation and feedback as you make changes
|
|
||||||
|
|
||||||
The interface supports multiple input formats, making it easy to load, edit, and save your database definitions in various formats.
|
|
||||||
|
|
||||||
<p align="center" width="100%">
|
|
||||||
<img src="./assets/image/screenshots/main_screen.jpg">
|
|
||||||
</p>
|
|
||||||
<p align="center" width="100%">
|
|
||||||
<img src="./assets/image/screenshots/table_view.jpg">
|
|
||||||
</p>
|
|
||||||
<p align="center" width="100%">
|
|
||||||
<img src="./assets/image/screenshots/edit_column.jpg">
|
|
||||||
</p>
|
|
||||||
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
go get github.com/wdevs/relspecgo
|
|
||||||
|
|
||||||
go install -v git.warky.dev/wdevs/relspecgo/cmd/relspec@latest
|
go install -v git.warky.dev/wdevs/relspecgo/cmd/relspec@latest
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Supported Formats
|
||||||
|
|
||||||
### Interactive Schema Editor
|
| 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
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Launch interactive editor with a DBML schema
|
# PostgreSQL → GORM models
|
||||||
relspec edit --from dbml --from-path schema.dbml --to dbml --to-path schema.dbml
|
relspec convert --from pgsql --from-conn "postgres://user:pass@localhost/mydb" \
|
||||||
|
--to gorm --to-path models/ --package models
|
||||||
|
|
||||||
# Edit PostgreSQL database in place
|
# DBML → PostgreSQL DDL
|
||||||
relspec edit --from pgsql --from-conn "postgres://user:pass@localhost/mydb" \
|
relspec convert --from dbml --from-path schema.dbml --to pgsql --to-path schema.sql
|
||||||
--to pgsql --to-conn "postgres://user:pass@localhost/mydb"
|
|
||||||
|
|
||||||
# Edit JSON schema and save as GORM models
|
# PostgreSQL → SQLite (auto flattens schemas)
|
||||||
relspec edit --from json --from-path db.json --to gorm --to-path models/
|
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
|
||||||
```
|
```
|
||||||
|
|
||||||
The `edit` command launches an interactive terminal user interface where you can:
|
### `merge` — Additive schema merge (never modifies existing items)
|
||||||
- Browse and navigate your database structure
|
|
||||||
- Create, modify, and delete schemas, tables, and columns
|
|
||||||
- Configure column properties, constraints, and relationships
|
|
||||||
- Save changes to various formats
|
|
||||||
- Import and merge schemas from other databases
|
|
||||||
|
|
||||||
### Schema Merging
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Merge two JSON schemas (additive merge - adds missing items only)
|
# Merge two JSON schemas
|
||||||
relspec merge --target json --target-path base.json \
|
relspec merge --target json --target-path base.json \
|
||||||
--source json --source-path additions.json \
|
--source json --source-path additions.json \
|
||||||
--output json --output-path merged.json
|
--output json --output-path merged.json
|
||||||
|
|
||||||
# Merge PostgreSQL database into JSON, skipping specific tables
|
# Merge PostgreSQL into JSON, skipping tables
|
||||||
relspec merge --target json --target-path current.json \
|
relspec merge --target json --target-path current.json \
|
||||||
--source pgsql --source-conn "postgres://user:pass@localhost/source_db" \
|
--source pgsql --source-conn "postgres://user:pass@localhost/db" \
|
||||||
--output json --output-path updated.json \
|
--output json --output-path updated.json \
|
||||||
--skip-tables "audit_log,temp_tables"
|
--skip-tables "audit_log,temp_tables"
|
||||||
|
|
||||||
# Cross-format merge (DBML + YAML → JSON)
|
|
||||||
relspec merge --target dbml --target-path base.dbml \
|
|
||||||
--source yaml --source-path additions.yaml \
|
|
||||||
--output json --output-path result.json \
|
|
||||||
--skip-relations --skip-views
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The `merge` command combines two database schemas additively:
|
Skip flags: `--skip-relations` `--skip-views` `--skip-domains` `--skip-enums` `--skip-sequences`
|
||||||
- Adds missing schemas, tables, columns, and other objects
|
|
||||||
- Never modifies or deletes existing items (safe operation)
|
|
||||||
- Supports selective merging with skip options (domains, relations, enums, views, sequences, specific tables)
|
|
||||||
- Works across any combination of supported formats
|
|
||||||
- Perfect for integrating multiple schema definitions or applying patches
|
|
||||||
|
|
||||||
### Schema Conversion
|
### `inspect` — Schema validation / linting
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Convert PostgreSQL database to GORM models
|
# Validate PostgreSQL database
|
||||||
relspec convert --from pgsql --from-conn "postgres://user:pass@localhost/mydb" \
|
|
||||||
--to gorm --to-path models/ --package models
|
|
||||||
|
|
||||||
# Convert GORM models to Bun
|
|
||||||
relspec convert --from gorm --from-path models.go \
|
|
||||||
--to bun --to-path bun_models.go --package models
|
|
||||||
|
|
||||||
# Export database schema to JSON
|
|
||||||
relspec convert --from pgsql --from-conn "postgres://..." \
|
|
||||||
--to json --to-path schema.json
|
|
||||||
|
|
||||||
# Convert DBML to PostgreSQL SQL
|
|
||||||
relspec convert --from dbml --from-path schema.dbml \
|
|
||||||
--to pgsql --to-path schema.sql
|
|
||||||
|
|
||||||
# Convert PostgreSQL database to SQLite (with automatic schema flattening)
|
|
||||||
relspec convert --from pgsql --from-conn "postgres://..." \
|
|
||||||
--to sqlite --to-path sqlite_schema.sql
|
|
||||||
```
|
|
||||||
|
|
||||||
### Schema Validation
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Validate a PostgreSQL database with default rules
|
|
||||||
relspec inspect --from pgsql --from-conn "postgres://user:pass@localhost/mydb"
|
relspec inspect --from pgsql --from-conn "postgres://user:pass@localhost/mydb"
|
||||||
|
|
||||||
# Validate DBML file with custom rules
|
# Validate DBML with custom rules
|
||||||
relspec inspect --from dbml --from-path schema.dbml --rules .relspec-rules.yaml
|
relspec inspect --from dbml --from-path schema.dbml --rules .relspec-rules.yaml
|
||||||
|
|
||||||
# Generate JSON validation report
|
# JSON report output
|
||||||
relspec inspect --from json --from-path db.json \
|
relspec inspect --from json --from-path db.json --output-format json --output report.json
|
||||||
--output-format json --output report.json
|
|
||||||
|
|
||||||
# Validate specific schema only
|
# Filter to specific schema
|
||||||
relspec inspect --from pgsql --from-conn "..." --schema public
|
relspec inspect --from pgsql --from-conn "..." --schema public
|
||||||
```
|
```
|
||||||
|
|
||||||
### Schema Comparison
|
Rules: naming conventions, PK/FK standards, missing indexes, reserved keywords, circular dependencies.
|
||||||
|
|
||||||
|
### `diff` — Schema comparison
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Compare two database schemas
|
|
||||||
relspec diff --from pgsql --from-conn "postgres://localhost/db1" \
|
relspec diff --from pgsql --from-conn "postgres://localhost/db1" \
|
||||||
--to pgsql --to-conn "postgres://localhost/db2"
|
--to pgsql --to-conn "postgres://localhost/db2"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `templ` — Custom template rendering
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 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
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 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"
|
||||||
|
```
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="./assets/image/screenshots/main_screen.jpg">
|
||||||
|
</p>
|
||||||
|
<p align="center">
|
||||||
|
<img src="./assets/image/screenshots/table_view.jpg">
|
||||||
|
</p>
|
||||||
|
<p align="center">
|
||||||
|
<img src="./assets/image/screenshots/edit_column.jpg">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
**Prerequisites:** Go 1.24.0+
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make build # → build/relspec
|
||||||
|
make test # race detection + coverage
|
||||||
|
make lint # requires golangci-lint
|
||||||
|
make coverage # → coverage.html
|
||||||
|
make install # → $GOPATH/bin
|
||||||
|
```
|
||||||
|
|
||||||
## Project Structure
|
## Project Structure
|
||||||
|
|
||||||
```
|
```
|
||||||
relspecgo/
|
cmd/relspec/ CLI commands
|
||||||
├── cmd/
|
pkg/readers/ Input format readers
|
||||||
│ └── relspec/ # CLI application (convert, inspect, diff, scripts)
|
pkg/writers/ Output format writers
|
||||||
├── pkg/
|
pkg/inspector/ Schema validation
|
||||||
│ ├── readers/ # Input format readers (DBML, GORM, PostgreSQL, etc.)
|
pkg/diff/ Schema comparison
|
||||||
│ ├── writers/ # Output format writers (GORM, Bun, SQL, etc.)
|
pkg/merge/ Schema merging
|
||||||
│ ├── inspector/ # Schema validation and linting
|
pkg/models/ Internal data models
|
||||||
│ ├── diff/ # Schema comparison
|
pkg/transform/ Transformation logic
|
||||||
│ ├── models/ # Internal data models
|
pkg/pgsql/ PostgreSQL utilities
|
||||||
│ ├── transform/ # Transformation logic
|
|
||||||
│ └── pgsql/ # PostgreSQL utilities (keywords, data types)
|
|
||||||
├── examples/ # Usage examples
|
|
||||||
└── tests/ # Test files
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Todo
|
|
||||||
|
|
||||||
[Todo List of Features](./TODO.md)
|
|
||||||
|
|
||||||
## Development
|
|
||||||
|
|
||||||
### Prerequisites
|
|
||||||
- Go 1.21 or higher
|
|
||||||
- Access to test databases (optional)
|
|
||||||
|
|
||||||
### Building
|
|
||||||
|
|
||||||
```bash
|
|
||||||
go build -o relspec ./cmd/relspec
|
|
||||||
```
|
|
||||||
|
|
||||||
### Testing
|
|
||||||
|
|
||||||
```bash
|
|
||||||
go test ./...
|
|
||||||
```
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
Apache License 2.0 - See [LICENSE](LICENSE) for details.
|
|
||||||
|
|
||||||
Copyright 2025 Warky Devs
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Contributions welcome. Please open an issue or submit a pull request.
|
1. Register or sign in with GitHub at [git.warky.dev](https://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/74rcTujp25](https://discord.gg/74rcTujp25) — `warkyhein`
|
||||||
|
|
||||||
|
## Links
|
||||||
|
|
||||||
|
- [Todo](./TODO.md)
|
||||||
|
- [AI Use Policy](./AI_USE.md)
|
||||||
|
- [License](LICENSE) — Apache 2.0 · Copyright 2025 Warky Devs
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 171 KiB After Width: | Height: | Size: 200 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 107 KiB After Width: | Height: | Size: 200 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 80 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 192 KiB |
Reference in New Issue
Block a user