diff

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package diff provides schema comparison and migration generation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(db *sql.DB, schemaDir string, opts ApplyOptions) error

Apply applies schema changes to a database

func GenerateSQL

func GenerateSQL(changes []Change) string

GenerateSQL generates a complete migration script

func HasDestructive

func HasDestructive(changes []Change) bool

HasDestructive returns true if any changes are destructive

Types

type ApplyOptions

type ApplyOptions struct {
	DryRun          bool
	SkipDestructive bool
	BackupPath      string // Path to create backup (empty = no backup)
}

ApplyOptions configures how changes are applied

type Change

type Change struct {
	Type        ChangeType
	Object      string   // Name of the object being changed
	Description string   // Human-readable description
	SQL         []string // SQL statements to apply
	Destructive bool     // Whether this change may lose data
}

Change represents a single schema change

func Compare

func Compare(db *sql.DB, schemaDir string) ([]Change, error)

Compare compares a database against a schema directory and returns changes. If SetBaseFS was called, reads from the embedded filesystem instead.

func CompareDatabases

func CompareDatabases(from, to *sql.DB) ([]Change, error)

CompareDatabases compares two databases

func Diff

func Diff(from, to *schema.Database) []Change

Diff compares two schemas and returns the changes

type ChangeType

type ChangeType string

ChangeType represents the type of schema change

const (
	CreateTable   ChangeType = "CREATE_TABLE"
	DropTable     ChangeType = "DROP_TABLE"
	AddColumn     ChangeType = "ADD_COLUMN"
	RecreateTable ChangeType = "RECREATE_TABLE"
	CreateIndex   ChangeType = "CREATE_INDEX"
	DropIndex     ChangeType = "DROP_INDEX"
	CreateView    ChangeType = "CREATE_VIEW"
	DropView      ChangeType = "DROP_VIEW"
	CreateTrigger ChangeType = "CREATE_TRIGGER"
	DropTrigger   ChangeType = "DROP_TRIGGER"
)

Jump to

Keyboard shortcuts

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