yaml

package
v1.13.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Package yaml provides YAML schema parsing, diff computation, and migration generation.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

View Source
const (
	FieldTypeVarchar    = "varchar"
	FieldTypeText       = "text"
	FieldTypeInteger    = "integer"
	FieldTypeBigint     = "bigint"
	FieldTypeSerial     = "serial"
	FieldTypeFloat      = "float"
	FieldTypeDecimal    = "decimal"
	FieldTypeBoolean    = "boolean"
	FieldTypeDate       = "date"
	FieldTypeTime       = "time"
	FieldTypeTimestamp  = "timestamp"
	FieldTypeUUID       = "uuid"
	FieldTypeJSON       = "json"
	FieldTypeJSONB      = "jsonb"
	FieldTypeForeignKey = "foreign_key"
)

Field types

View Source
const (
	SQLTypeText             = "TEXT"
	SQLTypeInteger          = "INTEGER"
	SQLTypeInt              = "INT"
	SQLTypeBigint           = "BIGINT"
	SQLTypeFloat            = "FLOAT"
	SQLTypeReal             = "REAL"
	SQLTypeDecimal          = "DECIMAL"
	SQLTypeBoolean          = "BOOLEAN"
	SQLTypeDate             = "DATE"
	SQLTypeTime             = "TIME"
	SQLTypeTimestamp        = "TIMESTAMP"
	SQLTypeUUID             = "UUID"
	SQLTypeChar36           = "CHAR(36)"
	SQLTypeUniqueIdentifier = "UNIQUEIDENTIFIER"
	SQLTypeJSONB            = "JSONB"
	SQLTypeNVarcharMax      = "NVARCHAR(MAX)"
)

SQL types

View Source
const (
	DatabasePostgreSQL = types.DatabasePostgreSQL
	DatabaseMySQL      = types.DatabaseMySQL
	DatabaseSQLServer  = types.DatabaseSQLServer
	DatabaseSQLite     = types.DatabaseSQLite
)

Re-export constants

View Source
const (
	DefaultMigrationsDir = "migrations"
)

Common values

Variables

View Source
var IsValidDatabase = types.IsValidDatabase
View Source
var IsValidFieldType = types.IsValidFieldType
View Source
var ParseDatabaseType = types.ParseDatabaseType

Re-export functions

View Source
var ValidFieldTypes = types.ValidFieldTypes

Re-export variables

Functions

func IsDestructiveOperation

func IsDestructiveOperation(changeType ChangeType) bool

IsDestructiveOperation returns true if the operation type may cause data loss. Exported so callers outside this package (e.g. cmd) can apply the same logic when building per-change decisions before code generation.

Types

type Change

type Change struct {
	Type        ChangeType  `json:"type"`
	TableName   string      `json:"table_name"`
	FieldName   string      `json:"field_name,omitempty"`
	Description string      `json:"description"`
	OldValue    interface{} `json:"old_value,omitempty"`
	NewValue    interface{} `json:"new_value,omitempty"`
	Destructive bool        `json:"destructive"`
}

Change represents a structural change between schemas

type ChangeType

type ChangeType string

ChangeType represents the type of change

const (
	ChangeTypeTableAdded           ChangeType = "table_added"
	ChangeTypeTableRemoved         ChangeType = "table_removed"
	ChangeTypeTableRenamed         ChangeType = "table_renamed"
	ChangeTypeFieldAdded           ChangeType = "field_added"
	ChangeTypeFieldRemoved         ChangeType = "field_removed"
	ChangeTypeFieldRenamed         ChangeType = "field_renamed"
	ChangeTypeFieldModified        ChangeType = "field_modified"
	ChangeTypeIndexAdded           ChangeType = "index_added"
	ChangeTypeIndexRemoved         ChangeType = "index_removed"
	ChangeTypeForeignKeyAdded      ChangeType = "foreign_key_added"
	ChangeTypeForeignKeyRemoved    ChangeType = "foreign_key_removed"
	ChangeTypeDefaultsModified     ChangeType = "defaults_modified"      // non-destructive: updates active schema defaults
	ChangeTypeTypeMappingsModified ChangeType = "type_mappings_modified" // non-destructive: updates active provider type mappings
)

ChangeType constants enumerate the kinds of schema changes that can be detected.

type Database

type Database = types.Database

Database is an alias for types.Database for backwards compatibility.

type DatabaseType

type DatabaseType = types.DatabaseType

DatabaseType is an alias for types.DatabaseType for backwards compatibility.

type Defaults

type Defaults = types.Defaults

Defaults is an alias for types.Defaults for backwards compatibility.

type Dependency

