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 Writer
Generates Clarion database dictionary (DCTX) files from database schema information.
Overview
The DCTX Writer converts RelSpec's internal database model representation into Clarion dictionary XML format, used by the Clarion development platform.
Features
- Generates DCTX XML format
- Creates file (table) definitions
- Defines fields (columns) with Clarion types
- Includes keys (indexes)
- Handles relationships
Usage
Basic Example
package main
import (
"git.warky.dev/wdevs/relspecgo/pkg/models"
"git.warky.dev/wdevs/relspecgo/pkg/writers"
"git.warky.dev/wdevs/relspecgo/pkg/writers/dctx"
)
func main() {
options := &writers.WriterOptions{
OutputPath: "database.dctx",
}
writer := dctx.NewWriter(options)
err := writer.WriteDatabase(db)
if err != nil {
panic(err)
}
}
CLI Examples
# Generate DCTX from PostgreSQL database (for Clarion migration)
relspec --input pgsql \
--conn "postgres://localhost/mydb" \
--output dctx \
--out-file app.dctx
# Convert GORM models to DCTX
relspec --input gorm --in-file models.go --output dctx --out-file legacy.dctx
# Convert JSON schema to DCTX
relspec --input json --in-file schema.json --output dctx --out-file database.dctx
Type Mapping
Converts standard SQL types to Clarion types:
| SQL Type | Clarion Type | Notes |
|---|---|---|
| VARCHAR(n) | STRING(n) | Fixed-length string |
| TEXT | STRING | Variable length |
| INTEGER | LONG | 32-bit integer |
| BIGINT | DECIMAL(20,0) | Large integer |
| SMALLINT | SHORT | 16-bit integer |
| NUMERIC(p,s) | DECIMAL(p,s) | Decimal number |
| REAL, FLOAT | REAL | Floating point |
| BOOLEAN | BYTE | 0/1 value |
| DATE | DATE | Date field |
| TIME | TIME | Time field |
| TIMESTAMP | LONG | Unix timestamp |
DCTX Structure
DCTX files are XML-based with this structure:
<?xml version="1.0"?>
<dictionary>
<file name="USERS" driver="TOPSPEED">
<record>
<field name="ID" type="LONG" />
<field name="USERNAME" type="STRING" bytes="50" />
<field name="EMAIL" type="STRING" bytes="100" />
</record>
<key name="KEY_PRIMARY" primary="true">
<field name="ID" />
</key>
</file>
</dictionary>
Features
- File definitions (equivalent to tables)
- Field definitions with Clarion-specific types
- Key definitions (primary and foreign)
- Relationships between files
- Driver specifications (TOPSPEED, SQL, etc.)
Notes
- DCTX is specific to Clarion development
- Useful for legacy system integration
- Field names are typically uppercase in Clarion
- Supports Clarion-specific attributes
- Can be imported into Clarion IDE