Table.Columns/Constraints/Indexes/Relationships are Go maps, and every writer, reader, diff, inspector, and merge code path that iterated them directly was subject to Go's randomized map order, so identical input could produce different output (or a different in-report violation/diff order) on every run. Most visibly this showed up as bun/gorm `unique:` struct tags changing order across consecutive `make models` runs with no source change. Fixed by sorting map iteration (by Sequence then Name, or alphabetically for string-keyed maps) everywhere the order affects generated output or first-match tie-break logic, across the bun, gorm, sqlite, dbml, drawdb, pgsql, prisma, graphql, typeorm, drizzle, and dctx writers; the dctx, prisma, and typeorm readers; the shared models.GetPrimaryKey/ GetForeignKeys helpers; pkg/diff, pkg/inspector, and pkg/merge; and the TUI column/relationship pickers in pkg/ui.
DCTX Reader
Reads Clarion database dictionary (DCTX) files and extracts database schema information.
Overview
The DCTX Reader parses Clarion dictionary files (.dctx) that define database structures in the Clarion development system and converts them into RelSpec's internal database model representation.
Features
- Parses Clarion DCTX XML format
- Extracts file (table) and field (column) definitions
- Supports Clarion data types
- Handles keys (indexes) and relationships
Usage
Basic Example
package main
import (
"fmt"
"git.warky.dev/wdevs/relspecgo/pkg/readers"
"git.warky.dev/wdevs/relspecgo/pkg/readers/dctx"
)
func main() {
options := &readers.ReaderOptions{
FilePath: "/path/to/database.dctx",
}
reader := dctx.NewReader(options)
db, err := reader.ReadDatabase()
if err != nil {
panic(err)
}
fmt.Printf("Found %d schemas\n", len(db.Schemas))
}
CLI Example
# Read DCTX file and convert to JSON
relspec --input dctx --in-file legacy.dctx --output json --out-file schema.json
# Convert DCTX to GORM models for migration
relspec --input dctx --in-file app.dctx --output gorm --out-file models.go
# Export DCTX to PostgreSQL DDL
relspec --input dctx --in-file database.dctx --output pgsql --out-file schema.sql
Example DCTX Structure
DCTX files are XML-based Clarion dictionary files that define:
- Files (equivalent to tables)
- Fields (columns) with Clarion-specific types
- Keys (indexes)
- Relationships between files
Common Clarion data types:
STRING- Fixed-length stringCSTRING- C-style null-terminated stringLONG- 32-bit integerSHORT- 16-bit integerDECIMAL- Decimal numberREAL- Floating pointDATE- Date fieldTIME- Time field
Type Mapping
The reader automatically maps Clarion data types to standard SQL types:
| Clarion Type | SQL Type |
|---|---|
| STRING | VARCHAR |
| CSTRING | VARCHAR |
| LONG | INTEGER |
| SHORT | SMALLINT |
| DECIMAL | NUMERIC |
| REAL | REAL |
| DATE | DATE |
| TIME | TIME |
Notes
- DCTX is specific to Clarion development platform
- Useful for migrating legacy Clarion applications
- Schema name defaults to
public - Preserves field properties and constraints where possible