type Dependency struct {
	FromTable string
	ToTable   string
	FieldName string
	Type      string // "foreign_key" or "many_to_many"
}

Dependency represents a foreign key dependency between tables

type DependencyAnalyzer

type DependencyAnalyzer struct {
	// contains filtered or unexported fields
}

DependencyAnalyzer handles foreign key dependency analysis and topological sorting for YAML schemas

func NewDependencyAnalyzer

func NewDependencyAnalyzer(verbose bool) *DependencyAnalyzer

NewDependencyAnalyzer creates a new YAML dependency analyzer

func (*DependencyAnalyzer) AnalyzeDependencies

func (a *DependencyAnalyzer) AnalyzeDependencies(schema *Schema) ([]Dependency, error)

AnalyzeDependencies analyzes foreign key dependencies in a YAML schema

func (*DependencyAnalyzer) GenerateJunctionTables

func (a *DependencyAnalyzer) GenerateJunctionTables(schema *Schema) ([]Table, error)

GenerateJunctionTables generates junction table definitions for many-to-many relationships

func (*DependencyAnalyzer) GetDependentTables

func (a *DependencyAnalyzer) GetDependentTables(schema *Schema, tableName string) ([]string, error)

GetDependentTables returns all tables that depend on the given table

func (*DependencyAnalyzer) GetManyToManyRelationships

func (a *DependencyAnalyzer) GetManyToManyRelationships(schema *Schema) []Dependency

GetManyToManyRelationships returns all many-to-many relationships in the schema

func (*DependencyAnalyzer) GetReferencedTables

func (a *DependencyAnalyzer) GetReferencedTables(schema *Schema, tableName string) ([]string, error)

GetReferencedTables returns all tables that the given table references

func (*DependencyAnalyzer) TopologicalSort

func (a *DependencyAnalyzer) TopologicalSort(schema *Schema) ([]string, error)

TopologicalSort sorts tables based on their foreign key dependencies

func (*DependencyAnalyzer) ValidateCircularDependencies

func (a *DependencyAnalyzer) ValidateCircularDependencies(schema *Schema) error

ValidateCircularDependencies checks for circular dependencies in the schema

type DiffEngine

type DiffEngine struct {
	// contains filtered or unexported fields
}

DiffEngine handles YAML schema comparison and diff generation

func NewDiffEngine

func NewDiffEngine(verbose bool) *DiffEngine

NewDiffEngine creates a new YAML diff engine

func (*DiffEngine) CompareSchemas

func (de *DiffEngine) CompareSchemas(oldSchema, newSchema *Schema) (*SchemaDiff, error)

CompareSchemas compares two YAML schemas and returns the differences

func (*DiffEngine) GenerateMigrationName

func (de *DiffEngine) GenerateMigrationName(diff *SchemaDiff) string

GenerateMigrationName generates a meaningful migration name from changes

func (*DiffEngine) GetChangesByType

func (de *DiffEngine) GetChangesByType(diff *SchemaDiff, changeType ChangeType) []Change

GetChangesByType returns changes filtered by type

func (*DiffEngine) GetDestructiveChanges

func (de *DiffEngine) GetDestructiveChanges(diff *SchemaDiff) []Change

GetDestructiveChanges returns only destructive changes

func (*DiffEngine) HasDestructiveChanges

func (de *DiffEngine) HasDestructiveChanges(diff *SchemaDiff) bool

HasDestructiveChanges checks if the diff contains destructive changes

type Field

type Field = types.Field

Field is an alias for types.Field for backwards compatibility.

type ForeignKey

type ForeignKey = types.ForeignKey

ForeignKey is an alias for types.ForeignKey for backwards compatibility.

type Include

type Include = types.Include

Include is an alias for types.Include for backwards compatibility.

type IncludeProcessor

type IncludeProcessor struct {
	// contains filtered or unexported fields
}

IncludeProcessor handles processing schema includes with circular dependency tracking

func NewIncludeProcessor

func NewIncludeProcessor(verbose bool) *IncludeProcessor

NewIncludeProcessor creates a new include processor

func (*IncludeProcessor) ProcessIncludes

func (ip *IncludeProcessor) ProcessIncludes(schema *Schema, currentFile string) (*Schema, error)

ProcessIncludes processes all includes in a schema recursively

func (*IncludeProcessor) Reset

func (ip *IncludeProcessor) Reset()

Reset clears the processed file tracking (useful for testing)

type Index

type Index = types.Index

Index is an alias for types.Index for backwards compatibility.

type ManyToMany

type ManyToMany = types.ManyToMany

ManyToMany is an alias for types.ManyToMany for backwards compatibility.

type Merger

