feat(writers): stamp RelSpec version in generated headers; preserve DBML column order

- Add pkg/buildinfo with Version/BuildDate (set via ldflags, VCS fallback);
  cmd/relspec now sources version info from it
- Emit "RelSpec <version> (built: <date>)" in generated file headers for
  bun, gorm, drizzle, pgsql (incl. migration), mssql, sqlite writers
- pgsql writer: getSortedColumns now sorts by Sequence then Name so the
  streaming WriteSchema/WriteDatabase path preserves source column order
- dbml reader: mergeTable re-bases merged-in column Sequence values past the
  existing max, fixing colliding sequences (and alphabetical fallback) when a
  table is split across multiple DBML files
- Tests for bun/gorm header + column order, and dbml multi-file merge ordering
This commit is contained in:
2026-09-10 22:08:49 +02:00
parent 58e46e5b59
commit 19a2cc1fe3
17 changed files with 214 additions and 65 deletions
+7 -4
View File
@@ -4,14 +4,16 @@ import (
"sort"
"strings"
"git.warky.dev/wdevs/relspecgo/pkg/buildinfo"
"git.warky.dev/wdevs/relspecgo/pkg/models"
)
// TemplateData represents the data passed to the template for code generation
type TemplateData struct {
Imports []string
Enums []*EnumData
Tables []*TableData
GeneratedBy string
Imports []string
Enums []*EnumData
Tables []*TableData
}
// EnumData represents an enum in the schema
@@ -59,7 +61,8 @@ type IndexData struct {
// NewTemplateData creates a new TemplateData
func NewTemplateData() *TemplateData {
return &TemplateData{
Imports: make([]string, 0),
GeneratedBy: buildinfo.GeneratedComment(),
Imports: make([]string, 0),
Enums: make([]*EnumData, 0),
Tables: make([]*TableData, 0),
}
+2 -1
View File
@@ -7,7 +7,8 @@ import (
// schemaTemplate defines the template for generating Drizzle schemas
const schemaTemplate = `// Code generated by relspecgo. DO NOT EDIT.
{{range .Imports}}{{.}}
{{if .GeneratedBy}}// {{.GeneratedBy}}
{{end}}{{range .Imports}}{{.}}
{{end}}
{{if .Enums}}
// Enums