Compare commits
2 Commits
466d657ea7
...
v1.0.33
| Author | SHA1 | Date | |
|---|---|---|---|
| 0e6e94797c | |||
| a033349c76 |
11
.github/workflows/release.yml
vendored
11
.github/workflows/release.yml
vendored
@@ -25,6 +25,7 @@ jobs:
|
|||||||
id: get_version
|
id: get_version
|
||||||
run: |
|
run: |
|
||||||
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
||||||
|
echo "BUILD_DATE=$(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_OUTPUT
|
||||||
echo "Version: ${GITHUB_REF#refs/tags/}"
|
echo "Version: ${GITHUB_REF#refs/tags/}"
|
||||||
|
|
||||||
- name: Build binaries for multiple platforms
|
- name: Build binaries for multiple platforms
|
||||||
@@ -32,19 +33,19 @@ jobs:
|
|||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
|
|
||||||
# Linux AMD64
|
# Linux AMD64
|
||||||
GOOS=linux GOARCH=amd64 go build -o dist/relspec-linux-amd64 -ldflags "-X main.version=${{ steps.get_version.outputs.VERSION }}" ./cmd/relspec
|
GOOS=linux GOARCH=amd64 go build -o dist/relspec-linux-amd64 -ldflags "-X 'main.version=${{ steps.get_version.outputs.VERSION }}' -X 'main.buildDate=${{ steps.get_version.outputs.BUILD_DATE }}'" ./cmd/relspec
|
||||||
|
|
||||||
# Linux ARM64
|
# Linux ARM64
|
||||||
GOOS=linux GOARCH=arm64 go build -o dist/relspec-linux-arm64 -ldflags "-X main.version=${{ steps.get_version.outputs.VERSION }}" ./cmd/relspec
|
GOOS=linux GOARCH=arm64 go build -o dist/relspec-linux-arm64 -ldflags "-X 'main.version=${{ steps.get_version.outputs.VERSION }}' -X 'main.buildDate=${{ steps.get_version.outputs.BUILD_DATE }}'" ./cmd/relspec
|
||||||
|
|
||||||
# macOS AMD64
|
# macOS AMD64
|
||||||
GOOS=darwin GOARCH=amd64 go build -o dist/relspec-darwin-amd64 -ldflags "-X main.version=${{ steps.get_version.outputs.VERSION }}" ./cmd/relspec
|
GOOS=darwin GOARCH=amd64 go build -o dist/relspec-darwin-amd64 -ldflags "-X 'main.version=${{ steps.get_version.outputs.VERSION }}' -X 'main.buildDate=${{ steps.get_version.outputs.BUILD_DATE }}'" ./cmd/relspec
|
||||||
|
|
||||||
# macOS ARM64 (Apple Silicon)
|
# macOS ARM64 (Apple Silicon)
|
||||||
GOOS=darwin GOARCH=arm64 go build -o dist/relspec-darwin-arm64 -ldflags "-X main.version=${{ steps.get_version.outputs.VERSION }}" ./cmd/relspec
|
GOOS=darwin GOARCH=arm64 go build -o dist/relspec-darwin-arm64 -ldflags "-X 'main.version=${{ steps.get_version.outputs.VERSION }}' -X 'main.buildDate=${{ steps.get_version.outputs.BUILD_DATE }}'" ./cmd/relspec
|
||||||
|
|
||||||
# Windows AMD64
|
# Windows AMD64
|
||||||
GOOS=windows GOARCH=amd64 go build -o dist/relspec-windows-amd64.exe -ldflags "-X main.version=${{ steps.get_version.outputs.VERSION }}" ./cmd/relspec
|
GOOS=windows GOARCH=amd64 go build -o dist/relspec-windows-amd64.exe -ldflags "-X 'main.version=${{ steps.get_version.outputs.VERSION }}' -X 'main.buildDate=${{ steps.get_version.outputs.BUILD_DATE }}'" ./cmd/relspec
|
||||||
|
|
||||||
# Create checksums
|
# Create checksums
|
||||||
cd dist
|
cd dist
|
||||||
|
|||||||
13
Makefile
13
Makefile
@@ -14,6 +14,11 @@ GOGET=$(GOCMD) get
|
|||||||
GOMOD=$(GOCMD) mod
|
GOMOD=$(GOCMD) mod
|
||||||
GOCLEAN=$(GOCMD) clean
|
GOCLEAN=$(GOCMD) clean
|
||||||
|
|
||||||
|
# Version information
|
||||||
|
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
||||||
|
BUILD_DATE := $(shell date -u +"%Y-%m-%d %H:%M:%S UTC")
|
||||||
|
LDFLAGS := -X 'main.version=$(VERSION)' -X 'main.buildDate=$(BUILD_DATE)'
|
||||||
|
|
||||||
# Auto-detect container runtime (Docker or Podman)
|
# Auto-detect container runtime (Docker or Podman)
|
||||||
CONTAINER_RUNTIME := $(shell \
|
CONTAINER_RUNTIME := $(shell \
|
||||||
if command -v podman > /dev/null 2>&1; then \
|
if command -v podman > /dev/null 2>&1; then \
|
||||||
@@ -37,9 +42,9 @@ COMPOSE_CMD := $(shell \
|
|||||||
all: lint test build ## Run linting, tests, and build
|
all: lint test build ## Run linting, tests, and build
|
||||||
|
|
||||||
build: deps ## Build the binary
|
build: deps ## Build the binary
|
||||||
@echo "Building $(BINARY_NAME)..."
|
@echo "Building $(BINARY_NAME) $(VERSION)..."
|
||||||
@mkdir -p $(BUILD_DIR)
|
@mkdir -p $(BUILD_DIR)
|
||||||
$(GOBUILD) -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/relspec
|
$(GOBUILD) -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/relspec
|
||||||
@echo "Build complete: $(BUILD_DIR)/$(BINARY_NAME)"
|
@echo "Build complete: $(BUILD_DIR)/$(BINARY_NAME)"
|
||||||
|
|
||||||
test: test-unit ## Run all unit tests (alias for test-unit)
|
test: test-unit ## Run all unit tests (alias for test-unit)
|
||||||
@@ -91,8 +96,8 @@ clean: ## Clean build artifacts
|
|||||||
@echo "Clean complete"
|
@echo "Clean complete"
|
||||||
|
|
||||||
install: ## Install the binary to $GOPATH/bin
|
install: ## Install the binary to $GOPATH/bin
|
||||||
@echo "Installing $(BINARY_NAME)..."
|
@echo "Installing $(BINARY_NAME) $(VERSION)..."
|
||||||
$(GOCMD) install ./cmd/relspec
|
$(GOCMD) install -ldflags "$(LDFLAGS)" ./cmd/relspec
|
||||||
@echo "Install complete"
|
@echo "Install complete"
|
||||||
|
|
||||||
deps: ## Download dependencies
|
deps: ## Download dependencies
|
||||||
|
|||||||
@@ -1,9 +1,17 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// Version information, set via ldflags during build
|
||||||
|
version = "dev"
|
||||||
|
buildDate = "unknown"
|
||||||
|
)
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "relspec",
|
Use: "relspec",
|
||||||
Short: "RelSpec - Database schema conversion and analysis tool",
|
Short: "RelSpec - Database schema conversion and analysis tool",
|
||||||
@@ -13,6 +21,9 @@ bidirectional conversion between various database schema formats.
|
|||||||
It reads database schemas from multiple sources (live databases, DBML,
|
It reads database schemas from multiple sources (live databases, DBML,
|
||||||
DCTX, DrawDB, etc.) and writes them to various formats (GORM, Bun,
|
DCTX, DrawDB, etc.) and writes them to various formats (GORM, Bun,
|
||||||
JSON, YAML, SQL, etc.).`,
|
JSON, YAML, SQL, etc.).`,
|
||||||
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||||
|
fmt.Printf("RelSpec %s (built: %s)\n\n", version, buildDate)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -24,4 +35,5 @@ func init() {
|
|||||||
rootCmd.AddCommand(editCmd)
|
rootCmd.AddCommand(editCmd)
|
||||||
rootCmd.AddCommand(mergeCmd)
|
rootCmd.AddCommand(mergeCmd)
|
||||||
rootCmd.AddCommand(splitCmd)
|
rootCmd.AddCommand(splitCmd)
|
||||||
|
rootCmd.AddCommand(versionCmd)
|
||||||
}
|
}
|
||||||
|
|||||||
16
cmd/relspec/version.go
Normal file
16
cmd/relspec/version.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var versionCmd = &cobra.Command{
|
||||||
|
Use: "version",
|
||||||
|
Short: "Print version information",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
fmt.Printf("RelSpec %s\n", version)
|
||||||
|
fmt.Printf("Built: %s\n", buildDate)
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -110,8 +110,7 @@ func NewModelData(table *models.Table, schema string, typeMapper *TypeMapper, fl
|
|||||||
tableName := writers.QualifiedTableName(schema, table.Name, flattenSchema)
|
tableName := writers.QualifiedTableName(schema, table.Name, flattenSchema)
|
||||||
|
|
||||||
// Generate model name: Model + Schema + Table (all PascalCase)
|
// Generate model name: Model + Schema + Table (all PascalCase)
|
||||||
singularTable := Singularize(table.Name)
|
tablePart := SnakeCaseToPascalCase(table.Name)
|
||||||
tablePart := SnakeCaseToPascalCase(singularTable)
|
|
||||||
|
|
||||||
// Include schema name in model name
|
// Include schema name in model name
|
||||||
var modelName string
|
var modelName string
|
||||||
|
|||||||
@@ -318,8 +318,7 @@ func (w *Writer) findTable(schemaName, tableName string, db *models.Database) *m
|
|||||||
|
|
||||||
// getModelName generates the model name from schema and table name
|
// getModelName generates the model name from schema and table name
|
||||||
func (w *Writer) getModelName(schemaName, tableName string) string {
|
func (w *Writer) getModelName(schemaName, tableName string) string {
|
||||||
singular := Singularize(tableName)
|
tablePart := SnakeCaseToPascalCase(tableName)
|
||||||
tablePart := SnakeCaseToPascalCase(singular)
|
|
||||||
|
|
||||||
// Include schema name in model name
|
// Include schema name in model name
|
||||||
var modelName string
|
var modelName string
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ func TestWriter_WriteTable(t *testing.T) {
|
|||||||
// Verify key elements are present
|
// Verify key elements are present
|
||||||
expectations := []string{
|
expectations := []string{
|
||||||
"package models",
|
"package models",
|
||||||
"type ModelPublicUser struct",
|
"type ModelPublicUsers struct",
|
||||||
"bun.BaseModel",
|
"bun.BaseModel",
|
||||||
"table:public.users",
|
"table:public.users",
|
||||||
"alias:users",
|
"alias:users",
|
||||||
@@ -78,9 +78,9 @@ func TestWriter_WriteTable(t *testing.T) {
|
|||||||
"resolvespec_common.SqlTime",
|
"resolvespec_common.SqlTime",
|
||||||
"bun:\"id",
|
"bun:\"id",
|
||||||
"bun:\"email",
|
"bun:\"email",
|
||||||
"func (m ModelPublicUser) TableName() string",
|
"func (m ModelPublicUsers) TableName() string",
|
||||||
"return \"public.users\"",
|
"return \"public.users\"",
|
||||||
"func (m ModelPublicUser) GetID() int64",
|
"func (m ModelPublicUsers) GetID() int64",
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, expected := range expectations {
|
for _, expected := range expectations {
|
||||||
|
|||||||
@@ -109,8 +109,7 @@ func NewModelData(table *models.Table, schema string, typeMapper *TypeMapper, fl
|
|||||||
tableName := writers.QualifiedTableName(schema, table.Name, flattenSchema)
|
tableName := writers.QualifiedTableName(schema, table.Name, flattenSchema)
|
||||||
|
|
||||||
// Generate model name: Model + Schema + Table (all PascalCase)
|
// Generate model name: Model + Schema + Table (all PascalCase)
|
||||||
singularTable := Singularize(table.Name)
|
tablePart := SnakeCaseToPascalCase(table.Name)
|
||||||
tablePart := SnakeCaseToPascalCase(singularTable)
|
|
||||||
|
|
||||||
// Include schema name in model name
|
// Include schema name in model name
|
||||||
var modelName string
|
var modelName string
|
||||||
|
|||||||
@@ -312,8 +312,7 @@ func (w *Writer) findTable(schemaName, tableName string, db *models.Database) *m
|
|||||||
|
|
||||||
// getModelName generates the model name from schema and table name
|
// getModelName generates the model name from schema and table name
|
||||||
func (w *Writer) getModelName(schemaName, tableName string) string {
|
func (w *Writer) getModelName(schemaName, tableName string) string {
|
||||||
singular := Singularize(tableName)
|
tablePart := SnakeCaseToPascalCase(tableName)
|
||||||
tablePart := SnakeCaseToPascalCase(singular)
|
|
||||||
|
|
||||||
// Include schema name in model name
|
// Include schema name in model name
|
||||||
var modelName string
|
var modelName string
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ func TestWriter_WriteTable(t *testing.T) {
|
|||||||
// Verify key elements are present
|
// Verify key elements are present
|
||||||
expectations := []string{
|
expectations := []string{
|
||||||
"package models",
|
"package models",
|
||||||
"type ModelPublicUser struct",
|
"type ModelPublicUsers struct",
|
||||||
"ID",
|
"ID",
|
||||||
"int64",
|
"int64",
|
||||||
"Email",
|
"Email",
|
||||||
@@ -75,9 +75,9 @@ func TestWriter_WriteTable(t *testing.T) {
|
|||||||
"time.Time",
|
"time.Time",
|
||||||
"gorm:\"column:id",
|
"gorm:\"column:id",
|
||||||
"gorm:\"column:email",
|
"gorm:\"column:email",
|
||||||
"func (m ModelPublicUser) TableName() string",
|
"func (m ModelPublicUsers) TableName() string",
|
||||||
"return \"public.users\"",
|
"return \"public.users\"",
|
||||||
"func (m ModelPublicUser) GetID() int64",
|
"func (m ModelPublicUsers) GetID() int64",
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, expected := range expectations {
|
for _, expected := range expectations {
|
||||||
|
|||||||
Reference in New Issue
Block a user