Documentation
¶
Index ¶
- Variables
- func CollectFilesFromDir(dir fs.FS) ([]string, error)
- func DeletionName(name string) string
- func DuplicationName(name string) string
- func IsDuplicatedName(name string) bool
- func IsNotNullConstraintName(name string) bool
- func NewAddColumnAction(conn db.DB, table string, c Column, withPK bool) *addColumnAction
- func NewAddConstraintUsingUniqueIndex(conn db.DB, table, constraint, indexName string) *addConstraintUsingUniqueIndexAction
- func NewAddPrimaryKeyAction(conn db.DB, table, indexName string) *addPrimaryKeyAction
- func NewAlterSequenceOwnerAction(conn db.DB, table, from, to string) *alterSequenceOwnerAction
- func NewColumnDuplicator(conn db.DB, table *schema.Table, columns ...*schema.Column) *duplicator
- func NewCommentColumnAction(conn db.DB, table, column string, comment *string) *commentColumnAction
- func NewCommentTableAction(conn db.DB, table string, comment *string) *commentTableAction
- func NewCreateFKConstraintAction(conn db.DB, table, constraint string, columns []string, ...) *createFKConstraintAction
- func NewCreateIndexConcurrentlyAction(conn db.DB, table, name, method string, unique bool, columns []IndexField, ...) *createIndexConcurrentlyAction
- func NewCreateTableAction(conn db.DB, table, columns, constraints string) *createTableAction
- func NewCreateUniqueIndexConcurrentlyAction(conn db.DB, schemaName, indexName, tableName string, columnNames ...string) *createUniqueIndexConcurrentlyAction
- func NewDropColumnAction(conn db.DB, table string, columns ...string) *dropColumnAction
- func NewDropConstraintAction(conn db.DB, table, constraint string) *dropConstraintAction
- func NewDropDefaultValueAction(conn db.DB, table, column string) *dropDefaultAction
- func NewDropFunctionAction(conn db.DB, functions ...string) *dropFunctionAction
- func NewDropIndexAction(conn db.DB, name string) *dropIndexAction
- func NewRawSQLAction(conn db.DB, sql string) *rawSQLAction
- func NewRenameColumnAction(conn db.DB, table, from, to string) *renameColumnAction
- func NewRenameConstraintAction(conn db.DB, table, from, to string) *renameConstraintAction
- func NewRenameDuplicatedColumnAction(conn db.DB, table *schema.Table, column string) *renameDuplicatedColumnAction
- func NewRenameTableAction(conn db.DB, from, to string) *renameTableAction
- func NewSetDefaultValueAction(conn db.DB, table, column, defaultValue string) *setDefaultAction
- func NewSetNotNullAction(conn db.DB, table, column string) *setNotNullAction
- func NewSetReplicaIdentityAction(conn db.DB, table string, identityType, index string) *setReplicaIdentityAction
- func NewValidateConstraintAction(conn db.DB, table, constraint string) *validateConstraintAction
- func NotNullConstraintName(columnName string) string
- func StripDuplicationPrefix(name string) string
- func TemporaryName(name string) string
- func UniqueIndexName(columnName string) string
- func UpdateCreateIndexColumnsList(op map[string]any) (map[string]any, error)
- func UpdateCreateIndexColumnsMapToArray(ops map[string]any) (map[string]any, error)
- func ValidateIdentifierLength(name string) error
- type AlterColumnNoChangesError
- type CheckConstraint
- type CheckConstraintError
- type Column
- type ColumnAlreadyExistsError
- type ColumnDoesNotExistError
- type ColumnGenerated
- type ColumnGeneratedIdentity
- type ColumnGeneratedIdentityUserSpecifiedValues
- type ColumnIsInvalidError
- type ColumnIsNotNullableError
- type ColumnIsNullableError
- type ColumnMigrationMissingError
- type ColumnMigrationRedundantError
- type ColumnReferenceError
- type ColumnSQLWriter
- type Constraint
- type ConstraintAlreadyExistsError
- type ConstraintDoesNotExistError
- type ConstraintExclude
- type ConstraintIndexParameters
- type ConstraintSQLWriter
- func (w *ConstraintSQLWriter) WriteCheck(check string, noInherit bool) string
- func (w *ConstraintSQLWriter) WriteExclude(indexMethod, elements, predicate string) string
- func (w *ConstraintSQLWriter) WriteForeignKey(referencedTable string, referencedColumns []string, ...) string
- func (w *ConstraintSQLWriter) WritePrimaryKey() string
- func (w *ConstraintSQLWriter) WriteUnique(nullsNotDistinct bool) string
- type ConstraintType
- type Coordinator
- type CreateCheckConstraintAction
- type Createable
- type DBAction
- type DropTableAction
- type EmptyMigrationError
- type FieldRequiredError
- type FileUpdater
- type ForeignKeyAction
- type ForeignKeyMatchType
- type ForeignKeyReference
- type IndexAlreadyExistsError
- type IndexDoesNotExistError
- type IndexField
- type IndexFieldNulls
- type IndexFieldOpclass
- type IndexFieldSort
- type InvalidGeneratedColumnError
- type InvalidIdentifierLengthError
- type InvalidMigrationError
- type InvalidOnDeleteSetColumnError
- type InvalidOnDeleteSettingError
- type InvalidReplicaIdentityError
- type IsolatedOperation
- type Logger
- type Migration
- type MigrationFormat
- type MigrationWriter
- type MultiColumnConstraintsNotSupportedError
- type MultiColumnDownSQL
- type MultiColumnUpSQL
- type OpAddColumn
- func (o *OpAddColumn) Complete(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpAddColumn) Create()
- func (o *OpAddColumn) Rollback(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpAddColumn) Start(ctx context.Context, l Logger, conn db.DB, s *schema.Schema) (*StartResult, error)
- func (o *OpAddColumn) Validate(ctx context.Context, s *schema.Schema) error
- type OpAlterColumn
- func (o *OpAlterColumn) Complete(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpAlterColumn) Create()
- func (o *OpAlterColumn) Rollback(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpAlterColumn) Start(ctx context.Context, l Logger, conn db.DB, s *schema.Schema) (*StartResult, error)
- func (o *OpAlterColumn) Validate(ctx context.Context, s *schema.Schema) error
- type OpChangeType
- func (o *OpChangeType) Complete(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpChangeType) Rollback(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpChangeType) Start(ctx context.Context, l Logger, conn db.DB, s *schema.Schema) (*StartResult, error)
- func (o *OpChangeType) Validate(ctx context.Context, s *schema.Schema) error
- type OpCreateConstraint
- func (o *OpCreateConstraint) Complete(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpCreateConstraint) Create()
- func (o *OpCreateConstraint) Rollback(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpCreateConstraint) Start(ctx context.Context, l Logger, conn db.DB, s *schema.Schema) (*StartResult, error)
- func (o *OpCreateConstraint) Validate(ctx context.Context, s *schema.Schema) error
- type OpCreateConstraintIndexParameters
- type OpCreateConstraintType
- type OpCreateIndex
- func (o *OpCreateIndex) Complete(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpCreateIndex) Create()
- func (o *OpCreateIndex) Rollback(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpCreateIndex) Start(ctx context.Context, l Logger, conn db.DB, s *schema.Schema) (*StartResult, error)
- func (o *OpCreateIndex) Validate(ctx context.Context, s *schema.Schema) error
- type OpCreateIndexMethod
- type OpCreateTable
- func (o *OpCreateTable) Complete(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpCreateTable) Create()
- func (o *OpCreateTable) Rollback(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpCreateTable) Start(ctx context.Context, l Logger, conn db.DB, s *schema.Schema) (*StartResult, error)
- func (o *OpCreateTable) Validate(ctx context.Context, s *schema.Schema) error
- type OpDropColumn
- func (o *OpDropColumn) Complete(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpDropColumn) Create()
- func (o *OpDropColumn) Rollback(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpDropColumn) Start(ctx context.Context, l Logger, conn db.DB, s *schema.Schema) (*StartResult, error)
- func (o *OpDropColumn) Validate(ctx context.Context, s *schema.Schema) error
- type OpDropConstraint
- func (o *OpDropConstraint) Complete(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpDropConstraint) Rollback(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpDropConstraint) Start(ctx context.Context, l Logger, conn db.DB, s *schema.Schema) (*StartResult, error)
- func (o *OpDropConstraint) Validate(ctx context.Context, s *schema.Schema) error
- type OpDropIndex
- func (o *OpDropIndex) Complete(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpDropIndex) Create()
- func (o *OpDropIndex) Rollback(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpDropIndex) Start(ctx context.Context, l Logger, conn db.DB, s *schema.Schema) (*StartResult, error)
- func (o *OpDropIndex) Validate(ctx context.Context, s *schema.Schema) error
- type OpDropMultiColumnConstraint
- func (o *OpDropMultiColumnConstraint) Complete(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpDropMultiColumnConstraint) Create()
- func (o *OpDropMultiColumnConstraint) Rollback(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpDropMultiColumnConstraint) Start(ctx context.Context, l Logger, conn db.DB, s *schema.Schema) (*StartResult, error)
- func (o *OpDropMultiColumnConstraint) Validate(ctx context.Context, s *schema.Schema) error
- type OpDropNotNull
- func (o *OpDropNotNull) Complete(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpDropNotNull) Rollback(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpDropNotNull) Start(ctx context.Context, l Logger, conn db.DB, s *schema.Schema) (*StartResult, error)
- func (o *OpDropNotNull) Validate(ctx context.Context, s *schema.Schema) error
- type OpDropTable
- func (o *OpDropTable) Complete(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpDropTable) Create()
- func (o *OpDropTable) Rollback(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpDropTable) Start(ctx context.Context, l Logger, conn db.DB, s *schema.Schema) (*StartResult, error)
- func (o *OpDropTable) Validate(ctx context.Context, s *schema.Schema) error
- type OpName
- type OpRawSQL
- func (o *OpRawSQL) Complete(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpRawSQL) Create()
- func (o *OpRawSQL) IsIsolated() bool
- func (o *OpRawSQL) RequiresSchemaRefresh()
- func (o *OpRawSQL) Rollback(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpRawSQL) Start(ctx context.Context, l Logger, conn db.DB, s *schema.Schema) (*StartResult, error)
- func (o *OpRawSQL) Validate(ctx context.Context, s *schema.Schema) error
- type OpRenameColumn
- func (o *OpRenameColumn) Complete(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpRenameColumn) Create()
- func (o *OpRenameColumn) Rollback(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpRenameColumn) Start(ctx context.Context, l Logger, conn db.DB, s *schema.Schema) (*StartResult, error)
- func (o *OpRenameColumn) Validate(ctx context.Context, s *schema.Schema) error
- type OpRenameConstraint
- func (o *OpRenameConstraint) Complete(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpRenameConstraint) Create()
- func (o *OpRenameConstraint) Rollback(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpRenameConstraint) Start(ctx context.Context, l Logger, conn db.DB, s *schema.Schema) (*StartResult, error)
- func (o *OpRenameConstraint) Validate(ctx context.Context, s *schema.Schema) error
- type OpRenameTable
- func (o *OpRenameTable) Complete(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpRenameTable) Create()
- func (o *OpRenameTable) Rollback(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpRenameTable) Start(ctx context.Context, l Logger, conn db.DB, s *schema.Schema) (*StartResult, error)
- func (o *OpRenameTable) Validate(ctx context.Context, s *schema.Schema) error
- type OpSetCheckConstraint
- func (o *OpSetCheckConstraint) Complete(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpSetCheckConstraint) Rollback(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpSetCheckConstraint) Start(ctx context.Context, l Logger, conn db.DB, s *schema.Schema) (*StartResult, error)
- func (o *OpSetCheckConstraint) Validate(ctx context.Context, s *schema.Schema) error
- type OpSetComment
- func (o *OpSetComment) Complete(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpSetComment) Rollback(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpSetComment) Start(ctx context.Context, l Logger, conn db.DB, s *schema.Schema) (*StartResult, error)
- func (o *OpSetComment) Validate(ctx context.Context, s *schema.Schema) error
- type OpSetDefault
- func (o *OpSetDefault) Complete(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpSetDefault) Rollback(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpSetDefault) Start(ctx context.Context, l Logger, conn db.DB, s *schema.Schema) (*StartResult, error)
- func (o *OpSetDefault) Validate(ctx context.Context, s *schema.Schema) error
- type OpSetForeignKey
- func (o *OpSetForeignKey) Complete(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpSetForeignKey) Rollback(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpSetForeignKey) Start(ctx context.Context, l Logger, conn db.DB, s *schema.Schema) (*StartResult, error)
- func (o *OpSetForeignKey) Validate(ctx context.Context, s *schema.Schema) error
- type OpSetNotNull
- func (o *OpSetNotNull) Complete(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpSetNotNull) Rollback(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpSetNotNull) Start(ctx context.Context, l Logger, conn db.DB, s *schema.Schema) (*StartResult, error)
- func (o *OpSetNotNull) Validate(ctx context.Context, s *schema.Schema) error
- type OpSetReplicaIdentity
- func (o *OpSetReplicaIdentity) Complete(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpSetReplicaIdentity) Rollback(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpSetReplicaIdentity) Start(ctx context.Context, l Logger, conn db.DB, s *schema.Schema) (*StartResult, error)
- func (o *OpSetReplicaIdentity) Validate(ctx context.Context, s *schema.Schema) error
- type OpSetUnique
- func (o *OpSetUnique) Complete(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpSetUnique) Rollback(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
- func (o *OpSetUnique) Start(ctx context.Context, l Logger, conn db.DB, s *schema.Schema) (*StartResult, error)
- func (o *OpSetUnique) Validate(ctx context.Context, s *schema.Schema) error
- type Operation
- type Operations
- type PgRollMigration
- type PgRollOperation
- type PgRollOperations
- type PrimaryKeysAreAlreadySetError
- type RawMigration
- type ReplicaIdentity
- type RequiresSchemaRefreshOperation
- type StartResult
- type TableAlreadyExistsError
- type TableDoesNotExistError
- type TableForeignKeyReference
- type UnexpectedOnDeleteSetColumnError
- type UniqueConstraint
- type UpSQLMustBeColumnDefaultError
- type UpdaterFn
Constants ¶
This section is empty.
Variables ¶
var AllNonDeprecatedOperations = []string{ string(OpNameCreateTable), string(OpNameRenameTable), string(OpNameRenameColumn), string(OpNameDropTable), string(OpNameAddColumn), string(OpNameDropColumn), string(OpNameAlterColumn), string(OpNameCreateIndex), string(OpNameDropIndex), string(OpNameRenameConstraint), string(OpNameDropMultiColumnConstraint), string(OpRawSQLName), string(OpCreateConstraintName), }
AllNonDeprecatedOperations contains the list of operations that are not deprecated. These operations must implement migrations.Createable interface.
var ErrInvalidMigrationFormat = errors.New("invalid migration format")
Functions ¶
func CollectFilesFromDir ¶ added in v0.11.0
CollectFilesFromDir returns a list of migration files in a directory. The files are ordered based on the filename without the extension name.
func DeletionName ¶ added in v0.9.0
DeletionName returns the deleted name for a given name.
func DuplicationName ¶ added in v0.5.0
DuplicationName returns the name of a duplicated column.
func IsDuplicatedName ¶ added in v0.5.0
IsDuplicatedName returns true if the name is a duplicated column name.
func IsNotNullConstraintName ¶ added in v0.5.0
IsNotNullConstraintName returns true if the given name is a NOT NULL constraint name
func NewAddColumnAction ¶ added in v0.14.0
func NewAddConstraintUsingUniqueIndex ¶ added in v0.14.0
func NewAddPrimaryKeyAction ¶ added in v0.14.0
func NewAlterSequenceOwnerAction ¶ added in v0.13.0
func NewColumnDuplicator ¶ added in v0.5.0
NewColumnDuplicator creates a new Duplicator for a column.
func NewCommentColumnAction ¶ added in v0.11.0
func NewCommentTableAction ¶ added in v0.11.0
func NewCreateFKConstraintAction ¶ added in v0.13.0
func NewCreateIndexConcurrentlyAction ¶ added in v0.14.0
func NewCreateTableAction ¶ added in v0.11.0
func NewCreateUniqueIndexConcurrentlyAction ¶ added in v0.11.0
func NewDropColumnAction ¶ added in v0.11.0
func NewDropConstraintAction ¶ added in v0.13.0
func NewDropDefaultValueAction ¶ added in v0.14.0
func NewDropFunctionAction ¶ added in v0.11.0
func NewDropIndexAction ¶ added in v0.12.0
func NewRawSQLAction ¶ added in v0.14.0
func NewRenameColumnAction ¶ added in v0.11.0
func NewRenameConstraintAction ¶ added in v0.11.0
func NewRenameDuplicatedColumnAction ¶ added in v0.14.0
func NewRenameTableAction ¶ added in v0.14.0
func NewSetDefaultValueAction ¶ added in v0.14.0
func NewSetNotNullAction ¶ added in v0.14.0
func NewSetReplicaIdentityAction ¶ added in v0.14.0
func NewValidateConstraintAction ¶ added in v0.13.0
func NotNullConstraintName ¶
NotNullConstraintName returns the name of the NOT NULL constraint for the given column
func StripDuplicationPrefix ¶ added in v0.5.0
StripDuplicationPrefix removes the duplication prefix from a column name.
func TemporaryName ¶
TemporaryName returns a temporary name for a given name.
func UniqueIndexName ¶ added in v0.10.0
UniqueIndexName returns the name of the unique index for the given column
func UpdateCreateIndexColumnsList ¶ added in v0.14.0
UpdateCreateIndexColumnsList transforms create_index's columns attribute from a string list to the new array format, preserving order:
Old format:
columns: ["name", "email"]
New format:
columns: [{"column": "name"}, {"column": "email"}]
breaking change was released in v0.10.0 PR: https://github.com/xataio/pgroll/pull/697
func UpdateCreateIndexColumnsMapToArray ¶ added in v0.16.0
UpdateCreateIndexColumnsMapToArray transforms create_index's columns from map to array format:
Old format:
columns: {"name": {}, "email": {"sort": "DESC"}}
New format:
columns: [{"column": "name"}, {"column": "email", "sort": "DESC"}]
This Updater should run after UpdateCreateIndexColumnsList in the chain.
func ValidateIdentifierLength ¶ added in v0.8.0
ValidateIdentifierLength returns an error if the given name exceeds the maximum allowed length for a Postgres identifier.
Types ¶
type AlterColumnNoChangesError ¶ added in v0.6.0
func (AlterColumnNoChangesError) Error ¶ added in v0.6.0
func (e AlterColumnNoChangesError) Error() string
type CheckConstraint ¶
type CheckConstraint struct {
// Constraint expression
Constraint string `json:"constraint"`
// Name of check constraint
Name string `json:"name"`
// Do not propagate constraint to child tables
NoInherit bool `json:"no_inherit,omitempty"`
}
Check constraint definition
func (*CheckConstraint) Validate ¶
func (c *CheckConstraint) Validate() error
Validate checks that the CheckConstraint is valid
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"`
// Postgres comment for the column
Comment *string `json:"comment,omitempty"`
// Default value for the column
Default *string `json:"default,omitempty"`
// Generated column definition
Generated *ColumnGenerated `json:"generated,omitempty"`
// Name of the column
Name string `json:"name"`
// Indicates if the column is nullable
Nullable bool `json:"nullable,omitempty"`
// Indicates if the column is part of the primary key
Pk bool `json:"pk,omitempty"`
// 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,omitempty"`
}
Column definition
func (*Column) HasDefault ¶ added in v0.10.0
HasDefault returns true if the column has a default value
func (*Column) HasImplicitDefault ¶ added in v0.8.0
HasImplicitDefault returns true if the column has an implicit default value
func (*Column) IsNullable ¶ added in v0.5.0
IsNullable returns true if the column is nullable
func (*Column) IsPrimaryKey ¶ added in v0.5.0
IsPrimaryKey returns true if the column is part of the primary key
type ColumnAlreadyExistsError ¶
func (ColumnAlreadyExistsError) Error ¶
func (e ColumnAlreadyExistsError) Error() string
type ColumnDoesNotExistError ¶
func (ColumnDoesNotExistError) Error ¶
func (e ColumnDoesNotExistError) Error() string
type ColumnGenerated ¶ added in v0.9.0
type ColumnGenerated struct {
// Generation expression of the column
Expression string `json:"expression,omitempty"`
// Identity corresponds to the JSON schema field "identity".
Identity *ColumnGeneratedIdentity `json:"identity,omitempty"`
}
Generated column definition
type ColumnGeneratedIdentity ¶ added in v0.9.0
type ColumnGeneratedIdentity struct {
// Sequence options for identity column, same as in CREATE SEQUENCE
SequenceOptions string `json:"sequence_options,omitempty"`
// How to handle user specified values for identity column in INSERT and UPDATE
// statements
UserSpecifiedValues ColumnGeneratedIdentityUserSpecifiedValues `json:"user_specified_values,omitempty"`
}
type ColumnGeneratedIdentityUserSpecifiedValues ¶ added in v0.9.0
type ColumnGeneratedIdentityUserSpecifiedValues string
const ColumnGeneratedIdentityUserSpecifiedValuesALWAYS ColumnGeneratedIdentityUserSpecifiedValues = "ALWAYS"
const ColumnGeneratedIdentityUserSpecifiedValuesBYDEFAULT ColumnGeneratedIdentityUserSpecifiedValues = "BY DEFAULT"
type ColumnIsInvalidError ¶ added in v0.10.0
func (ColumnIsInvalidError) Error ¶ added in v0.10.0
func (e ColumnIsInvalidError) Error() string
type ColumnIsNotNullableError ¶
func (ColumnIsNotNullableError) Error ¶
func (e ColumnIsNotNullableError) Error() string
type ColumnIsNullableError ¶ added in v0.5.0
func (ColumnIsNullableError) Error ¶ added in v0.5.0
func (e ColumnIsNullableError) Error() string
type ColumnMigrationMissingError ¶ added in v0.8.0
func (ColumnMigrationMissingError) Error ¶ added in v0.8.0
func (e ColumnMigrationMissingError) Error() string
type ColumnMigrationRedundantError ¶ added in v0.8.0
func (ColumnMigrationRedundantError) Error ¶ added in v0.8.0
func (e ColumnMigrationRedundantError) Error() string
type ColumnReferenceError ¶
func (ColumnReferenceError) Error ¶
func (e ColumnReferenceError) Error() string
func (ColumnReferenceError) Unwrap ¶
func (e ColumnReferenceError) Unwrap() error
type ColumnSQLWriter ¶ added in v0.8.0
type ColumnSQLWriter struct {
WithPK bool
}
ColumnSQLWriter writes a column to SQL It can optionally include the primary key constraint When creating a table, the primary key constraint is not added to the column definition
type Constraint ¶ added in v0.9.0
type Constraint struct {
// Check constraint expression
Check string `json:"check,omitempty"`
// Columns to add constraint to
Columns []string `json:"columns,omitempty"`
// Deferable constraint
Deferrable bool `json:"deferrable,omitempty"`
// Exclude constraint definition
Exclude *ConstraintExclude `json:"exclude,omitempty"`
// IndexParameters corresponds to the JSON schema field "index_parameters".
IndexParameters *ConstraintIndexParameters `json:"index_parameters,omitempty"`
// Initially deferred constraint
InitiallyDeferred bool `json:"initially_deferred,omitempty"`
// Name of the constraint
Name string `json:"name"`
// Do not propagate constraint to child tables
NoInherit bool `json:"no_inherit,omitempty"`
// Nulls not distinct constraint
NullsNotDistinct bool `json:"nulls_not_distinct,omitempty"`
// Reference to the foreign key
References *TableForeignKeyReference `json:"references,omitempty"`
// Type of the constraint
Type ConstraintType `json:"type"`
}
Constraint definition
type ConstraintAlreadyExistsError ¶ added in v0.6.0
func (ConstraintAlreadyExistsError) Error ¶ added in v0.6.0
func (e ConstraintAlreadyExistsError) Error() string
type ConstraintDoesNotExistError ¶ added in v0.5.0
func (ConstraintDoesNotExistError) Error ¶ added in v0.5.0
func (e ConstraintDoesNotExistError) Error() string
type ConstraintExclude ¶ added in v0.9.0
type ConstraintExclude struct {
// Expressions of the exclude constraint
Elements string `json:"elements,omitempty"`
// Index method
IndexMethod string `json:"index_method,omitempty"`
// Predicate for the exclusion constraint
Predicate string `json:"predicate,omitempty"`
}
Exclude constraint definition
type ConstraintIndexParameters ¶ added in v0.9.0
type ConstraintIndexParameters struct {
// IncludeColumns corresponds to the JSON schema field "include_columns".
IncludeColumns []string `json:"include_columns,omitempty"`
// StorageParameters corresponds to the JSON schema field "storage_parameters".
StorageParameters string `json:"storage_parameters,omitempty"`
// Tablespace corresponds to the JSON schema field "tablespace".
Tablespace string `json:"tablespace,omitempty"`
}
type ConstraintSQLWriter ¶ added in v0.9.0
type ConstraintSQLWriter struct {
Name string
Columns []string
InitiallyDeferred bool
Deferrable bool
SkipValidation bool
// unique, exclude, primary key constraints support the following options
IncludeColumns []string
StorageParameters string
Tablespace string
}
ConstraintSQLWriter is a helper struct to write constraint SQL statements. It can generate SQL for unique, check, primary key, foreign key and exclude constraints. The generated SQL can be used in CREATE TABLE or ALTER TABLE statements both as an inline constraint or as a table level constraint.
func (*ConstraintSQLWriter) WriteCheck ¶ added in v0.9.0
func (w *ConstraintSQLWriter) WriteCheck(check string, noInherit bool) string
WriteCheck generates a check constraint. Supported options: - noInherit: if true, the constraint is not inherited by child tables. - skipValidation: if true, the constraint is not validated.
func (*ConstraintSQLWriter) WriteExclude ¶ added in v0.9.0
func (w *ConstraintSQLWriter) WriteExclude(indexMethod, elements, predicate string) string
WriteExclude generates an exclude constraint. Supported options: - includeColumns: additional columns to include in the index. - storageParameters: storage parameters for the index. - tablespace: tablespace for the index. - deferrable: if true, the constraint is deferrable. - initiallyDeferred: if true, the constraint is initially deferred.
func (*ConstraintSQLWriter) WriteForeignKey ¶ added in v0.9.0
func (w *ConstraintSQLWriter) WriteForeignKey(referencedTable string, referencedColumns []string, onDelete, onUpdate ForeignKeyAction, setColumns []string, matchType ForeignKeyMatchType) string
WriteForeignKey generates a foreign key constraint on the table level and inline. Supported options: - includeColumns: additional columns to include in the index. - storageParameters: storage parameters for the index. - tablespace: tablespace for the index. - deferrable: if true, the constraint is deferrable. - initiallyDeferred: if true, the constraint is initially deferred. - skipValidation: if true, the constraint is not validated.
func (*ConstraintSQLWriter) WritePrimaryKey ¶ added in v0.9.0
func (w *ConstraintSQLWriter) WritePrimaryKey() string
WritePrimaryKey generates a primary key constraint. Supported options: - includeColumns: additional columns to include in the index. - storageParameters: storage parameters for the index. - tablespace: tablespace for the index. - deferrable: if true, the constraint is deferrable. - initiallyDeferred: if true, the constraint is initially deferred.
func (*ConstraintSQLWriter) WriteUnique ¶ added in v0.9.0
func (w *ConstraintSQLWriter) WriteUnique(nullsNotDistinct bool) string
WriteUnique generates a unique constraint. Supported options: - nullsNotDistinct: if true, NULL values are considered equal. - includeColumns: additional columns to include in the index. - storageParameters: storage parameters for the index. - tablespace: tablespace for the index. - deferrable: if true, the constraint is deferrable. - initiallyDeferred: if true, the constraint is initially deferred.
type ConstraintType ¶ added in v0.9.0
type ConstraintType string
const ConstraintTypeCheck ConstraintType = "check"
const ConstraintTypeExclude ConstraintType = "exclude"
const ConstraintTypeForeignKey ConstraintType = "foreign_key"
const ConstraintTypePrimaryKey ConstraintType = "primary_key"
const ConstraintTypeUnique ConstraintType = "unique"
type Coordinator ¶ added in v0.14.2
type Coordinator struct {
// contains filtered or unexported fields
}
Coordinator is responsible for executing a series of database actions in a specific orderedActions. It ensures that each action is executed only once, even if it is added multiple times.
func NewCoordinator ¶ added in v0.14.2
func NewCoordinator(actions []DBAction) *Coordinator
type CreateCheckConstraintAction ¶ added in v0.13.0
type CreateCheckConstraintAction struct {
// contains filtered or unexported fields
}
CreateCheckConstraintAction creates a check constraint on a table.
func NewCreateCheckConstraintAction ¶ added in v0.13.0
func (*CreateCheckConstraintAction) Execute ¶ added in v0.13.0
func (a *CreateCheckConstraintAction) Execute(ctx context.Context) error
func (*CreateCheckConstraintAction) ID ¶ added in v0.14.2
func (a *CreateCheckConstraintAction) ID() string
type Createable ¶ added in v0.12.0
type Createable interface {
Create()
}
Createable interface must be implemented for all operations that can be created using the CLI create command.
The function must prompt users to configure all attributes of an operation.
Example implementation for OpMyOperation that has 3 attributes: table, column and down:
func (o *OpMyOperation) Create() {
o.Table, _ = pterm.DefaultInteractiveTextInput.WithDefaultText("table").Show()
o.Column, _ = pterm.DefaultInteractiveTextInput.WithDefaultText("column").Show()
o.Down, _ = pterm.DefaultInteractiveTextInput.WithDefaultText("down").Show()
}
type DBAction ¶ added in v0.11.0
DBAction is an interface for common database actions pgroll runs during migrations.
type DropTableAction ¶ added in v0.12.0
type DropTableAction struct {
// contains filtered or unexported fields
}
DropTableAction is a DBAction that drops a table.
func NewDropTableAction ¶ added in v0.12.0
func NewDropTableAction(conn db.DB, table string) *DropTableAction
func (*DropTableAction) Execute ¶ added in v0.12.0
func (a *DropTableAction) Execute(ctx context.Context) error
func (*DropTableAction) ID ¶ added in v0.14.2
func (a *DropTableAction) ID() string
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 FileUpdater ¶ added in v0.14.0
type FileUpdater struct {
// contains filtered or unexported fields
}
FileUpdater updates raw migration files if they contain any breaking changes that have proper updater functions registered.
func NewFileUpdater ¶ added in v0.14.0
func NewFileUpdater(updaters map[string][]UpdaterFn) *FileUpdater
func (*FileUpdater) Update ¶ added in v0.14.0
func (u *FileUpdater) Update(rawMigration *RawMigration) (*Migration, error)
type ForeignKeyAction ¶ added in v0.9.0
type ForeignKeyAction string
const ForeignKeyActionCASCADE ForeignKeyAction = "CASCADE"
const ForeignKeyActionNOACTION ForeignKeyAction = "NO ACTION"
const ForeignKeyActionRESTRICT ForeignKeyAction = "RESTRICT"
const ForeignKeyActionSETDEFAULT ForeignKeyAction = "SET DEFAULT"
const ForeignKeyActionSETNULL ForeignKeyAction = "SET NULL"
type ForeignKeyMatchType ¶ added in v0.9.0
type ForeignKeyMatchType string
const ForeignKeyMatchTypeFULL ForeignKeyMatchType = "FULL"
const ForeignKeyMatchTypePARTIAL ForeignKeyMatchType = "PARTIAL"
const ForeignKeyMatchTypeSIMPLE ForeignKeyMatchType = "SIMPLE"
type ForeignKeyReference ¶
type ForeignKeyReference struct {
// Name of the referenced column
Column string `json:"column"`
// Deferable constraint
Deferrable bool `json:"deferrable,omitempty"`
// Initially deferred constraint
InitiallyDeferred bool `json:"initially_deferred,omitempty"`
// Match type of the foreign key constraint
MatchType ForeignKeyMatchType `json:"match_type,omitempty"`
// Name of the foreign key constraint
Name string `json:"name"`
// On delete behavior of the foreign key constraint
OnDelete ForeignKeyAction `json:"on_delete,omitempty"`
// On update behavior of the foreign key constraint
OnUpdate ForeignKeyAction `json:"on_update,omitempty"`
// 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 IndexField ¶ added in v0.10.0
type IndexField struct {
// Collation for the index element
Collate string `json:"collate,omitempty"`
// Name of the column
Column string `json:"column"`
// Nulls ordering, default is first if ascending, last if descending
Nulls *IndexFieldNulls `json:"nulls,omitempty"`
// Operator class settings
Opclass *IndexFieldOpclass `json:"opclass,omitempty"`
// Sort order, default is ascending (ASC)
Sort IndexFieldSort `json:"sort,omitempty"`
}
Index field and its settings
type IndexFieldNulls ¶ added in v0.10.0
type IndexFieldNulls string
const IndexFieldNullsFIRST IndexFieldNulls = "FIRST"
const IndexFieldNullsLAST IndexFieldNulls = "LAST"
type IndexFieldOpclass ¶ added in v0.10.0
type IndexFieldOpclass struct {
// Name of the operator class
Name string `json:"name,omitempty"`
// Operator class parameters
Params []string `json:"params,omitempty"`
}
Operator class settings
type IndexFieldSort ¶ added in v0.10.0
type IndexFieldSort string
const IndexFieldSortASC IndexFieldSort = "ASC"
const IndexFieldSortDESC IndexFieldSort = "DESC"
type InvalidGeneratedColumnError ¶ added in v0.9.0
func (InvalidGeneratedColumnError) Error ¶ added in v0.9.0
func (e InvalidGeneratedColumnError) Error() string
type InvalidIdentifierLengthError ¶ added in v0.8.0
type InvalidIdentifierLengthError struct {
Name string
}
func (InvalidIdentifierLengthError) Error ¶ added in v0.8.0
func (e InvalidIdentifierLengthError) Error() string
type InvalidMigrationError ¶
type InvalidMigrationError struct {
Reason string
}
func (InvalidMigrationError) Error ¶
func (e InvalidMigrationError) Error() string
type InvalidOnDeleteSetColumnError ¶ added in v0.9.0
func (InvalidOnDeleteSetColumnError) Error ¶ added in v0.9.0
func (e InvalidOnDeleteSetColumnError) Error() string
type InvalidOnDeleteSettingError ¶ added in v0.6.0
func (InvalidOnDeleteSettingError) Error ¶ added in v0.6.0
func (e InvalidOnDeleteSettingError) 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 defines where this operation is isolated when executed on start, cannot be executed
// with other operations.
IsIsolated() bool
}
IsolatedOperation is an operation that cannot be executed with other operations in the same migration.
type Logger ¶ added in v0.12.0
type Logger interface {
LogMigrationStart(*Migration)
LogMigrationComplete(*Migration)
LogMigrationRollback(*Migration)
LogMigrationRollbackComplete(*Migration)
LogOperationStart(Operation)
LogOperationComplete(Operation)
LogOperationRollback(Operation)
LogBackfillStart(table string)
LogBackfillComplete(table string)
LogSchemaCreation(migration, schema string)
LogSchemaDeletion(migration, schema string)
Info(msg string, args ...any)
}
Logger is responsible for logging all migration steps.
func NewNoopLogger ¶ added in v0.12.0
func NewNoopLogger() Logger
type Migration ¶
type Migration struct {
Name string `json:"-"`
VersionSchema string `json:"version_schema,omitempty"`
Operations Operations `json:"operations"`
}
func ParseMigration ¶ added in v0.12.0
func ParseMigration(raw *RawMigration) (*Migration, error)
ParseMigration converts a RawMigration to a fully parsed Migration
func ReadMigration ¶ added in v0.3.0
ReadMigration reads and parses a migration file
func (*Migration) UpdateVirtualSchema ¶ added in v0.9.0
UpdateVirtualSchema updates the in-memory schema representation with the changes made by the migration. No changes are made to the physical database.
func (*Migration) Validate ¶
Validate will check that the migration can be applied to the given schema returns a descriptive error if the migration is invalid
func (*Migration) VersionSchemaName ¶ added in v0.14.0
VersionSchemaName returns the version schema name for the migration. It defaults to the migration name if no version schema is set.
type MigrationFormat ¶ added in v0.13.0
type MigrationFormat int
const ( YAMLMigrationFormat MigrationFormat = iota JSONMigrationFormat )
func NewMigrationFormat ¶ added in v0.13.0
func NewMigrationFormat(useJSON bool) MigrationFormat
NewMigrationFormat returns YAML or JSON format
func (MigrationFormat) Extension ¶ added in v0.13.0
func (f MigrationFormat) Extension() string
Extension returns the extension name for the migration file
type MigrationWriter ¶ added in v0.13.0
type MigrationWriter struct {
// contains filtered or unexported fields
}
MigrationWriter is responsible for writing Migrations and RawMigrations to the configured io.Writer instance in either YAML or JSON.
func NewWriter ¶ added in v0.13.0
func NewWriter(w io.Writer, f MigrationFormat) *MigrationWriter
NewWriter creates a new MigrationWriter
func (*MigrationWriter) Write ¶ added in v0.13.0
func (w *MigrationWriter) Write(m *Migration) error
Write writes a migration.Migration to the configured writer.
func (*MigrationWriter) WriteRaw ¶ added in v0.13.0
func (w *MigrationWriter) WriteRaw(m *RawMigration) error
Write writes a migration.RawMigration to the configured writer.
type MultiColumnConstraintsNotSupportedError ¶ added in v0.8.0
func (MultiColumnConstraintsNotSupportedError) Error ¶ added in v0.8.0
func (e MultiColumnConstraintsNotSupportedError) Error() string
type MultiColumnDownSQL ¶ added in v0.8.0
Map of column names to down SQL expressions
type MultiColumnUpSQL ¶ added in v0.8.0
Map of column names to up SQL expressions
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
func (*OpAddColumn) Create ¶ added in v0.12.0
func (o *OpAddColumn) Create()
type OpAlterColumn ¶
type OpAlterColumn struct {
// Add check constraint to the column
Check *CheckConstraint `json:"check,omitempty"`
// Name of the column
Column string `json:"column"`
// New comment on the column
Comment nullable.Nullable[string] `json:"comment,omitempty"`
// Default value of the column. Setting to null will drop the default if it was
// set previously.
Default nullable.Nullable[string] `json:"default,omitempty"`
// SQL expression for down migration
Down string `json:"down"`
// Indicates if the column is nullable (for add/remove 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,omitempty"`
// Add unique constraint to the column
Unique *UniqueConstraint `json:"unique,omitempty"`
// SQL expression for up migration
Up string `json:"up"`
}
Alter column operation
func (*OpAlterColumn) Create ¶ added in v0.12.0
func (o *OpAlterColumn) Create()
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 OpCreateConstraint ¶ added in v0.8.0
type OpCreateConstraint struct {
// Check constraint expression
Check *string `json:"check,omitempty"`
// Columns to add constraint to
Columns []string `json:"columns,omitempty"`
// SQL expressions for down migrations
Down MultiColumnDownSQL `json:"down"`
// IndexParameters corresponds to the JSON schema field "index_parameters".
IndexParameters *OpCreateConstraintIndexParameters `json:"index_parameters,omitempty"`
// Name of the constraint
Name string `json:"name"`
// Do not propagate constraint to child tables
NoInherit bool `json:"no_inherit,omitempty"`
// Reference to the foreign key
References *TableForeignKeyReference `json:"references,omitempty"`
// Name of the table
Table string `json:"table"`
// Type of the constraint
Type OpCreateConstraintType `json:"type"`
// SQL expressions for up migrations
Up MultiColumnUpSQL `json:"up"`
}
Add constraint to table operation
func (*OpCreateConstraint) Create ¶ added in v0.12.0
func (o *OpCreateConstraint) Create()
type OpCreateConstraintIndexParameters ¶ added in v0.12.0
type OpCreateConstraintIndexParameters struct {
// IncludeColumns corresponds to the JSON schema field "include_columns".
IncludeColumns []string `json:"include_columns,omitempty"`
// StorageParameters corresponds to the JSON schema field "storage_parameters".
StorageParameters string `json:"storage_parameters,omitempty"`
// Tablespace corresponds to the JSON schema field "tablespace".
Tablespace string `json:"tablespace,omitempty"`
}
type OpCreateConstraintType ¶ added in v0.8.0
type OpCreateConstraintType string
const OpCreateConstraintTypeCheck OpCreateConstraintType = "check"
const OpCreateConstraintTypeForeignKey OpCreateConstraintType = "foreign_key"
const OpCreateConstraintTypePrimaryKey OpCreateConstraintType = "primary_key"
const OpCreateConstraintTypeUnique OpCreateConstraintType = "unique"
type OpCreateIndex ¶
type OpCreateIndex struct {
// Names and settings of columns on which to define the index
Columns []IndexField `json:"columns"`
// Index method to use for the index: btree, hash, gist, spgist, gin, brin
Method OpCreateIndexMethod `json:"method,omitempty"`
// Index name
Name string `json:"name"`
// Conditional expression for defining a partial index
Predicate string `json:"predicate,omitempty"`
// Storage parameters for the index
StorageParameters string `json:"storage_parameters,omitempty"`
// Name of table on which to define the index
Table string `json:"table"`
// Indicates if the index is unique
Unique bool `json:"unique,omitempty"`
}
Create index operation
func (*OpCreateIndex) Create ¶ added in v0.12.0
func (o *OpCreateIndex) Create()
type OpCreateIndexMethod ¶ added in v0.8.0
type OpCreateIndexMethod string
const OpCreateIndexMethodBrin OpCreateIndexMethod = "brin"
const OpCreateIndexMethodBtree OpCreateIndexMethod = "btree"
const OpCreateIndexMethodGin OpCreateIndexMethod = "gin"
const OpCreateIndexMethodGist OpCreateIndexMethod = "gist"
const OpCreateIndexMethodHash OpCreateIndexMethod = "hash"
const OpCreateIndexMethodSpgist OpCreateIndexMethod = "spgist"
func ParseCreateIndexMethod ¶ added in v0.9.0
func ParseCreateIndexMethod(method string) (OpCreateIndexMethod, error)
ParseCreateIndexMethod parsed index methods into OpCreateIndexMethod
type OpCreateTable ¶
type OpCreateTable struct {
// Columns corresponds to the JSON schema field "columns".
Columns []Column `json:"columns"`
// Postgres comment for the table
Comment *string `json:"comment,omitempty"`
// Constraints corresponds to the JSON schema field "constraints".
Constraints []Constraint `json:"constraints,omitempty"`
// Name of the table
Name string `json:"name"`
}
Create table operation
func (*OpCreateTable) Create ¶ added in v0.12.0
func (o *OpCreateTable) Create()
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
func (*OpDropColumn) Create ¶ added in v0.12.0
func (o *OpDropColumn) Create()
type OpDropConstraint ¶
type OpDropConstraint struct {
// 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
func (*OpDropIndex) Create ¶ added in v0.12.0
func (o *OpDropIndex) Create()
type OpDropMultiColumnConstraint ¶ added in v0.8.0
type OpDropMultiColumnConstraint struct {
// SQL expressions for down migrations
Down MultiColumnDownSQL `json:"down"`
// Name of the constraint
Name string `json:"name"`
// Name of the table
Table string `json:"table"`
// SQL expressions for up migrations
Up MultiColumnUpSQL `json:"up,omitempty"`
}
Drop multi-column constraint operation
func (*OpDropMultiColumnConstraint) Create ¶ added in v0.12.0
func (o *OpDropMultiColumnConstraint) Create()
type OpDropNotNull ¶ added in v0.5.0
type OpDropNotNull struct {
Table string `json:"table"`
Column string `json:"column"`
Up string `json:"up"`
Down string `json:"down"`
}
OpDropNotNull is an operation that drops the NOT NULL constraint from a column
type OpDropTable ¶
type OpDropTable struct {
// Name of the table
Name string `json:"name"`
}
Drop table operation
func (*OpDropTable) Create ¶ added in v0.12.0
func (o *OpDropTable) Create()
type OpName ¶
type OpName string
const ( OpNameCreateTable OpName = "create_table" OpNameRenameTable OpName = "rename_table" OpNameRenameColumn OpName = "rename_column" OpNameDropTable OpName = "drop_table" OpNameAddColumn OpName = "add_column" OpNameDropColumn OpName = "drop_column" OpNameAlterColumn OpName = "alter_column" OpNameCreateIndex OpName = "create_index" OpNameDropIndex OpName = "drop_index" OpNameRenameConstraint OpName = "rename_constraint" OpNameDropConstraint OpName = "drop_constraint" OpNameSetReplicaIdentity OpName = "set_replica_identity" OpNameDropMultiColumnConstraint OpName = "drop_multicolumn_constraint" OpRawSQLName OpName = "sql" OpCreateConstraintName OpName = "create_constraint" )
func OperationName ¶
OperationName returns the name of the operation.
type OpRawSQL ¶
type OpRawSQL struct {
// SQL expression for down migration
Down string `json:"down,omitempty"`
// SQL expression will run on complete step (rather than on start)
OnComplete bool `json:"onComplete,omitempty"`
// SQL expression for up migration
Up string `json:"up"`
}
Raw SQL operation
func (*OpRawSQL) IsIsolated ¶
IsIsolated returns true if the operation is isolated and should be run with other operations.
func (*OpRawSQL) RequiresSchemaRefresh ¶
func (o *OpRawSQL) RequiresSchemaRefresh()
type OpRenameColumn ¶
type OpRenameColumn struct {
// Old name of the column
From string `json:"from"`
// Name of the table
Table string `json:"table"`
// New name of the column
To string `json:"to"`
}
Rename column operation
func (*OpRenameColumn) Create ¶ added in v0.12.0
func (o *OpRenameColumn) Create()
type OpRenameConstraint ¶ added in v0.6.0
type OpRenameConstraint struct {
// Name of the constraint
From string `json:"from"`
// Name of the table
Table string `json:"table"`
// New name of the constraint
To string `json:"to"`
}
Rename constraint operation
func (*OpRenameConstraint) Create ¶ added in v0.12.0
func (o *OpRenameConstraint) Create()
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
func (*OpRenameTable) Create ¶ added in v0.12.0
func (o *OpRenameTable) Create()
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 OpSetComment ¶ added in v0.6.0
type OpSetComment struct {
Table string `json:"table"`
Column string `json:"column"`
Comment *string `json:"comment"`
Up string `json:"up"`
Down string `json:"down"`
}
OpSetComment is a operation that sets a comment on a object.
type OpSetDefault ¶ added in v0.6.0
type OpSetDefault struct {
Table string `json:"table"`
Column string `json:"column"`
Default *string `json:"default"`
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 return the list of 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
// Returns the table that requires backfilling, if any.
Start(ctx context.Context, l Logger, conn db.DB, s *schema.Schema) (*StartResult, 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(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
// Rollback will revert the changes made by Start. It is not possible to
// rollback a completed migration.
Rollback(l Logger, conn db.DB, s *schema.Schema) ([]DBAction, error)
// Validate returns a descriptive error if the operation cannot be applied to the given schema.
Validate(ctx context.Context, s *schema.Schema) error
}
Operation is an operation that can be applied to a schema
func OperationFromName ¶ added in v0.12.0
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,omitempty"`
// Operations corresponds to the JSON schema field "operations".
Operations PgRollOperations `json:"operations"`
// Name of the version schema to use for this migration
VersionSchema *string `json:"version_schema,omitempty"`
}
PgRoll migration definition
type PgRollOperation ¶ added in v0.5.0
type PgRollOperation interface{}
type PgRollOperations ¶ added in v0.5.0
type PgRollOperations []interface{}
type PrimaryKeysAreAlreadySetError ¶ added in v0.9.0
type PrimaryKeysAreAlreadySetError struct {
Table string
}
func (PrimaryKeysAreAlreadySetError) Error ¶ added in v0.9.0
func (e PrimaryKeysAreAlreadySetError) Error() string
type RawMigration ¶ added in v0.12.0
type RawMigration struct {
Name string `json:"-"`
VersionSchema string `json:"version_schema,omitempty"`
Operations json.RawMessage `json:"operations"`
}
func ReadRawMigration ¶ added in v0.12.0
func ReadRawMigration(dir fs.FS, filename string) (*RawMigration, error)
ReadMigration opens the migration file and reads the migration as a RawMigration.
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 defines if this operation requires the resulting schema to be refreshed when
// executed on start.
RequiresSchemaRefresh()
}
RequiresSchemaRefreshOperation is an operation that requires the resulting schema to be refreshed.
type StartResult ¶ added in v0.14.0
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 TableForeignKeyReference ¶ added in v0.9.0
type TableForeignKeyReference struct {
// Columns to reference
Columns []string `json:"columns"`
// Match type of the foreign key constraint
MatchType ForeignKeyMatchType `json:"match_type,omitempty"`
// On delete behavior of the foreign key constraint
OnDelete ForeignKeyAction `json:"on_delete,omitempty"`
// Columns to set to null or to default on delete
OnDeleteSetColumns []string `json:"on_delete_set_columns,omitempty"`
// On update behavior of the foreign key constraint
OnUpdate ForeignKeyAction `json:"on_update,omitempty"`
// Name of the table
Table string `json:"table"`
}
Table level foreign key reference definition
type UnexpectedOnDeleteSetColumnError ¶ added in v0.9.0
type UnexpectedOnDeleteSetColumnError struct {
Name string
}
func (UnexpectedOnDeleteSetColumnError) Error ¶ added in v0.9.0
func (e UnexpectedOnDeleteSetColumnError) Error() string
type UniqueConstraint ¶
type UniqueConstraint struct {
// Name of unique constraint
Name string `json:"name"`
}
Unique constraint definition
func (*UniqueConstraint) Validate ¶
func (c *UniqueConstraint) Validate() error
Validate validates the UniqueConstraint
type UpSQLMustBeColumnDefaultError ¶ added in v0.10.0
type UpSQLMustBeColumnDefaultError struct {
Column string
}
func (UpSQLMustBeColumnDefaultError) Error ¶ added in v0.10.0
func (e UpSQLMustBeColumnDefaultError) Error() string
Source Files
¶
- check.go
- column.go
- constraints.go
- coordinator.go
- dbactions.go
- duplicate.go
- errors.go
- fk_reference.go
- logger.go
- migrations.go
- op_add_column.go
- op_alter_column.go
- op_change_type.go
- op_common.go
- op_create_constraint.go
- op_create_index.go
- op_create_table.go
- op_drop_column.go
- op_drop_constraint.go
- op_drop_index.go
- op_drop_multicolumn_constraint.go
- op_drop_not_null.go
- op_drop_table.go
- op_raw_sql.go
- op_rename_column.go
- op_rename_constraint.go
- op_rename_table.go
- op_set_check.go
- op_set_comment.go
- op_set_default.go
- op_set_fk.go
- op_set_notnull.go
- op_set_replica_identity.go
- op_set_unique.go
- pterm_create.go
- rename.go
- types.go
- unique.go
- updater.go
- writer.go