Reverse reading bun/gorm models
Some checks failed
CI / Test (1.24) (push) Has been cancelled
CI / Test (1.25) (push) Has been cancelled
CI / Test (1.23) (push) Has been cancelled
CI / Lint (push) Failing after -26m40s
CI / Build (push) Failing after -25m24s

This commit is contained in:
2025-12-18 20:00:59 +02:00
parent d93a4b6f08
commit 5f1923233e
2 changed files with 198 additions and 24 deletions

View File

@@ -8,9 +8,11 @@ import (
"git.warky.dev/wdevs/relspecgo/pkg/models"
"git.warky.dev/wdevs/relspecgo/pkg/readers"
"git.warky.dev/wdevs/relspecgo/pkg/readers/bun"
"git.warky.dev/wdevs/relspecgo/pkg/readers/dbml"
"git.warky.dev/wdevs/relspecgo/pkg/readers/dctx"
"git.warky.dev/wdevs/relspecgo/pkg/readers/drawdb"
"git.warky.dev/wdevs/relspecgo/pkg/readers/gorm"
"git.warky.dev/wdevs/relspecgo/pkg/readers/json"
"git.warky.dev/wdevs/relspecgo/pkg/readers/pgsql"
"git.warky.dev/wdevs/relspecgo/pkg/readers/yaml"
@@ -51,6 +53,8 @@ Input formats:
- drawdb: DrawDB JSON files
- json: JSON database schema
- yaml: YAML database schema
- gorm: GORM model files (Go, file or directory)
- bun: Bun model files (Go, file or directory)
- pgsql: PostgreSQL database (live connection)
Output formats:
@@ -106,12 +110,20 @@ Examples:
# Convert DBML to DCTX with specific schema
relspec convert --from dbml --from-path schema.dbml \
--to dctx --to-path output.dctx --schema public`,
--to dctx --to-path output.dctx --schema public
# Convert GORM models directory to DBML
relspec convert --from gorm --from-path /path/to/models \
--to dbml --to-path schema.dbml
# Convert Bun models directory to JSON
relspec convert --from bun --from-path ./models \
--to json --to-path schema.json`,
RunE: runConvert,
}
func init() {
convertCmd.Flags().StringVar(&convertSourceType, "from", "", "Source format (dbml, dctx, drawdb, json, yaml, pgsql)")
convertCmd.Flags().StringVar(&convertSourceType, "from", "", "Source format (dbml, dctx, drawdb, json, yaml, gorm, bun, pgsql)")
convertCmd.Flags().StringVar(&convertSourcePath, "from-path", "", "Source file path (for file-based formats)")
convertCmd.Flags().StringVar(&convertSourceConn, "from-conn", "", "Source connection string (for database formats)")
@@ -215,6 +227,18 @@ func readDatabaseForConvert(dbType, filePath, connString string) (*models.Databa
}
reader = pgsql.NewReader(&readers.ReaderOptions{ConnectionString: connString})
case "gorm":
if filePath == "" {
return nil, fmt.Errorf("file path is required for GORM format")
}
reader = gorm.NewReader(&readers.ReaderOptions{FilePath: filePath})
case "bun":
if filePath == "" {
return nil, fmt.Errorf("file path is required for Bun format")
}
reader = bun.NewReader(&readers.ReaderOptions{FilePath: filePath})
default:
return nil, fmt.Errorf("unsupported source format: %s", dbType)
}