type Merger struct {
	// contains filtered or unexported fields
}

Merger handles YAML schema merging with conflict resolution

func NewMerger

func NewMerger(verbose bool) *Merger

NewMerger creates a new YAML merger

func (*Merger) GetMergedFieldNames

func (m *Merger) GetMergedFieldNames(_ string, tables []Table) []string

GetMergedFieldNames returns the names of all fields that were merged within each table

func (*Merger) GetMergedTableNames

func (m *Merger) GetMergedTableNames(schemas []*Schema) []string

GetMergedTableNames returns the names of all tables that were merged from multiple definitions

func (*Merger) MergeSchemas

func (m *Merger) MergeSchemas(schemas []*Schema) (*Schema, error)

MergeSchemas merges multiple YAML schemas into a single unified schema

func (*Merger) ValidateMergedSchema

func (m *Merger) ValidateMergedSchema(schema *Schema) error

ValidateMergedSchema validates the merged schema for consistency

type ModuleResolver

type ModuleResolver struct {
	// contains filtered or unexported fields
}

ModuleResolver handles resolving Go module paths to filesystem paths without shelling out to `go list`. It reads go.mod and go.work directly.

func NewModuleResolver

func NewModuleResolver(verbose bool) *ModuleResolver

NewModuleResolver creates a new module resolver

func (*ModuleResolver) ResolveIncludePath

func (mr *ModuleResolver) ResolveIncludePath(include Include) (string, error)

ResolveIncludePath resolves a module + path combination to a full file path

func (*ModuleResolver) ResolveModulePath

func (mr *ModuleResolver) ResolveModulePath(modulePath string) (string, error)

ResolveModulePath resolves a Go module path to a filesystem directory. Resolution order: go.mod replace directives, go.work workspace members, then the Go module cache under GOPATH.

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser handles YAML schema parsing and validation

func NewParser

func NewParser(verbose bool) *Parser

NewParser creates a new YAML parser

func (*Parser) FormatValidationErrors

func (p *Parser) FormatValidationErrors(errors []ValidationError) string

FormatValidationErrors formats validation errors for display

func (*Parser) GetDefaultValue

func (p *Parser) GetDefaultValue(schema *Schema, dbType DatabaseType, defaultKey string) (string, error)

GetDefaultValue gets the default value for a database type

func (*Parser) ParseAndValidate

func (p *Parser) ParseAndValidate(content string) (*Schema, error)

ParseAndValidate parses and fully validates a YAML schema

func (*Parser) ParseSchema

func (p *Parser) ParseSchema(content string) (*Schema, error)

ParseSchema parses a YAML schema string into a Schema struct

func (*Parser) ParseSchemaFile

func (p *Parser) ParseSchemaFile(filePath string) (*Schema, error)

ParseSchemaFile parses a YAML schema file and processes includes

func (*Parser) ParseSchemaFileWithContent

func (p *Parser) ParseSchemaFileWithContent(content, filePath string) (*Schema, error)

ParseSchemaFileWithContent parses YAML content and processes includes

func (*Parser) ValidateComprehensive

func (p *Parser) ValidateComprehensive(schema *Schema, databaseType DatabaseType) []ValidationError

ValidateComprehensive performs all validation checks with detailed error reporting

func (*Parser) ValidateDatabaseSpecificRules

func (p *Parser) ValidateDatabaseSpecificRules(schema *Schema, databaseType DatabaseType) error

ValidateDatabaseSpecificRules validates database-specific rules

func (*Parser) ValidateForeignKeyReferences

func (p *Parser) ValidateForeignKeyReferences(schema *Schema) error

ValidateForeignKeyReferences validates that all foreign key references exist

func (*Parser) ValidateSchemaStructure

func (p *Parser) ValidateSchemaStructure(schema *Schema) error

ValidateSchemaStructure performs additional structural validation

type PromptFunc

type PromptFunc func(sqlStmt string, change Change) (PromptResponse, error)

PromptFunc is called when a destructive operation is detected during SQL conversion. It receives the SQL statement and change details, and returns the user's choice. Implementations can use any UI (bubbletea TUI, plain stdin, etc.).

type PromptResponse

type PromptResponse int

PromptResponse represents the user's response to a destructive operation prompt

const (
	PromptGenerate     PromptResponse = 1 // Generate SQL without any prefix
	PromptReview       PromptResponse = 2 // Mark for review (use review prefix)
	PromptOmit         PromptResponse = 3 // Don't generate statement (omit from output)
	PromptExit         PromptResponse = 4 // Exit migration generation
	PromptGenerateAll  PromptResponse = 5 // Generate all remaining destructive operations without prompting
	PromptIgnoreErrors PromptResponse = 6 // Generate with IgnoreErrors: true (runner continues on failure)
)

