Documentation
¶
Index ¶
- func ColumnToSQL(col Column) string
- func NotNullConstraintName(columnName string) string
- func TemporaryName(name string) string
- func TriggerFunctionName(tableName, columnName string) string
- func TriggerName(tableName, columnName string) string
- type CallbackFn
- type CheckConstraint
- type CheckConstraintError
- type Column
- type ColumnAlreadyExistsError
- type ColumnDoesNotExistError
- type ColumnIsNotNullableError
- type ColumnReferenceError
- type EmptyMigrationError
- type FieldRequiredError
- type ForeignKeyReference
- type IndexAlreadyExistsError
- type IndexDoesNotExistError
- type InvalidMigrationError
- type InvalidPrimaryKeyError
- type InvalidReplicaIdentityError
- type IsolatedOperation
- type Migration
- type MultipleAlterColumnChangesError
- type NoDownSQLAllowedError
- type NoUpSQLAllowedError
- type OpAddColumn
- func (o *OpAddColumn) Complete(ctx context.Context, conn *sql.DB) error
- func (o *OpAddColumn) Rollback(ctx context.Context, conn *sql.DB) error
- func (o *OpAddColumn) Start(ctx context.Context, conn *sql.DB, stateSchema string, s *schema.Schema, ...) error
- func (o *OpAddColumn) Validate(ctx context.Context, s *schema.Schema) error
- type OpAlterColumn
- func (o *OpAlterColumn) Complete(ctx context.Context, conn *sql.DB) error
- func (o *OpAlterColumn) Rollback(ctx context.Context, conn *sql.DB) error
- func (o *OpAlterColumn) Start(ctx context.Context, conn *sql.DB, stateSchema string, s *schema.Schema, ...) error
- func (o *OpAlterColumn) Validate(ctx context.Context, s *schema.Schema) error
- type OpChangeType
- func (o *OpChangeType) Complete(ctx context.Context, conn *sql.DB) error
- func (o *OpChangeType) Rollback(ctx context.Context, conn *sql.DB) error
- func (o *OpChangeType) Start(ctx context.Context, conn *sql.DB, stateSchema string, s *schema.Schema, ...) error
- func (o *OpChangeType) Validate(ctx context.Context, s *schema.Schema) error
- type OpCreateIndex
- func (o *OpCreateIndex) Complete(ctx context.Context, conn *sql.DB) error
- func (o *OpCreateIndex) Rollback(ctx context.Context, conn *sql.DB) error
- func (o *OpCreateIndex) Start(ctx context.Context, conn *sql.DB, stateSchema string, s *schema.Schema, ...) error
- func (o *OpCreateIndex) Validate(ctx context.Context, s *schema.Schema) error
- type OpCreateTable
- func (o *OpCreateTable) Complete(ctx context.Context, conn *sql.DB) error
- func (o *OpCreateTable) Rollback(ctx context.Context, conn *sql.DB) error
- func (o *OpCreateTable) Start(ctx context.Context, conn *sql.DB, stateSchema string, s *schema.Schema, ...) error
- func (o *OpCreateTable) Validate(ctx context.Context, s *schema.Schema) error
- type OpDropColumn
- func (o *OpDropColumn) Complete(ctx context.Context, conn *sql.DB) error
- func (o *OpDropColumn) Rollback(ctx context.Context, conn *sql.DB) error
- func (o *OpDropColumn) Start(ctx context.Context, conn *sql.DB, stateSchema string, s *schema.Schema, ...) error
- func (o *OpDropColumn) Validate(ctx context.Context, s *schema.Schema) error
- type OpDropConstraint
- func (o *OpDropConstraint) Complete(ctx context.Context, conn *sql.DB) error
- func (o *OpDropConstraint) Rollback(ctx context.Context, conn *sql.DB) error
- func (o *OpDropConstraint) Start(ctx context.Context, conn *sql.DB, stateSchema string, s *schema.Schema, ...) error
- func (o *OpDropConstraint) Validate(ctx context.Context, s *schema.Schema) error
- type OpDropIndex
- func (o *OpDropIndex) Complete(ctx context.Context, conn *sql.DB) error
- func (o *OpDropIndex) Rollback(ctx context.Context, conn *sql.DB) error
- func (o *OpDropIndex) Start(ctx context.Context, conn *sql.DB, stateSchema string, s *schema.Schema, ...) error
- func (o *OpDropIndex) Validate(ctx context.Context, s *schema.Schema) error
- type OpDropTable
- func (o *OpDropTable) Complete(ctx context.Context, conn *sql.DB) error
- func (o *OpDropTable) Rollback(ctx context.Context, conn *sql.DB) error
- func (o *OpDropTable) Start(ctx context.Context, conn *sql.DB, stateSchema string, s *schema.Schema, ...) error
- func (o *OpDropTable) Validate(ctx context.Context, s *schema.Schema) error
- type OpName
- type OpRawSQL
- func (o *OpRawSQL) Complete(ctx context.Context, conn *sql.DB) error
- func (o *OpRawSQL) IsIsolated()
- func (o *OpRawSQL) RequiresSchemaRefresh()
- func (o *OpRawSQL) Rollback(ctx context.Context, conn *sql.DB) error
- func (o *OpRawSQL) Start(ctx context.Context, conn *sql.DB, stateSchema string, s *schema.Schema, ...) error
- func (o *OpRawSQL) Validate(ctx context.Context, s *schema.Schema) error
- type OpRenameColumn
- func (o *OpRenameColumn) Complete(ctx context.Context, conn *sql.DB) error
- func (o *OpRenameColumn) Rollback(ctx context.Context, conn *sql.DB) error
- func (o *OpRenameColumn) Start(ctx context.Context, conn *sql.DB, stateSchema string, s *schema.Schema, ...) error
- func (o *OpRenameColumn) Validate(ctx context.Context, s *schema.Schema) error
- type OpRenameTable
- func (o *OpRenameTable) Complete(ctx context.Context, conn *sql.DB) error
- func (o *OpRenameTable) Rollback(ctx context.Context, conn *sql.DB) error
- func (o *OpRenameTable) Start(ctx context.Context, conn *sql.DB, stateSchema string, s *schema.Schema, ...) error
- func (o *OpRenameTable) Validate(ctx context.Context, s *schema.Schema) error
- type OpSetCheckConstraint
- func (o *OpSetCheckConstraint) Complete(ctx context.Context, conn *sql.DB) error
- func (o *OpSetCheckConstraint) Rollback(ctx context.Context, conn *sql.DB) error
- func (o *OpSetCheckConstraint) Start(ctx context.Context, conn *sql.DB, stateSchema string, s *schema.Schema, ...) error
- func (o *OpSetCheckConstraint) Validate(ctx context.Context, s *schema.Schema) error
- type OpSetForeignKey
- func (o *OpSetForeignKey) Complete(ctx context.Context, conn *sql.DB) error
- func (o *OpSetForeignKey) Rollback(ctx context.Context, conn *sql.DB) error
- func (o *OpSetForeignKey) Start(ctx context.Context, conn *sql.DB, stateSchema string, s *schema.Schema, ...) error
- func (o *OpSetForeignKey) Validate(ctx context.Context, s *schema.Schema) error
- type OpSetNotNull
- func (o *OpSetNotNull) Complete(ctx context.Context, conn *sql.DB) error
- func (o *OpSetNotNull) Rollback(ctx context.Context, conn *sql.DB) error
- func (o *OpSetNotNull) Start(ctx context.Context, conn *sql.DB, stateSchema string, s *schema.Schema, ...) error
- func (o *OpSetNotNull) Validate(ctx context.Context, s *schema.Schema) error
- type OpSetReplicaIdentity
- func (o *OpSetReplicaIdentity) Complete(ctx context.Context, conn *sql.DB) error
- func (o *OpSetReplicaIdentity) Rollback(ctx context.Context, conn *sql.DB) error
- func (o *OpSetReplicaIdentity) Start(ctx context.Context, conn *sql.DB, stateSchema string, s *schema.Schema, ...) error
- func (o *OpSetReplicaIdentity) Validate(ctx context.Context, s *schema.Schema) error
- type OpSetUnique
- func (o *OpSetUnique) Complete(ctx context.Context, conn *sql.DB) error
- func (o *OpSetUnique) Rollback(ctx context.Context, conn *sql.DB) error
- func (o *OpSetUnique) Start(ctx context.Context, conn *sql.DB, stateSchema string, s *schema.Schema, ...) error
- func (o *OpSetUnique) Validate(ctx context.Context, s *schema.Schema) error
- type Operation
- type Operations
- type PgRollMigration
- type ReplicaIdentity
- type RequiresSchemaRefreshOperation
- type TableAlreadyExistsError
- type TableDoesNotExistError
- type TriggerDirection
- type UniqueConstraint
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ColumnToSQL ¶
func NotNullConstraintName ¶
func TemporaryName ¶
func TriggerFunctionName ¶
func TriggerName ¶
Types ¶
type CallbackFn ¶ added in v0.2.0
type CallbackFn func(int64)
type CheckConstraint ¶
type CheckConstraint struct {
// Constraint expression
Constraint string `json:"constraint"`
// Name of check constraint
Name string `json:"name"`
}
Check constraint definition
func (*CheckConstraint) Validate ¶
func (c *CheckConstraint) Validate() error
type CheckConstraintError ¶
func (CheckConstraintError) Error ¶
func (e CheckConstraintError) Error() string
func (CheckConstraintError) Unwrap ¶
func (e CheckConstraintError) Unwrap() error
type Column ¶
type Column struct {
// Check constraint for the column
Check *CheckConstraint `json:"check,omitempty"`
// Default value for the column
Default *string `json:"default,omitempty"`
// Name of the column
Name string `json:"name"`
// Indicates if the column is nullable
Nullable bool `json:"nullable"`
// Indicates if the column is part of the primary key
Pk bool `json:"pk"`
// Foreign key constraint for the column
References *ForeignKeyReference `json:"references,omitempty"`
// Postgres type of the column
Type string `json:"type"`
// Indicates if the column values must be unique
Unique bool `json:"unique"`
}
Column definition
type ColumnAlreadyExistsError ¶
func (ColumnAlreadyExistsError) Error ¶
func (e ColumnAlreadyExistsError) Error() string
type ColumnDoesNotExistError ¶
func (ColumnDoesNotExistError) Error ¶
func (e ColumnDoesNotExistError) Error() string
type ColumnIsNotNullableError ¶
func (ColumnIsNotNullableError) Error ¶
func (e ColumnIsNotNullableError) Error() string
type ColumnReferenceError ¶
func (ColumnReferenceError) Error ¶
func (e ColumnReferenceError) Error() string
func (ColumnReferenceError) Unwrap ¶
func (e ColumnReferenceError) Unwrap() error
type EmptyMigrationError ¶
type EmptyMigrationError struct{}
func (EmptyMigrationError) Error ¶
func (e EmptyMigrationError) Error() string
type FieldRequiredError ¶
type FieldRequiredError struct {
Name string
}
func (FieldRequiredError) Error ¶
func (e FieldRequiredError) Error() string
type ForeignKeyReference ¶
type ForeignKeyReference struct {
// Name of the referenced column
Column string `json:"column"`
// Name of the foreign key constraint
Name string `json:"name"`
// Name of the referenced table
Table string `json:"table"`
}
Foreign key reference definition
type IndexAlreadyExistsError ¶
type IndexAlreadyExistsError struct {
Name string
}
func (IndexAlreadyExistsError) Error ¶
func (e IndexAlreadyExistsError) Error() string
type IndexDoesNotExistError ¶
type IndexDoesNotExistError struct {
Name string
}
func (IndexDoesNotExistError) Error ¶
func (e IndexDoesNotExistError) Error() string
type InvalidMigrationError ¶
type InvalidMigrationError struct {
Reason string
}
func (InvalidMigrationError) Error ¶
func (e InvalidMigrationError) Error() string
type InvalidPrimaryKeyError ¶ added in v0.2.0
func (InvalidPrimaryKeyError) Error ¶ added in v0.2.0
func (e InvalidPrimaryKeyError) Error() string
type InvalidReplicaIdentityError ¶ added in v0.4.0
func (InvalidReplicaIdentityError) Error ¶ added in v0.4.0
func (e InvalidReplicaIdentityError) Error() string
type IsolatedOperation ¶
type IsolatedOperation interface {
IsIsolated()
}
IsolatedOperation is an operation that cannot be executed with other operations in the same migration
type Migration ¶
type Migration struct {
Name string `json:"name"`
Operations Operations `json:"operations"`
}
type MultipleAlterColumnChangesError ¶
type MultipleAlterColumnChangesError struct {
Changes int
}
func (MultipleAlterColumnChangesError) Error ¶
func (e MultipleAlterColumnChangesError) Error() string
type NoDownSQLAllowedError ¶
type NoDownSQLAllowedError struct{}
func (NoDownSQLAllowedError) Error ¶
func (e NoDownSQLAllowedError) Error() string
type NoUpSQLAllowedError ¶
type NoUpSQLAllowedError struct{}
func (NoUpSQLAllowedError) Error ¶
func (e NoUpSQLAllowedError) Error() string
type OpAddColumn ¶
type OpAddColumn struct {
// Column to add
Column Column `json:"column"`
// Name of the table
Table string `json:"table"`
// SQL expression for up migration
Up *string `json:"up,omitempty"`
}
Add column operation
type OpAlterColumn ¶
type OpAlterColumn struct {
// Add check constraint to the column
Check *CheckConstraint `json:"check,omitempty"`
// Name of the column
Column string `json:"column"`
// SQL expression for down migration
Down string `json:"down"`
// New name of the column (for rename column operation)
Name string `json:"name"`
// Indicates if the column is nullable (for add not null constraint operation)
Nullable *bool `json:"nullable,omitempty"`
// Add foreign key constraint to the column
References *ForeignKeyReference `json:"references,omitempty"`
// Name of the table
Table string `json:"table"`
// New type of the column (for change type operation)
Type string `json:"type"`
// Add unique constraint to the column
Unique *UniqueConstraint `json:"unique,omitempty"`
// SQL expression for up migration
Up string `json:"up"`
}
Alter column operation
type OpChangeType ¶
type OpChangeType struct {
Table string `json:"table"`
Column string `json:"column"`
Type string `json:"type"`
Up string `json:"up"`
Down string `json:"down"`
}
type OpCreateIndex ¶
type OpCreateIndex struct {
// Names of columns on which to define the index
Columns []string `json:"columns"`
// Index name
Name string `json:"name"`
// Name of table on which to define the index
Table string `json:"table"`
}
Create index operation
type OpCreateTable ¶
type OpCreateTable struct {
// Columns corresponds to the JSON schema field "columns".
Columns []Column `json:"columns"`
// Name of the table
Name string `json:"name"`
}
Create table operation
type OpDropColumn ¶
type OpDropColumn struct {
// Name of the column
Column string `json:"column"`
// SQL expression for down migration
Down *string `json:"down,omitempty"`
// Name of the table
Table string `json:"table"`
}
Drop column operation
type OpDropConstraint ¶
type OpDropConstraint struct {
// Name of the column
Column string `json:"column"`
// SQL expression for down migration
Down string `json:"down"`
// Name of the constraint
Name string `json:"name"`
// Name of the table
Table string `json:"table"`
// SQL expression for up migration
Up string `json:"up"`
}
Drop constraint operation
type OpDropIndex ¶
type OpDropIndex struct {
// Index name
Name string `json:"name"`
}
Drop index operation
type OpDropTable ¶
type OpDropTable struct {
// Name of the table
Name string `json:"name"`
}
Drop table operation
type OpName ¶
type OpName string
const ( OpNameCreateTable OpName = "create_table" OpNameRenameTable OpName = "rename_table" OpNameDropTable OpName = "drop_table" OpNameAddColumn OpName = "add_column" OpNameDropColumn OpName = "drop_column" OpNameAlterColumn OpName = "alter_column" OpNameCreateIndex OpName = "create_index" OpNameDropIndex OpName = "drop_index" OpNameDropConstraint OpName = "drop_constraint" OpNameSetReplicaIdentity OpName = "set_replica_identity" OpRawSQLName OpName = "sql" // Internal operation types used by `alter_column` OpNameRenameColumn OpName = "rename_column" OpNameSetUnique OpName = "set_unique" OpNameSetNotNull OpName = "set_not_null" OpNameSetForeignKey OpName = "set_foreign_key" OpNameSetCheckConstraint OpName = "set_check_constraint" OpNameChangeType OpName = "change_type" )
func OperationName ¶
type OpRawSQL ¶
type OpRawSQL struct {
// SQL expression for down migration
Down string `json:"down,omitempty"`
// SQL expression for up migration
Up string `json:"up"`
}
Raw SQL operation
func (*OpRawSQL) IsIsolated ¶
func (o *OpRawSQL) IsIsolated()
this operation is isolated, cannot be executed with other operations
func (*OpRawSQL) RequiresSchemaRefresh ¶
func (o *OpRawSQL) RequiresSchemaRefresh()
this operation requires the resulting schema to be refreshed
type OpRenameColumn ¶
type OpRenameColumn struct {
Table string `json:"table"`
From string `json:"from"`
To string `json:"to"`
}
type OpRenameTable ¶
type OpRenameTable struct {
// Old name of the table
From string `json:"from"`
// New name of the table
To string `json:"to"`
}
Rename table operation
type OpSetCheckConstraint ¶
type OpSetCheckConstraint struct {
Table string `json:"table"`
Column string `json:"column"`
Check CheckConstraint `json:"check"`
Up string `json:"up"`
Down string `json:"down"`
}
type OpSetForeignKey ¶
type OpSetForeignKey struct {
Table string `json:"table"`
Column string `json:"column"`
References ForeignKeyReference `json:"references"`
Up string `json:"up"`
Down string `json:"down"`
}
type OpSetNotNull ¶
type OpSetNotNull struct {
Table string `json:"table"`
Column string `json:"column"`
Up string `json:"up"`
Down string `json:"down"`
}
type OpSetReplicaIdentity ¶ added in v0.4.0
type OpSetReplicaIdentity struct {
// Replica identity to set
Identity ReplicaIdentity `json:"identity"`
// Name of the table
Table string `json:"table"`
}
Set replica identity operation
type OpSetUnique ¶
type OpSetUnique struct {
Name string `json:"name"`
Table string `json:"table"`
Column string `json:"column"`
Up string `json:"up"`
Down string `json:"down"`
}
type Operation ¶
type Operation interface {
// Start will apply the required changes to enable supporting the new schema
// version in the database (through a view)
// update the given views to expose the new schema version
Start(ctx context.Context, conn *sql.DB, stateSchema string, s *schema.Schema, cbs ...CallbackFn) error
// Complete will update the database schema to match the current version
// after calling Start.
// This method should be called once the previous version is no longer used
Complete(ctx context.Context, conn *sql.DB) error
// Rollback will revert the changes made by Start. It is not possible to
// rollback a completed migration.
Rollback(ctx context.Context, conn *sql.DB) error
// Validate returns a descriptive error if the operation cannot be applied to the given schema
Validate(ctx context.Context, s *schema.Schema) error
}
type Operations ¶
type Operations []Operation
func (Operations) MarshalJSON ¶
func (v Operations) MarshalJSON() ([]byte, error)
MarshalJSON serializes the list of operations into a JSON array.
func (*Operations) UnmarshalJSON ¶
func (v *Operations) UnmarshalJSON(data []byte) error
UnmarshalJSON deserializes the list of operations from a JSON array.
type PgRollMigration ¶ added in v0.4.2
type PgRollMigration struct {
// Name of the migration
Name string `json:"name"`
// Operations corresponds to the JSON schema field "operations".
Operations []interface{} `json:"operations"`
}
PgRoll migration definition
type ReplicaIdentity ¶ added in v0.4.0
type ReplicaIdentity struct {
// Name of the index to use as replica identity
Index string `json:"index"`
// Type of replica identity
Type string `json:"type"`
}
Replica identity definition
type RequiresSchemaRefreshOperation ¶
type RequiresSchemaRefreshOperation interface {
RequiresSchemaRefresh()
}
RequiresSchemaRefreshOperation is an operation that requires the resulting schema to be refreshed
type TableAlreadyExistsError ¶
type TableAlreadyExistsError struct {
Name string
}
func (TableAlreadyExistsError) Error ¶
func (e TableAlreadyExistsError) Error() string
type TableDoesNotExistError ¶
type TableDoesNotExistError struct {
Name string
}
func (TableDoesNotExistError) Error ¶
func (e TableDoesNotExistError) Error() string
type TriggerDirection ¶
type TriggerDirection string
const ( TriggerDirectionUp TriggerDirection = "up" TriggerDirectionDown TriggerDirection = "down" )
type UniqueConstraint ¶
type UniqueConstraint struct {
// Name of unique constraint
Name string `json:"name"`
}
Unique constraint definition
func (*UniqueConstraint) Validate ¶
func (c *UniqueConstraint) Validate() error
Source Files
¶
- backfill.go
- check.go
- errors.go
- fk_reference.go
- migrations.go
- op_add_column.go
- op_alter_column.go
- op_change_type.go
- op_common.go
- op_create_index.go
- op_create_table.go
- op_drop_column.go
- op_drop_constraint.go
- op_drop_index.go
- op_drop_table.go
- op_raw_sql.go
- op_rename_column.go
- op_rename_table.go
- op_set_check.go
- op_set_fk.go
- op_set_notnull.go
- op_set_replica_identity.go
- op_set_unique.go
- trigger.go
- types.go
- unique.go