Documentation
¶
Overview ¶
Package diff compares GORM models with a live database and writes the difference as migration files (the same .up.sql / .down.sql format migrate.FromFS reads).
It detects new tables, added/removed/renamed columns and added/removed indexes. It deliberately does NOT detect column type or nullability changes (type names differ per database and would cause false positives); those are reported as warnings.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ColumnDef ¶
type ColumnDef struct {
Name string
Kind dialect.Kind
Length int
Precision int
Scale int
Unsigned bool
NotNull bool
Primary bool
Auto bool
Big bool
HasDefault bool
Default any
}
ColumnDef is a database-agnostic column description.
type Op ¶
type Op struct {
Kind OpKind
Table string
Def *TableDef // CreateTable
Column *ColumnDef // AddColumn
From string // RenameColumn old name; DropColumn name
To string // RenameColumn new name
Index *IndexDef // AddIndex / DropIndex
Note string // human hint, rendered as a SQL comment in the down file
}
Op is one planned change.
type Options ¶
type Options struct {
// AllowDestructive includes DropColumn and DropIndex in Ops.
AllowDestructive bool
// Renames maps "table.old_column" to "new_column" so a rename is not planned as drop+add.
Renames map[string]string
}
Options tune Generate.
type Plan ¶
type Plan struct {
Ops []Op
// Blocked holds destructive ops (drops) that were not applied because AllowDestructive is false.
Blocked []Op
Warnings []string
// contains filtered or unexported fields
}
Plan is the result of Generate.
func (Plan) Render ¶
Render returns the up and down SQL. Down statements are in reverse order; changes that cannot be reversed (dropped columns) appear as SQL comments.
func (Plan) WriteFiles ¶
WriteFiles writes <timestamp>_<name>.up.sql and .down.sql into dir and returns their paths. An empty plan writes nothing and returns (nil, nil).