type SQLConverter

type SQLConverter struct {
	// contains filtered or unexported fields
}

SQLConverter converts YAML schema definitions to database-specific SQL DDL.

Per-change-type operation handlers live in sql_operations.go. Review comment logic lives in sql_review.go.

func NewSQLConverter

func NewSQLConverter(databaseType DatabaseType, verbose bool) *SQLConverter

NewSQLConverter creates a new SQL converter

func NewSQLConverterWithConfig

func NewSQLConverterWithConfig(databaseType DatabaseType, verbose bool, safeTypeChanges bool, reviewPrefix string, destructiveOps []string, silent bool, rejectionPrefix string, promptFn ...PromptFunc) *SQLConverter

NewSQLConverterWithConfig creates a new SQL converter with full configuration. The promptFn parameter is called for destructive operations. When nil or when silent is true, destructive operations default to PromptReview (mark for review).

func NewSQLConverterWithOptions

func NewSQLConverterWithOptions(databaseType DatabaseType, verbose bool, safeTypeChanges bool) *SQLConverter

NewSQLConverterWithOptions creates a new SQL converter with configuration options

func (*SQLConverter) ConvertDiffToSQL

func (sc *SQLConverter) ConvertDiffToSQL(diff *SchemaDiff, oldSchema, newSchema *Schema) (upSQL, downSQL string, err error)

ConvertDiffToSQL converts a YAML schema diff to SQL migration statements

func (*SQLConverter) ConvertSchema

func (sc *SQLConverter) ConvertSchema(schema *Schema) (string, error)

ConvertSchema converts a complete YAML schema to SQL DDL statements

func (*SQLConverter) ConvertTable

func (sc *SQLConverter) ConvertTable(schema *Schema, table *Table) (string, error)

ConvertTable converts a single YAML table definition to SQL CREATE TABLE statement

type Schema

type Schema = types.Schema

Schema is an alias for types.Schema for backwards compatibility.

type SchemaDiff

type SchemaDiff struct {
	Changes       []Change `json:"changes"`
	HasChanges    bool     `json:"has_changes"`
	IsDestructive bool     `json:"is_destructive"`
}

SchemaDiff represents the complete difference between two schemas

type StateManager

type StateManager struct {
	// contains filtered or unexported fields
}

StateManager handles YAML schema state management

func NewStateManager

func NewStateManager(verbose bool) *StateManager

NewStateManager creates a new YAML state manager

func (*StateManager) BackupSnapshot

func (sm *StateManager) BackupSnapshot(migrationsDir string) error

BackupSnapshot creates a backup of the current snapshot

func (*StateManager) CompareSnapshots

func (sm *StateManager) CompareSnapshots(schema1, schema2 *Schema) bool

CompareSnapshots compares two schema snapshots and returns whether they are equivalent

func (*StateManager) CreateInitialSnapshot

func (sm *StateManager) CreateInitialSnapshot(databaseName string, migrationsDir string) error

CreateInitialSnapshot creates an initial empty schema snapshot

func (*StateManager) GetSnapshotPath

func (sm *StateManager) GetSnapshotPath(migrationsDir string) string

GetSnapshotPath returns the path to the schema snapshot file

func (*StateManager) LoadSchemaSnapshot

func (sm *StateManager) LoadSchemaSnapshot(migrationsDir string) (*Schema, error)

LoadSchemaSnapshot loads a YAML schema from the .schema_snapshot.yaml file

func (*StateManager) SaveSchemaSnapshot

func (sm *StateManager) SaveSchemaSnapshot(schema *Schema, migrationsDir string) error

SaveSchemaSnapshot saves a YAML schema to the .schema_snapshot.yaml file

func (*StateManager) SchemaSnapshotExists

func (sm *StateManager) SchemaSnapshotExists(migrationsDir string) bool

SchemaSnapshotExists checks if a schema snapshot file exists

func (*StateManager) ValidateSnapshot

func (sm *StateManager) ValidateSnapshot(migrationsDir string) error

ValidateSnapshot validates that a snapshot file is valid YAML schema

type Table

type Table = types.Table

Table is an alias for types.Table for backwards compatibility.

type TypeMappings

type TypeMappings = types.TypeMappings

TypeMappings is an alias for types.TypeMappings for backwards compatibility.

type ValidationError

type ValidationError struct {
	Type     string // "schema", "structure", "foreign_key", "database_specific"
	Table    string
	Field    string
	Message  string
	Severity string // "error", "warning"
}

ValidationError represents a validation error with context

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL