Documentation
¶
Overview ¶
Package checkmigration: Database schema migration validation and SQL generation engine Performs intelligent comparison between GORM model definitions and actual database schemas Captures and parses SQL statements from GORM's DryRun mode to identify migration requirements Generates both forward and reverse migration scripts with proper categorization
checkmigration: 数据库结构迁移验证和 SQL 生成引擎 在 GORM 模型定义与实际数据库结构之间执行智能比较 从 GORM 的 DryRun 模式捕获和解析 SQL 语句,识别迁移需求 生成正向和反向迁移脚本,并进行适当分类
Index ¶
- func CheckMigrate(db *gorm.DB, objects []interface{}) []string
- type CustomLogger
- func (c *CustomLogger) Error(_ context.Context, msg string, data ...interface{})
- func (c *CustomLogger) Info(_ context.Context, msg string, data ...interface{})
- func (c *CustomLogger) LogMode(level logger.LogLevel) logger.Interface
- func (c *CustomLogger) Trace(_ context.Context, begin time.Time, fc func() (string, int64), err error)
- func (c *CustomLogger) Warn(_ context.Context, msg string, data ...interface{})
- type MigrationKind
- type MigrationOp
- type MigrationOps
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckMigrate ¶
CheckMigrate compares database schema against GORM models and returns missing SQL statements Performs comprehensive analysis to identify required database migrations Returns list of forward SQL statements that need to be executed
CheckMigrate 对比数据库结构与 GORM 模型,返回缺失的 SQL 语句 执行全面分析来识别所需的数据库迁移 返回需要执行的正向 SQL 语句列表
Types ¶
type CustomLogger ¶
type CustomLogger struct {
SQLs []string // Collection of captured SQL statements // 捕获的 SQL 语句集合
}
CustomLogger implements GORM logger interface to capture executed SQL statements Uses slice collection to record all SQL operations during DryRun mode Provides tracing capabilities for migration analysis and script generation
CustomLogger 实现 GORM 日志接口来捕获执行的 SQL 语句 使用切片集合在 DryRun 模式下记录所有 SQL 操作 为迁移分析和脚本生成提供跟踪功能
func (*CustomLogger) Error ¶
func (c *CustomLogger) Error(_ context.Context, msg string, data ...interface{})
func (*CustomLogger) Info ¶
func (c *CustomLogger) Info(_ context.Context, msg string, data ...interface{})
func (*CustomLogger) LogMode ¶
func (c *CustomLogger) LogMode(level logger.LogLevel) logger.Interface
type MigrationKind ¶ added in v0.0.11
type MigrationKind struct { ForwardSubstr string // SQL pattern for forward operation // 正向操作的 SQL 模式 ReverseSubstr string // SQL pattern for reverse operation // 反向操作的 SQL 模式 }
MigrationKind represents the type and characteristics of a database migration operation Contains substring patterns for identifying operation type and corresponding reverse operation Used for automated reverse script generation and operation categorization
MigrationKind 表示数据库迁移操作的类型和特征 包含用于识别操作类型和对应反向操作的子字符串模式 用于自动反向脚本生成和操作分类
type MigrationOp ¶ added in v0.0.11
type MigrationOp struct { ForwardSQL string // SQL statement for forward migration // 正向迁移的 SQL 语句 Kind *MigrationKind // Operation type and reverse pattern // 操作类型和反向模式 }
MigrationOp represents a single database migration operation with forward SQL and operation metadata Combines SQL statement with operation type information for comprehensive migration management Supports both forward execution and reverse script generation
MigrationOp 表示单个数据库迁移操作,包含正向 SQL 和操作元数据 将 SQL 语句与操作类型信息相结合,用于全面的迁移管理 支持正向执行和反向脚本生成
func NewMigrationOp ¶ added in v0.0.11
func NewMigrationOp(forwardSQL string) (*MigrationOp, bool)
NewMigrationOp creates migration operation from SQL statement by matching against known patterns Analyzes SQL content to determine operation type and appropriate reverse operation Returns migration operation instance and success flag
NewMigrationOp 通过与已知模式匹配,从 SQL 语句创建迁移操作 分析 SQL 内容来确定操作类型和适当的反向操作 返回迁移操作实例和成功标志
func (*MigrationOp) GetForwardSQL ¶ added in v0.0.11
func (op *MigrationOp) GetForwardSQL() string
func (*MigrationOp) GetReverseSQL ¶ added in v0.0.11
func (op *MigrationOp) GetReverseSQL() (string, bool)
type MigrationOps ¶ added in v0.0.11
type MigrationOps []*MigrationOp
MigrationOps represents a collection of migration operations with batch processing capabilities Provides methods for searching, SQL extraction, and script generation Supports both forward and reverse migration script creation
MigrationOps 表示具有批量处理功能的迁移操作集合 提供搜索、SQL 提取和脚本生成方法 支持正向和反向迁移脚本创建
func GetMigrateOps ¶ added in v0.0.11
func GetMigrateOps(db *gorm.DB, objects []interface{}) MigrationOps
GetMigrateOps analyzes GORM models and generates migration operations based on database differences Uses GORM DryRun mode with custom logger to capture SQL statements without execution Returns structured migration operations with both forward and reverse SQL scripts
GetMigrateOps 分析 GORM 模型并基于数据库差异生成迁移操作 使用 GORM DryRun 模式和自定义日志来捕获 SQL 语句而不执行 返回包含正向和反向 SQL 脚本的结构化迁移操作
func (MigrationOps) GetForwardSQLs ¶ added in v0.0.11
func (ops MigrationOps) GetForwardSQLs() []string
func (MigrationOps) GetForwardScript ¶ added in v0.0.11
func (ops MigrationOps) GetForwardScript() string
func (MigrationOps) GetReverseScript ¶ added in v0.0.11
func (ops MigrationOps) GetReverseScript() (string, bool)
func (MigrationOps) SearchOp ¶ added in v0.0.11
func (ops MigrationOps) SearchOp(forwardSQL string) *MigrationOp