Documentation
¶
Overview ¶
operations.go defines the Operation interface and all 10 concrete migration operation types used by the makemigrations Go migration framework.
Package migrate provides the runtime library for the makemigrations Go migration framework. Generated migration files import this package and call Register() in their init() functions.
Index ¶
- func EnvOr(name, defaultVal string) string
- func Register(m *Migration)
- func RenderDAGASCII(out *DAGOutput) string
- type AddField
- func (op *AddField) Describe() string
- func (op *AddField) Down(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
- func (op *AddField) IsDestructive() bool
- func (op *AddField) Mutate(state *SchemaState) error
- func (op *AddField) TableName() string
- func (op *AddField) TypeName() string
- func (op *AddField) Up(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
- type AddIndex
- func (op *AddIndex) Describe() string
- func (op *AddIndex) Down(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
- func (op *AddIndex) IsDestructive() bool
- func (op *AddIndex) Mutate(state *SchemaState) error
- func (op *AddIndex) TableName() string
- func (op *AddIndex) TypeName() string
- func (op *AddIndex) Up(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
- type AlterField
- func (op *AlterField) Describe() string
- func (op *AlterField) Down(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
- func (op *AlterField) IsDestructive() bool
- func (op *AlterField) Mutate(state *SchemaState) error
- func (op *AlterField) TableName() string
- func (op *AlterField) TypeName() string
- func (op *AlterField) Up(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
- type App
- type Config
- type CreateTable
- func (op *CreateTable) Describe() string
- func (op *CreateTable) Down(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
- func (op *CreateTable) IsDestructive() bool
- func (op *CreateTable) Mutate(state *SchemaState) error
- func (op *CreateTable) TableName() string
- func (op *CreateTable) TypeName() string
- func (op *CreateTable) Up(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
- type DAGOutput
- type DropField
- func (op *DropField) Describe() string
- func (op *DropField) Down(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
- func (op *DropField) IsDestructive() bool
- func (op *DropField) Mutate(state *SchemaState) error
- func (op *DropField) TableName() string
- func (op *DropField) TypeName() string
- func (op *DropField) Up(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
- type DropIndex
- func (op *DropIndex) Describe() string
- func (op *DropIndex) Down(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
- func (op *DropIndex) IsDestructive() bool
- func (op *DropIndex) Mutate(state *SchemaState) error
- func (op *DropIndex) TableName() string
- func (op *DropIndex) TypeName() string
- func (op *DropIndex) Up(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
- type DropTable
- func (op *DropTable) Describe() string
- func (op *DropTable) Down(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
- func (op *DropTable) IsDestructive() bool
- func (op *DropTable) Mutate(state *SchemaState) error
- func (op *DropTable) TableName() string
- func (op *DropTable) TypeName() string
- func (op *DropTable) Up(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
- type Field
- type ForeignKey
- type Graph
- func (g *Graph) DetectBranches() [][]string
- func (g *Graph) HasBranches() bool
- func (g *Graph) Leaves() []string
- func (g *Graph) Linearize() ([]*Migration, error)
- func (g *Graph) ReconstructState() (*SchemaState, error)
- func (g *Graph) Roots() []string
- func (g *Graph) ToDAGOutput() (*DAGOutput, error)
- type Index
- type ManyToMany
- type Migration
- type MigrationRecorder
- type MigrationSummary
- type Operation
- type OperationSummary
- type Registry
- type RenameField
- func (op *RenameField) Describe() string
- func (op *RenameField) Down(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
- func (op *RenameField) IsDestructive() bool
- func (op *RenameField) Mutate(state *SchemaState) error
- func (op *RenameField) TableName() string
- func (op *RenameField) TypeName() string
- func (op *RenameField) Up(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
- type RenameTable
- func (op *RenameTable) Describe() string
- func (op *RenameTable) Down(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
- func (op *RenameTable) IsDestructive() bool
- func (op *RenameTable) Mutate(state *SchemaState) error
- func (op *RenameTable) TableName() string
- func (op *RenameTable) TypeName() string
- func (op *RenameTable) Up(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
- type RunSQL
- func (op *RunSQL) Describe() string
- func (op *RunSQL) Down(_ providers.Provider, _ *SchemaState, _ map[string]string) (string, error)
- func (op *RunSQL) IsDestructive() bool
- func (op *RunSQL) Mutate(_ *SchemaState) error
- func (op *RunSQL) TableName() string
- func (op *RunSQL) TypeName() string
- func (op *RunSQL) Up(_ providers.Provider, _ *SchemaState, _ map[string]string) (string, error)
- type Runner
- type SchemaState
- func (s *SchemaState) AddField(tableName string, field Field) error
- func (s *SchemaState) AddIndex(tableName string, index Index) error
- func (s *SchemaState) AddTable(name string, fields []Field, indexes []Index) error
- func (s *SchemaState) AlterField(tableName string, newField Field) error
- func (s *SchemaState) DropField(tableName, fieldName string) error
- func (s *SchemaState) DropIndex(tableName, indexName string) error
- func (s *SchemaState) DropTable(name string) error
- func (s *SchemaState) RenameField(tableName, oldName, newName string) error
- func (s *SchemaState) RenameTable(oldName, newName string) error
- type TableState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnvOr ¶
EnvOr returns the value of the named environment variable, or defaultVal if the variable is not set or empty.
func Register ¶
func Register(m *Migration)
Register adds a migration to the global registry. Called by each generated migration file's init() function. Panics on duplicates.
func RenderDAGASCII ¶
RenderDAGASCII produces a human-readable ASCII tree of the migration graph. It uses box-drawing characters to show parent->child relationships.
Types ¶
type AddField ¶
type AddField struct {
Table string
Field Field
SchemaOnly bool // when true, Up/Down return no SQL; Mutate still runs
}
AddField is a migration operation that adds a new column to an existing table. When SchemaOnly is true the operation advances the in-memory schema state (via Mutate) but does not execute any SQL, allowing the schema state to be seeded from an existing database without running ALTER TABLE ADD COLUMN.
func (*AddField) Down ¶
func (op *AddField) Down(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
Down generates the DROP COLUMN SQL to reverse the addition. Returns empty string when SchemaOnly is set.
func (*AddField) IsDestructive ¶
IsDestructive returns false — adding a column is not destructive.
func (*AddField) Mutate ¶
func (op *AddField) Mutate(state *SchemaState) error
Mutate adds the new field to the table's entry in SchemaState.
type AddIndex ¶
AddIndex is a migration operation that adds an index to an existing table.
func (*AddIndex) Down ¶
func (op *AddIndex) Down(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
Down generates the DROP INDEX SQL to reverse the index creation.
func (*AddIndex) IsDestructive ¶
IsDestructive returns false — adding an index is not destructive.
func (*AddIndex) Mutate ¶
func (op *AddIndex) Mutate(state *SchemaState) error
Mutate adds the index to the table's entry in SchemaState.
type AlterField ¶
AlterField is a migration operation that modifies an existing column's definition.
func (*AlterField) Describe ¶
func (op *AlterField) Describe() string
Describe returns a human-readable description of this operation.
func (*AlterField) Down ¶
func (op *AlterField) Down(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
Down generates the ALTER COLUMN SQL to restore the original field definition.
func (*AlterField) IsDestructive ¶
func (op *AlterField) IsDestructive() bool
IsDestructive returns false — altering a column is not considered destructive (though data conversion may fail at the database level for incompatible types).
func (*AlterField) Mutate ¶
func (op *AlterField) Mutate(state *SchemaState) error
Mutate replaces the field in the table's entry in SchemaState.
func (*AlterField) TableName ¶
func (op *AlterField) TableName() string
TableName returns the name of the table being altered.
func (*AlterField) TypeName ¶
func (op *AlterField) TypeName() string
TypeName returns the operation type identifier.
func (*AlterField) Up ¶
func (op *AlterField) Up(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
Up generates the ALTER COLUMN SQL to apply the new field definition.
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is the CLI application embedded in each compiled migration binary.
func NewApp ¶
NewApp creates a new App with the given configuration. It uses the global registry by default.
func NewAppWithRegistry ¶
NewAppWithRegistry creates a new App with the given configuration and a specific registry. This is primarily useful for testing.
type Config ¶
type Config struct {
DatabaseType string // postgresql, mysql, sqlserver, sqlite
DatabaseURL string // full DSN — overrides individual fields if set
DBHost string
DBPort string
DBUser string
DBPassword string
DBName string
DBSSLMode string
}
Config holds database connection configuration for the migration binary. All fields default to environment variables if not set explicitly.
type CreateTable ¶
type CreateTable struct {
Name string
Fields []Field
Indexes []Index
SchemaOnly bool // when true, Up/Down return no SQL; Mutate still runs
}
CreateTable is a migration operation that creates a new database table with the specified fields and indexes. When SchemaOnly is true the operation advances the in-memory schema state (via Mutate) but does not execute any SQL, allowing the schema state to be seeded from an existing database without re-running CREATE TABLE.
func (*CreateTable) Describe ¶
func (op *CreateTable) Describe() string
Describe returns a human-readable description of this operation.
func (*CreateTable) Down ¶
func (op *CreateTable) Down(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
Down generates the DROP TABLE SQL to reverse the creation. Returns empty string when SchemaOnly is set.
func (*CreateTable) IsDestructive ¶
func (op *CreateTable) IsDestructive() bool
IsDestructive returns false — creating a table is not destructive.
func (*CreateTable) Mutate ¶
func (op *CreateTable) Mutate(state *SchemaState) error
Mutate adds the new table to the SchemaState.
func (*CreateTable) TableName ¶
func (op *CreateTable) TableName() string
TableName returns the name of the table being created.
func (*CreateTable) TypeName ¶
func (op *CreateTable) TypeName() string
TypeName returns the operation type identifier.
func (*CreateTable) Up ¶
func (op *CreateTable) Up(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
Up generates the CREATE TABLE SQL statement, or returns empty string when SchemaOnly is set.
type DAGOutput ¶
type DAGOutput struct {
Migrations []MigrationSummary `json:"migrations"`
Roots []string `json:"roots"`
Leaves []string `json:"leaves"`
HasBranches bool `json:"has_branches"`
SchemaState *SchemaState `json:"schema_state"`
}
DAGOutput is the JSON-serialisable representation of the full migration graph. This is what the compiled migration binary emits via the `dag --format json` command.
type DropField ¶
type DropField struct {
Table string
Field string
SchemaOnly bool // when true, Up/Down return no SQL; Mutate still runs
}
DropField is a migration operation that removes a column from an existing table. When SchemaOnly is true the operation advances the in-memory schema state (via Mutate) but does not execute any SQL against the database, allowing the developer to acknowledge a removal in the schema definition without immediately dropping the live column.
func (*DropField) Down ¶
func (op *DropField) Down(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
Down reconstructs the ADD COLUMN SQL by reading the field's pre-drop state. Returns empty string when SchemaOnly is set.
func (*DropField) IsDestructive ¶
IsDestructive returns true — dropping a column causes data loss.
func (*DropField) Mutate ¶
func (op *DropField) Mutate(state *SchemaState) error
Mutate removes the field from the table's entry in SchemaState.
type DropIndex ¶
DropIndex is a migration operation that removes an index from an existing table.
func (*DropIndex) Down ¶
func (op *DropIndex) Down(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
Down reconstructs the CREATE INDEX SQL by reading the index's pre-drop state.
func (*DropIndex) IsDestructive ¶
IsDestructive returns false — dropping an index is not considered destructive.
func (*DropIndex) Mutate ¶
func (op *DropIndex) Mutate(state *SchemaState) error
Mutate removes the index from the table's entry in SchemaState.
type DropTable ¶
type DropTable struct {
Name string
SchemaOnly bool // when true, Up/Down return no SQL; Mutate still runs
}
DropTable is a migration operation that drops an existing database table. When SchemaOnly is true the operation advances the in-memory schema state (via Mutate) but does not execute any SQL against the database, allowing the developer to acknowledge a removal in the schema definition without immediately dropping the live table.
func (*DropTable) Down ¶
func (op *DropTable) Down(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
Down reconstructs the CREATE TABLE SQL by reading the table's pre-drop state. Returns empty string when SchemaOnly is set.
func (*DropTable) IsDestructive ¶
IsDestructive returns true — dropping a table causes data loss.
func (*DropTable) Mutate ¶
func (op *DropTable) Mutate(state *SchemaState) error
Mutate removes the table from the SchemaState.
type Field ¶
type Field struct {
Name string `json:"name"`
Type string `json:"type"` // varchar, text, integer, uuid, boolean, timestamp, foreign_key, etc.
PrimaryKey bool `json:"primary_key,omitempty"`
Nullable bool `json:"nullable,omitempty"`
Default string `json:"default,omitempty"` // default reference name e.g. "new_uuid", "now", "true"
Length int `json:"length,omitempty"` // for varchar
Precision int `json:"precision,omitempty"` // for decimal/numeric
Scale int `json:"scale,omitempty"` // for decimal/numeric
AutoCreate bool `json:"auto_create,omitempty"` // auto-set on row creation (created_at)
AutoUpdate bool `json:"auto_update,omitempty"` // auto-set on row update (updated_at)
ForeignKey *ForeignKey `json:"foreign_key,omitempty"`
ManyToMany *ManyToMany `json:"many_to_many,omitempty"`
}
Field represents a database column definition used in migration operations.
type ForeignKey ¶
type ForeignKey struct {
Table string `json:"table"`
OnDelete string `json:"on_delete,omitempty"`
OnUpdate string `json:"on_update,omitempty"`
}
ForeignKey represents a foreign key constraint.
type Graph ¶
type Graph struct {
// contains filtered or unexported fields
}
Graph is a directed acyclic graph (DAG) of migrations. Each node represents one migration; edges represent dependencies.
func BuildGraph ¶
BuildGraph constructs a Graph from a Registry. Returns an error if any dependency is missing or if a cycle is detected.
func (*Graph) DetectBranches ¶
DetectBranches returns groups of leaf migration names when there are multiple leaves (indicating concurrent development branches). Returns empty slice if the graph is linear.
func (*Graph) HasBranches ¶
HasBranches returns true if the graph contains any branching structure. This includes divergent branches (multiple leaves) and diamond topologies where a node has more than one child, even if the branches later converge.
func (*Graph) Leaves ¶
Leaves returns names of migrations that no other migration depends on (no children).
func (*Graph) Linearize ¶
Linearize returns all migrations in topological order using Kahn's algorithm. Deterministic: nodes at the same level are sorted by name.
func (*Graph) ReconstructState ¶
func (g *Graph) ReconstructState() (*SchemaState, error)
ReconstructState replays all operations in topological order to produce the full schema state as it would exist after all registered migrations have run.
func (*Graph) ToDAGOutput ¶
ToDAGOutput builds a DAGOutput from this graph, including the reconstructed schema state.
type Index ¶
type Index struct {
Name string `json:"name"`
Fields []string `json:"fields"`
Unique bool `json:"unique,omitempty"`
}
Index represents a database index definition.
type ManyToMany ¶
type ManyToMany struct {
Table string `json:"table"`
}
ManyToMany represents a many-to-many relationship via junction table.
type Migration ¶
type Migration struct {
Name string `json:"name"` // Unique identifier e.g. "0001_initial"
Dependencies []string `json:"dependencies"` // Names of migrations this depends on
Operations []Operation `json:"-"` // Ordered list of schema operations to apply
Replaces []string `json:"replaces,omitempty"` // For squashed migrations: names of migrations this replaces
}
Migration represents a single database migration with its name, dependencies, and operations.
type MigrationRecorder ¶
type MigrationRecorder struct {
// contains filtered or unexported fields
}
MigrationRecorder manages the makemigrations_history table. It records which migrations have been applied to the database.
func NewMigrationRecorder ¶
func NewMigrationRecorder(db *sql.DB) *MigrationRecorder
NewMigrationRecorder creates a new MigrationRecorder using the given db connection.
func (*MigrationRecorder) EnsureTable ¶
func (r *MigrationRecorder) EnsureTable() error
EnsureTable creates the makemigrations_history table if it does not exist.
func (*MigrationRecorder) Fake ¶
func (r *MigrationRecorder) Fake(name string) error
Fake inserts a migration name without executing any SQL. Used to mark migrations as applied when the database already has the schema.
func (*MigrationRecorder) GetApplied ¶
func (r *MigrationRecorder) GetApplied() (map[string]bool, error)
GetApplied returns a set of migration names that have been applied.
func (*MigrationRecorder) RecordApplied ¶
func (r *MigrationRecorder) RecordApplied(name string) error
RecordApplied inserts a migration name into the history table.
func (*MigrationRecorder) RecordRolledBack ¶
func (r *MigrationRecorder) RecordRolledBack(name string) error
RecordRolledBack removes a migration name from the history table.
type MigrationSummary ¶
type MigrationSummary struct {
Name string `json:"name"`
Dependencies []string `json:"dependencies"`
Operations []OperationSummary `json:"operations"`
}
MigrationSummary is a JSON-serialisable summary of a single migration.
type Operation ¶
type Operation interface {
// Up generates the forward SQL for this operation.
Up(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
// Down generates the reverse SQL to undo this operation.
Down(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
// Mutate applies this operation to the given SchemaState, updating the
// in-memory schema representation during migration graph traversal.
Mutate(state *SchemaState) error
// Describe returns a human-readable description of the operation.
Describe() string
// TypeName returns the operation type identifier (e.g. "create_table").
TypeName() string
// TableName returns the primary table this operation acts on, or "" for RunSQL.
TableName() string
// IsDestructive returns true if this operation may cause data loss.
IsDestructive() bool
}
Operation is the interface all migration operations must implement. Each operation can generate forward (Up) and reverse (Down) SQL, mutate the in-memory SchemaState for graph traversal, and describe itself for display. Up/Down method names align with the CLI commands `./migrate up` / `./migrate down`.
type OperationSummary ¶
type OperationSummary struct {
Type string `json:"type"`
Table string `json:"table,omitempty"`
Description string `json:"description"`
}
OperationSummary is a JSON-serialisable summary of a single operation.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry stores all registered migrations, preserving insertion order.
func GlobalRegistry ¶
func GlobalRegistry() *Registry
GlobalRegistry returns the global registry. Used by app.go to build the migration graph.
func NewRegistry ¶
func NewRegistry() *Registry
NewRegistry creates an empty Registry. Used for testing; generated migration files use the global registry.
type RenameField ¶
RenameField is a migration operation that renames a column in an existing table.
func (*RenameField) Describe ¶
func (op *RenameField) Describe() string
Describe returns a human-readable description of this operation.
func (*RenameField) Down ¶
func (op *RenameField) Down(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
Down generates the reverse RENAME COLUMN SQL to restore the original name.
func (*RenameField) IsDestructive ¶
func (op *RenameField) IsDestructive() bool
IsDestructive returns false — renaming a column is not destructive.
func (*RenameField) Mutate ¶
func (op *RenameField) Mutate(state *SchemaState) error
Mutate updates the field name in the table's entry in SchemaState.
func (*RenameField) TableName ¶
func (op *RenameField) TableName() string
TableName returns the name of the table being altered.
func (*RenameField) TypeName ¶
func (op *RenameField) TypeName() string
TypeName returns the operation type identifier.
func (*RenameField) Up ¶
func (op *RenameField) Up(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
Up generates the RENAME COLUMN SQL statement.
type RenameTable ¶
type RenameTable struct{ OldName, NewName string }
RenameTable is a migration operation that renames an existing database table.
func (*RenameTable) Describe ¶
func (op *RenameTable) Describe() string
Describe returns a human-readable description of this operation.
func (*RenameTable) Down ¶
func (op *RenameTable) Down(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
Down generates the reverse RENAME TABLE SQL to restore the original name.
func (*RenameTable) IsDestructive ¶
func (op *RenameTable) IsDestructive() bool
IsDestructive returns false — renaming a table is not destructive.
func (*RenameTable) Mutate ¶
func (op *RenameTable) Mutate(state *SchemaState) error
Mutate updates the SchemaState to reflect the renamed table.
func (*RenameTable) TableName ¶
func (op *RenameTable) TableName() string
TableName returns the old (pre-rename) table name.
func (*RenameTable) TypeName ¶
func (op *RenameTable) TypeName() string
TypeName returns the operation type identifier.
func (*RenameTable) Up ¶
func (op *RenameTable) Up(p providers.Provider, state *SchemaState, defaults map[string]string) (string, error)
Up generates the RENAME TABLE SQL statement.
type RunSQL ¶
type RunSQL struct {
// ForwardSQL is the raw SQL to execute on Up (forward migration).
ForwardSQL string
// BackwardSQL is the raw SQL to execute on Down (reverse migration).
BackwardSQL string
}
RunSQL is a migration operation that executes raw SQL for forward and reverse migrations. ForwardSQL and BackwardSQL field names are used (not Forward/Backward) to avoid conflict with the Up/Down method names on the Operation interface.
func (*RunSQL) IsDestructive ¶
IsDestructive returns false — RunSQL destructiveness depends on the SQL content.
func (*RunSQL) Mutate ¶
func (op *RunSQL) Mutate(_ *SchemaState) error
Mutate is a no-op for RunSQL — raw SQL does not alter the SchemaState.
func (*RunSQL) TableName ¶
TableName returns an empty string — RunSQL does not target a specific table.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner executes migrations against a database in topological order.
func NewRunner ¶
func NewRunner(graph *Graph, provider providers.Provider, db *sql.DB, recorder *MigrationRecorder) *Runner
NewRunner creates a Runner using the given graph, provider, db, and recorder.
func (*Runner) Down ¶
Down rolls back migrations. If steps > 0, rolls back that many. If to is set, rolls back until that migration name is reached (exclusive).
type SchemaState ¶
type SchemaState struct {
Tables map[string]*TableState `json:"tables"`
}
SchemaState holds the in-memory representation of the database schema at a specific point in the migration graph. Operations call Mutate() to update it as they are applied during graph traversal.
func NewSchemaState ¶
func NewSchemaState() *SchemaState
NewSchemaState returns an empty SchemaState.
func (*SchemaState) AddField ¶
func (s *SchemaState) AddField(tableName string, field Field) error
AddField appends a field to an existing table. Returns error if the field name already exists.
func (*SchemaState) AddIndex ¶
func (s *SchemaState) AddIndex(tableName string, index Index) error
AddIndex appends an index to an existing table. Returns error if the index name already exists.
func (*SchemaState) AddTable ¶
func (s *SchemaState) AddTable(name string, fields []Field, indexes []Index) error
AddTable adds a new table. Returns error if the table already exists.
func (*SchemaState) AlterField ¶
func (s *SchemaState) AlterField(tableName string, newField Field) error
AlterField replaces a field (matched by name) in an existing table.
func (*SchemaState) DropField ¶
func (s *SchemaState) DropField(tableName, fieldName string) error
DropField removes a named field from an existing table.
func (*SchemaState) DropIndex ¶
func (s *SchemaState) DropIndex(tableName, indexName string) error
DropIndex removes a named index from an existing table.
func (*SchemaState) DropTable ¶
func (s *SchemaState) DropTable(name string) error
DropTable removes a table. Returns error if the table does not exist.
func (*SchemaState) RenameField ¶
func (s *SchemaState) RenameField(tableName, oldName, newName string) error
RenameField renames a field within an existing table.
func (*SchemaState) RenameTable ¶
func (s *SchemaState) RenameTable(oldName, newName string) error
RenameTable renames a table. Returns error if old name does not exist or new name already exists.
type TableState ¶
type TableState struct {
Name string `json:"name"`
Fields []Field `json:"fields"`
Indexes []Index `json:"indexes"`
}
TableState holds the state of a single table.