Help us shape the future of Go! Take the 2026 Go Developer Survey

drivers

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoTransactionDirective      = "-- dbdiff:no-transaction"
	AtlasNoTransactionDirective = "-- atlas:txmode none"
)
View Source
const MigrationHistoryTableName = "dbdiff_migrations"

The diff hides this table. Without that step, a diff prints a DROP statement for the table, and the user then erases the history of every migration.

Variables

Functions

func ApplySQLContent added in v1.2.0

func ApplySQLContent(ctx context.Context, db *sql.DB, content string) error

func DetectPostgresScratchVersion added in v1.2.0

func DetectPostgresScratchVersion(ctx context.Context, connectionString string) embeddedpostgres.PostgresVersion

func FileUsesTransaction added in v1.2.0

func FileUsesTransaction(content string) bool

func FirstError added in v1.2.0

func FirstError(candidates ...error) error

func HasSQLExtension added in v1.2.0

func HasSQLExtension(path string) bool

func IsDownMigration added in v1.2.0

func IsDownMigration(name string) bool

func IsSQLSource added in v1.2.0

func IsSQLSource(path string) bool

func OpenPostgresConnection added in v1.2.0

func OpenPostgresConnection(connectionString string, schema string) (*sql.DB, error)

func QuoteIdentifier added in v1.2.0

func QuoteIdentifier(name string) string

func QuoteIdentifiers added in v1.2.0

func QuoteIdentifiers(names []string) []string

func RenderInstructions added in v1.2.0

func RenderInstructions(instructions []Instruction) string

func SplitSQLStatements added in v1.2.0

func SplitSQLStatements(content string) []string

PostgreSQL runs the statements of one call in an implicit transaction block, and it refuses CREATE INDEX CONCURRENTLY there. A file that holds the directive takes one call for each statement for that reason, and every other file runs in one call.

A semicolon splits nothing inside parentheses, because the actions of CREATE RULE sit there. It splits nothing inside BEGIN ... END, because the body of a trigger of SQLite and the body of BEGIN ATOMIC hold whole statements. A CASE expression ends with END too, so the block counter reads CASE as an opener.

func TrimGooseDownSection added in v1.2.0

func TrimGooseDownSection(content string) string

A goose file holds the up migration and the down migration in one file, and the down part removes the schema that the up part built.

func TrimSQLitePrefix added in v1.2.0

func TrimSQLitePrefix(path string) string

Types

type AlterDomainAction added in v1.2.0

type AlterDomainAction interface {
	DomainActionClause() string
}

type AlterTableAction added in v1.2.0

type AlterTableAction interface {
	TableActionClause() string
}

type AutomaticCastLookup added in v1.2.0

type AutomaticCastLookup func(oldType string, newType string) (bool, error)

type Condition added in v1.2.0

type Condition interface {
	ConditionClause() string
}

type Driver

type Driver interface {
	Close() error
	Diff(ctx context.Context) ([]Instruction, error)
}

func NewDriver added in v1.2.0

func NewDriver(ctx context.Context, driverName DriverName, currentSchema string, finalSchema string,
	schema string, scratchVersion string, compareData bool,
	comparePrivileges bool) (Driver, error)

type DriverName added in v1.2.0

type DriverName string
const (
	SQLiteDriverName   DriverName = "sqlite3"
	PostgresDriverName DriverName = "postgres"
)

func DetectDriver added in v1.2.0

func DetectDriver(source string, target string) (DriverName, error)

type Instruction added in v1.2.0

type Instruction interface {
	String() string
	// The name of the object that the statement changes, and not a comment of the schema.
	Comment() string
}

Every type of the catalogue uses a pointer receiver, so only a pointer satisfies this interface.

func AnnotateInstructions added in v1.2.0

func AnnotateInstructions(instructions []Instruction) []Instruction

type PostgresAddColumnAction added in v1.2.0

type PostgresAddColumnAction struct {
	Column *PostgresColumn
}

func (*PostgresAddColumnAction) TableActionClause added in v1.2.0

func (a *PostgresAddColumnAction) TableActionClause() string

type PostgresAddConstraintAction added in v1.2.0

type PostgresAddConstraintAction struct {
	Constraint *PostgresConstraint
}

func (*PostgresAddConstraintAction) TableActionClause added in v1.2.0

func (a *PostgresAddConstraintAction) TableActionClause() string

type PostgresAddDomainConstraintAction added in v1.2.0

type PostgresAddDomainConstraintAction struct {
	ConstraintName string
	Definition     string
}

func (*PostgresAddDomainConstraintAction) DomainActionClause added in v1.2.0

func (a *PostgresAddDomainConstraintAction) DomainActionClause() string

type PostgresAddIdentityAction added in v1.2.0

type PostgresAddIdentityAction struct {
	ColumnName string
	Identity   string
}

func (*PostgresAddIdentityAction) TableActionClause added in v1.2.0

func (a *PostgresAddIdentityAction) TableActionClause() string

type PostgresAggregate added in v1.2.0

type PostgresAggregate struct {
	Name               string
	Arguments          string
	StateType          string
	TransitionFunction string
	TransitionSpace    int64
	FinalFunction      sql.NullString
	FinalFunctionExtra bool

	// An empty value is the default READ_ONLY, so an equal pair compares as equal.
	FinalFunctionModify string

	CombineFunction     sql.NullString
	SerializeFunction   sql.NullString
	DeserializeFunction sql.NullString
	InitialCondition    sql.NullString

	MovingTransitionFunction        sql.NullString
	MovingInverseTransitionFunction sql.NullString
	MovingStateType                 sql.NullString
	MovingTransitionSpace           int64
	MovingFinalFunction             sql.NullString
	MovingFinalFunctionExtra        bool
	MovingFinalFunctionModify       string
	MovingInitialCondition          sql.NullString

	SortOperator sql.NullString

	// An empty value is the default UNSAFE, so an equal pair compares as equal.
	Parallel string
}

func (*PostgresAggregate) CreateInstruction added in v1.2.0

func (a *PostgresAggregate) CreateInstruction() *PostgresCreateAggregateInstruction

func (*PostgresAggregate) Diff added in v1.2.0

PostgreSQL changes the name and the owner of an aggregate only, so every other change needs a recreation.

func (*PostgresAggregate) DropInstruction added in v1.2.0

func (*PostgresAggregate) Equal added in v1.2.0

func (a *PostgresAggregate) Equal(other *PostgresAggregate) bool

func (*PostgresAggregate) Signature added in v1.2.0

func (a *PostgresAggregate) Signature() string

type PostgresAlterColumnTypeAction added in v1.2.0

type PostgresAlterColumnTypeAction struct {
	ColumnName string
	DataType   string
	Collation  string
	UsingCast  bool
}

func (*PostgresAlterColumnTypeAction) TableActionClause added in v1.2.0

func (a *PostgresAlterColumnTypeAction) TableActionClause() string

type PostgresAlterDomainInstruction added in v1.2.0

type PostgresAlterDomainInstruction struct {
	Name   string
	Action AlterDomainAction
}

func (*PostgresAlterDomainInstruction) Comment added in v1.2.0

func (*PostgresAlterDomainInstruction) String added in v1.2.0

type PostgresAlterExtensionInstruction added in v1.2.0

type PostgresAlterExtensionInstruction struct {
	Name       string
	NewVersion string
}

func (*PostgresAlterExtensionInstruction) Comment added in v1.2.0

func (*PostgresAlterExtensionInstruction) String added in v1.2.0

type PostgresAlterSequenceInstruction added in v1.2.0

type PostgresAlterSequenceInstruction struct {
	Name      string
	DataType  sql.NullString
	Increment sql.NullInt64
	Min       sql.NullInt64
	Max       sql.NullInt64
	Start     sql.NullInt64
	Cache     sql.NullInt64
	Cycle     sql.NullBool
	Restart   sql.NullInt64
}

func (*PostgresAlterSequenceInstruction) Comment added in v1.2.0

func (*PostgresAlterSequenceInstruction) String added in v1.2.0

type PostgresAlterTableInstruction added in v1.2.0

type PostgresAlterTableInstruction struct {
	Name    string
	Actions []AlterTableAction
}

func (*PostgresAlterTableInstruction) Comment added in v1.2.0

func (*PostgresAlterTableInstruction) String added in v1.2.0

type PostgresAlterTypeAddValueInstruction added in v1.2.0

type PostgresAlterTypeAddValueInstruction struct {
	Name  string
	Value string
}

func (*PostgresAlterTypeAddValueInstruction) Comment added in v1.2.0

func (*PostgresAlterTypeAddValueInstruction) String added in v1.2.0

type PostgresAttachPartitionInstruction added in v1.2.0

type PostgresAttachPartitionInstruction struct {
	ParentName    string
	PartitionName string
	Bound         string
}

func (*PostgresAttachPartitionInstruction) Comment added in v1.2.0

func (*PostgresAttachPartitionInstruction) String added in v1.2.0

type PostgresColumn added in v1.2.0

type PostgresColumn struct {
	Name    string
	Type    string
	NotNull bool
	Default sql.NullString

	Identity string

	IdentityOptions string

	GeneratedExpression string

	Serial string

	SerialSequenceName string

	Collation string

	// Definition writes no comment, because a column definition accepts none.
	Comment string

	Storage string

	StatisticsTarget sql.NullInt64
}

func (*PostgresColumn) Copy added in v1.2.0

func (c *PostgresColumn) Copy() *PostgresColumn

func (*PostgresColumn) Definition added in v1.2.0

func (c *PostgresColumn) Definition() string

func (*PostgresColumn) HasEqualAttributes added in v1.2.0

func (c *PostgresColumn) HasEqualAttributes(other *PostgresColumn) bool

func (*PostgresColumn) StatisticsInstructions added in v1.2.0

func (c *PostgresColumn) StatisticsInstructions(tableName string) []Instruction

A column definition accepts no statistics source, so a separate statement holds it. The

func (*PostgresColumn) StorageInstructions added in v1.2.0

func (c *PostgresColumn) StorageInstructions(tableName string) []Instruction

A column definition accepts no storage mode before PostgreSQL 16, so a separate statement

type PostgresCommentOnColumnInstruction added in v1.2.0

type PostgresCommentOnColumnInstruction struct {
	TableName  string
	ColumnName string
	Text       string
}

func (*PostgresCommentOnColumnInstruction) Comment added in v1.2.0

func (*PostgresCommentOnColumnInstruction) String added in v1.2.0

type PostgresCommentOnIndexInstruction added in v1.2.0

type PostgresCommentOnIndexInstruction struct {
	Name string
	Text string
}

func (*PostgresCommentOnIndexInstruction) Comment added in v1.2.0

func (*PostgresCommentOnIndexInstruction) String added in v1.2.0

type PostgresCommentOnMaterializedViewInstruction added in v1.2.0

type PostgresCommentOnMaterializedViewInstruction struct {
	Name string
	Text string
}

func (*PostgresCommentOnMaterializedViewInstruction) Comment added in v1.2.0

func (*PostgresCommentOnMaterializedViewInstruction) String added in v1.2.0

type PostgresCommentOnRoutineInstruction added in v1.2.0

type PostgresCommentOnRoutineInstruction struct {
	Name      string
	Arguments string
	Text      string
}

The word ROUTINE covers a function and a procedure, so one type serves both kinds.

func (*PostgresCommentOnRoutineInstruction) Comment added in v1.2.0

func (*PostgresCommentOnRoutineInstruction) String added in v1.2.0

type PostgresCommentOnTableInstruction added in v1.2.0

type PostgresCommentOnTableInstruction struct {
	Name string
	Text string
}

func (*PostgresCommentOnTableInstruction) Comment added in v1.2.0

func (*PostgresCommentOnTableInstruction) String added in v1.2.0

type PostgresCommentOnTypeInstruction added in v1.2.0

type PostgresCommentOnTypeInstruction struct {
	Name string
	Text string
}

func (*PostgresCommentOnTypeInstruction) Comment added in v1.2.0

func (*PostgresCommentOnTypeInstruction) String added in v1.2.0

type PostgresCommentOnViewInstruction added in v1.2.0

type PostgresCommentOnViewInstruction struct {
	Name string
	Text string
}

func (*PostgresCommentOnViewInstruction) Comment added in v1.2.0

func (*PostgresCommentOnViewInstruction) String added in v1.2.0

type PostgresCompositeType added in v1.2.0

type PostgresCompositeType struct {
	Name       string
	Attributes []*PostgresCompositeTypeAttribute
}

func (*PostgresCompositeType) CreateInstruction added in v1.2.0

func (*PostgresCompositeType) Diff added in v1.2.0

One ALTER TYPE statement changes one attribute only, and the order of the attributes stays fixed. A recreation gives the wanted attribute list in every case.

func (*PostgresCompositeType) DropInstruction added in v1.2.0

func (t *PostgresCompositeType) DropInstruction() *PostgresDropTypeInstruction

func (*PostgresCompositeType) Equal added in v1.2.0

type PostgresCompositeTypeAttribute added in v1.2.0

type PostgresCompositeTypeAttribute struct {
	Name string
	Type string
}

type PostgresConstraint added in v1.2.0

type PostgresConstraint struct {
	Name string
	Type string
	Def  string
}

func (*PostgresConstraint) Clause added in v1.2.0

func (c *PostgresConstraint) Clause() string

func (*PostgresConstraint) IsForeignKey added in v1.2.0

func (c *PostgresConstraint) IsForeignKey() bool

type PostgresCreateAggregateInstruction added in v1.2.0

type PostgresCreateAggregateInstruction struct {
	Name                string
	Arguments           string
	TransitionFunction  string
	TransitionSpace     int64
	StateType           string
	FinalFunction       sql.NullString
	FinalFunctionExtra  bool
	FinalFunctionModify string
	CombineFunction     sql.NullString
	SerializeFunction   sql.NullString
	DeserializeFunction sql.NullString
	InitialCondition    sql.NullString

	MovingTransitionFunction        sql.NullString
	MovingInverseTransitionFunction sql.NullString
	MovingStateType                 sql.NullString
	MovingTransitionSpace           int64
	MovingFinalFunction             sql.NullString
	MovingFinalFunctionExtra        bool
	MovingFinalFunctionModify       string
	MovingInitialCondition          sql.NullString

	SortOperator sql.NullString
	Parallel     string
}

func (*PostgresCreateAggregateInstruction) Comment added in v1.2.0

func (*PostgresCreateAggregateInstruction) String added in v1.2.0

type PostgresCreateCompositeTypeInstruction added in v1.2.0

type PostgresCreateCompositeTypeInstruction struct {
	Name       string
	Attributes []*PostgresCompositeTypeAttribute
}

func (*PostgresCreateCompositeTypeInstruction) Comment added in v1.2.0

func (*PostgresCreateCompositeTypeInstruction) String added in v1.2.0

type PostgresCreateDomainInstruction added in v1.2.0

type PostgresCreateDomainInstruction struct {
	Name        string
	BaseType    string
	Default     sql.NullString
	NotNull     bool
	Constraints []*PostgresDomainConstraint
}

func (*PostgresCreateDomainInstruction) Comment added in v1.2.0

func (*PostgresCreateDomainInstruction) String added in v1.2.0

type PostgresCreateEnumTypeInstruction added in v1.2.0

type PostgresCreateEnumTypeInstruction struct {
	Name   string
	Labels []string
}

func (*PostgresCreateEnumTypeInstruction) Comment added in v1.2.0

func (*PostgresCreateEnumTypeInstruction) String added in v1.2.0

type PostgresCreateExtensionInstruction added in v1.2.0

type PostgresCreateExtensionInstruction struct {
	Name string
}

func (*PostgresCreateExtensionInstruction) Comment added in v1.2.0

func (*PostgresCreateExtensionInstruction) String added in v1.2.0

type PostgresCreateFunctionInstruction added in v1.2.0

type PostgresCreateFunctionInstruction struct {
	Definition string
}

func (*PostgresCreateFunctionInstruction) Comment added in v1.2.0

func (*PostgresCreateFunctionInstruction) String added in v1.2.0

type PostgresCreateIndexInstruction added in v1.2.0

type PostgresCreateIndexInstruction struct {
	Definition string
}

func (*PostgresCreateIndexInstruction) Comment added in v1.2.0

func (*PostgresCreateIndexInstruction) String added in v1.2.0

type PostgresCreateMaterializedViewInstruction added in v1.2.0

type PostgresCreateMaterializedViewInstruction struct {
	Name  string
	Query string
}

func (*PostgresCreateMaterializedViewInstruction) Comment added in v1.2.0

func (*PostgresCreateMaterializedViewInstruction) String added in v1.2.0

type PostgresCreateOperatorInstruction added in v1.2.0

type PostgresCreateOperatorInstruction struct {
	Name             string
	Function         string
	LeftArgument     sql.NullString
	RightArgument    sql.NullString
	Commutator       sql.NullString
	Negator          sql.NullString
	RestrictFunction sql.NullString
	JoinFunction     sql.NullString
	CanHash          bool
	CanMerge         bool
}

The name of an operator holds punctuation marks only, so it takes no quotes.

func (*PostgresCreateOperatorInstruction) Comment added in v1.2.0

func (*PostgresCreateOperatorInstruction) String added in v1.2.0

type PostgresCreateOwnedSequenceInstruction added in v1.2.0

type PostgresCreateOwnedSequenceInstruction struct {
	Name       string
	TableName  string
	ColumnName string
}

func (*PostgresCreateOwnedSequenceInstruction) Comment added in v1.2.0

func (*PostgresCreateOwnedSequenceInstruction) String added in v1.2.0

type PostgresCreatePolicyInstruction added in v1.2.0

type PostgresCreatePolicyInstruction struct {
	Name       string
	TableName  string
	Permissive string
	Command    string
	Roles      []string
	Using      string
	WithCheck  string
}

func (*PostgresCreatePolicyInstruction) Comment added in v1.2.0

func (*PostgresCreatePolicyInstruction) String added in v1.2.0

type PostgresCreateProcedureInstruction added in v1.2.0

type PostgresCreateProcedureInstruction struct {
	Definition string
}

func (*PostgresCreateProcedureInstruction) Comment added in v1.2.0

func (*PostgresCreateProcedureInstruction) String added in v1.2.0

type PostgresCreateRuleInstruction added in v1.2.0

type PostgresCreateRuleInstruction struct {
	Definition string
}

The definition of pg_rules ends with a semicolon, so String adds no second one.

func (*PostgresCreateRuleInstruction) Comment added in v1.2.0

func (*PostgresCreateRuleInstruction) String added in v1.2.0

type PostgresCreateSequenceInstruction added in v1.2.0

type PostgresCreateSequenceInstruction struct {
	Name      string
	DataType  string
	Increment int64
	Min       int64
	Max       int64
	Start     int64
	Cache     int64
	Cycle     bool
}

func (*PostgresCreateSequenceInstruction) Comment added in v1.2.0

func (*PostgresCreateSequenceInstruction) String added in v1.2.0

type PostgresCreateStatisticsInstruction added in v1.2.0

type PostgresCreateStatisticsInstruction struct {
	Definition string
}

func (*PostgresCreateStatisticsInstruction) Comment added in v1.2.0

func (*PostgresCreateStatisticsInstruction) String added in v1.2.0

type PostgresCreateTableInstruction added in v1.2.0

type PostgresCreateTableInstruction struct {
	Name              string
	Columns           []*PostgresColumn
	Constraints       []*PostgresConstraint
	PartitionKey      string
	Inherits          []string
	Unlogged          bool
	StorageParameters []string
}

func (*PostgresCreateTableInstruction) Comment added in v1.2.0

func (*PostgresCreateTableInstruction) String added in v1.2.0

type PostgresCreateTablePartitionInstruction added in v1.2.0

type PostgresCreateTablePartitionInstruction struct {
	Name       string
	ParentName string
	Bound      string
}

func (*PostgresCreateTablePartitionInstruction) Comment added in v1.2.0

func (*PostgresCreateTablePartitionInstruction) String added in v1.2.0

type PostgresCreateTriggerInstruction added in v1.2.0

type PostgresCreateTriggerInstruction struct {
	Definition string
}

func (*PostgresCreateTriggerInstruction) Comment added in v1.2.0

func (*PostgresCreateTriggerInstruction) String added in v1.2.0

type PostgresCreateViewInstruction added in v1.2.0

type PostgresCreateViewInstruction struct {
	Name        string
	Query       string
	CheckOption string
}

func (*PostgresCreateViewInstruction) Comment added in v1.2.0

func (*PostgresCreateViewInstruction) String added in v1.2.0

type PostgresDetachPartitionInstruction added in v1.2.0

type PostgresDetachPartitionInstruction struct {
	ParentName    string
	PartitionName string
}

func (*PostgresDetachPartitionInstruction) Comment added in v1.2.0

func (*PostgresDetachPartitionInstruction) String added in v1.2.0

type PostgresDomain added in v1.2.0

type PostgresDomain struct {
	Name        string
	BaseType    string
	NotNull     bool
	Default     sql.NullString
	Constraints []*PostgresDomainConstraint
}

func (*PostgresDomain) ConstraintByName added in v1.2.0

func (d *PostgresDomain) ConstraintByName(name string) (*PostgresDomainConstraint, bool)

func (*PostgresDomain) CreateInstruction added in v1.2.0

func (d *PostgresDomain) CreateInstruction() *PostgresCreateDomainInstruction

func (*PostgresDomain) Diff added in v1.2.0

func (d *PostgresDomain) Diff(other *PostgresDomain) []Instruction

PostgreSQL changes no base type of a domain, so a new base type needs a recreation.

func (*PostgresDomain) DropInstruction added in v1.2.0

func (d *PostgresDomain) DropInstruction() *PostgresDropDomainInstruction

type PostgresDomainConstraint added in v1.2.0

type PostgresDomainConstraint struct {
	Name string
	Def  string
}

type PostgresDriver added in v1.2.0

type PostgresDriver struct {
	TargetDatabaseConnection *sql.DB
	SourceDatabaseConnection *sql.DB
	TargetSchema             string
	SourceSchema             string
	CompareData              bool
	ComparePrivileges        bool

	ScratchVersion embeddedpostgres.PostgresVersion
	// contains filtered or unexported fields
}

func NewPostgresDriver added in v1.2.0

func NewPostgresDriver(ctx context.Context, config *PostgresDriverConfig) (*PostgresDriver, error)

func (*PostgresDriver) Close added in v1.2.0

func (d *PostgresDriver) Close() error

func (*PostgresDriver) Diff added in v1.2.0

func (d *PostgresDriver) Diff(ctx context.Context) ([]Instruction, error)

func (*PostgresDriver) DiffAggregates added in v1.2.0

func (d *PostgresDriver) DiffAggregates(ctx context.Context) (*SectionDiff, error)

func (*PostgresDriver) DiffCompositeTypes added in v1.2.0

func (d *PostgresDriver) DiffCompositeTypes(ctx context.Context) (*SectionDiff, error)

func (*PostgresDriver) DiffData added in v1.2.0

func (d *PostgresDriver) DiffData(ctx context.Context) ([]Instruction, error)

The schema section already creates or drops the other tables.

func (*PostgresDriver) DiffDomains added in v1.2.0

func (d *PostgresDriver) DiffDomains(ctx context.Context) (*SectionDiff, error)

func (*PostgresDriver) DiffExtensions added in v1.2.0

func (d *PostgresDriver) DiffExtensions(ctx context.Context) (*SectionDiff, error)

func (*PostgresDriver) DiffFunctions added in v1.2.0

func (d *PostgresDriver) DiffFunctions(ctx context.Context) (*SectionDiff, error)

func (*PostgresDriver) DiffOperators added in v1.2.0

func (d *PostgresDriver) DiffOperators(ctx context.Context) (*SectionDiff, error)

func (*PostgresDriver) DiffPrivileges added in v1.2.0

func (d *PostgresDriver) DiffPrivileges(ctx context.Context) (*SectionDiff, error)

func (*PostgresDriver) DiffSequences added in v1.2.0

func (d *PostgresDriver) DiffSequences(ctx context.Context) (*SectionDiff, error)

func (*PostgresDriver) DiffStatistics added in v1.2.0

func (d *PostgresDriver) DiffStatistics(ctx context.Context) (*SectionDiff, error)

An extended statistics object names a table, so this section comes after the tables.

func (*PostgresDriver) DiffTableData added in v1.2.0

func (d *PostgresDriver) DiffTableData(ctx context.Context, targetTable *PostgresTable, sourceTable *PostgresTable) ([]Instruction, []Instruction, error)

func (*PostgresDriver) DiffTables added in v1.2.0

func (d *PostgresDriver) DiffTables(ctx context.Context) (*SectionDiff, error)

func (*PostgresDriver) DiffTypes added in v1.2.0

func (d *PostgresDriver) DiffTypes(ctx context.Context) (*SectionDiff, error)

func (*PostgresDriver) DiffViewsAndMaterializedViews added in v1.2.0

func (d *PostgresDriver) DiffViewsAndMaterializedViews(ctx context.Context) (*SectionDiff, error)

A view can read a materialized view, and a materialized view can read a view, so the two kinds share one section and one dependency order.

func (*PostgresDriver) GetAggregates added in v1.2.0

func (d *PostgresDriver) GetAggregates(ctx context.Context, db *sql.DB) ([]*PostgresAggregate, error)

func (*PostgresDriver) GetCompositeTypes added in v1.2.0

func (d *PostgresDriver) GetCompositeTypes(ctx context.Context, db *sql.DB) ([]*PostgresCompositeType, error)

func (*PostgresDriver) GetDomains added in v1.2.0

func (d *PostgresDriver) GetDomains(ctx context.Context, db *sql.DB) ([]*PostgresDomain, error)

func (*PostgresDriver) GetExtensions added in v1.2.0

func (d *PostgresDriver) GetExtensions(ctx context.Context, db *sql.DB) ([]*PostgresExtension, error)

func (*PostgresDriver) GetFunctions added in v1.2.0

func (d *PostgresDriver) GetFunctions(ctx context.Context, db *sql.DB) ([]*PostgresFunction, error)

func (*PostgresDriver) GetMaterializedViewIndexes added in v1.2.0

func (d *PostgresDriver) GetMaterializedViewIndexes(ctx context.Context, db *sql.DB, viewName string) ([]*PostgresIndex, error)

func (*PostgresDriver) GetMaterializedViews added in v1.2.0

func (d *PostgresDriver) GetMaterializedViews(ctx context.Context, db *sql.DB) ([]*PostgresMaterializedView, error)

func (*PostgresDriver) GetOperators added in v1.2.0

func (d *PostgresDriver) GetOperators(ctx context.Context, db *sql.DB) ([]*PostgresOperator, error)

func (*PostgresDriver) GetOwners added in v1.2.0

func (d *PostgresDriver) GetOwners(ctx context.Context, db *sql.DB) ([]*PostgresOwner, error)

func (*PostgresDriver) GetPrivileges added in v1.2.0

func (d *PostgresDriver) GetPrivileges(ctx context.Context, db *sql.DB) ([]*PostgresPrivilege, error)

PostgreSQL gives the privileges of the owner with the object.

func (*PostgresDriver) GetSequences added in v1.2.0

func (d *PostgresDriver) GetSequences(ctx context.Context, db *sql.DB) ([]*PostgresSequence, error)

func (*PostgresDriver) GetStatistics added in v1.2.0

func (d *PostgresDriver) GetStatistics(ctx context.Context, db *sql.DB) ([]*PostgresStatistics, error)

func (*PostgresDriver) GetTable added in v1.2.0

func (d *PostgresDriver) GetTable(ctx context.Context, db *sql.DB, tableName string) (*PostgresTable, error)

func (*PostgresDriver) GetTableData added in v1.2.0

func (d *PostgresDriver) GetTableData(ctx context.Context, db *sql.DB, tableName string, columnNames []string, primaryKeyColumnNames []string) (*PostgresTableData, error)

PostgreSQL gives no stable order, so the ORDER BY clause keeps the output equal between two runs.

func (*PostgresDriver) GetTablePolicies added in v1.2.0

func (d *PostgresDriver) GetTablePolicies(ctx context.Context, db *sql.DB, tableName string) ([]*PostgresPolicy, error)

func (*PostgresDriver) GetTablePrimaryKey added in v1.2.0

func (d *PostgresDriver) GetTablePrimaryKey(ctx context.Context, db *sql.DB, tableName string) ([]string, error)

func (*PostgresDriver) GetTableRules added in v1.2.0

func (d *PostgresDriver) GetTableRules(ctx context.Context, db *sql.DB, tableName string) ([]*PostgresRule, error)

pg_rules reports no _RETURN rule, which is the implicit rule of a view.

func (*PostgresDriver) GetTables added in v1.2.0

func (d *PostgresDriver) GetTables(ctx context.Context, db *sql.DB) ([]*PostgresTable, error)

information_schema reports no partition key, no partition bound, and no replica identity, so the query reads pg_class.

pg_inherits names the parent of a partition and the parent of a table of INHERITS, so relispartition separates the two. Without that test a table of INHERITS takes the statement of a partition, and that statement holds no bound.

func (*PostgresDriver) GetTypes added in v1.2.0

func (d *PostgresDriver) GetTypes(ctx context.Context, db *sql.DB) ([]*PostgresType, error)

func (*PostgresDriver) GetViewColumns added in v1.2.0

func (d *PostgresDriver) GetViewColumns(ctx context.Context, db *sql.DB, viewName string) ([]*PostgresViewColumn, error)

The type of each column comes with it, because a type change makes the view invalid.

func (*PostgresDriver) GetViews added in v1.2.0

func (d *PostgresDriver) GetViews(ctx context.Context, db *sql.DB) ([]*PostgresView, error)

func (*PostgresDriver) HasAutomaticCast added in v1.2.0

func (d *PostgresDriver) HasAutomaticCast(ctx context.Context, db *sql.DB, oldType string, newType string) (bool, error)

The rules of pg_cast are long, so this function asks the database. ALTER TABLE ALTER COLUMN TYPE uses the assignment context. An unknown type name gives true, and the output then keeps the form that it had before this rule.

func (*PostgresDriver) OpenSide added in v1.2.0

func (d *PostgresDriver) OpenSide(ctx context.Context, connectionString string, schema string, role string) (*sql.DB, error)

func (*PostgresDriver) ScratchServer added in v1.2.0

func (d *PostgresDriver) ScratchServer() (*PostgresScratchServer, error)

func (*PostgresDriver) StopScratchServer added in v1.2.0

func (d *PostgresDriver) StopScratchServer() error

func (*PostgresDriver) TableDataInstructions added in v1.2.0

func (d *PostgresDriver) TableDataInstructions(ctx context.Context, targetTable *PostgresTable) ([]Instruction, error)

The schema section creates this table with no row, so every target row becomes an INSERT statement.

func (*PostgresDriver) VerifySchema added in v1.2.0

func (d *PostgresDriver) VerifySchema(ctx context.Context, db *sql.DB, schema string, role string) error

PostgreSQL accepts a search path that names no schema, and each query then reads an empty schema. Without this check the diff drops every object of the source.

type PostgresDriverConfig added in v1.2.0

type PostgresDriverConfig struct {
	TargetConnectionString string
	SourceConnectionString string
	TargetSchema           string
	SourceSchema           string
	CompareData            bool
	ComparePrivileges      bool

	ScratchServerVersion string
}

type PostgresDropAggregateInstruction added in v1.2.0

type PostgresDropAggregateInstruction struct {
	Name      string
	Arguments string
}

func (*PostgresDropAggregateInstruction) Comment added in v1.2.0

func (*PostgresDropAggregateInstruction) String added in v1.2.0

type PostgresDropConstraintAction added in v1.2.0

type PostgresDropConstraintAction struct {
	ConstraintName string
}

func (*PostgresDropConstraintAction) TableActionClause added in v1.2.0

func (a *PostgresDropConstraintAction) TableActionClause() string

type PostgresDropDefaultAction added in v1.2.0

type PostgresDropDefaultAction struct {
	ColumnName string
}

func (*PostgresDropDefaultAction) TableActionClause added in v1.2.0

func (a *PostgresDropDefaultAction) TableActionClause() string

type PostgresDropDomainConstraintAction added in v1.2.0

type PostgresDropDomainConstraintAction struct {
	ConstraintName string
}

func (*PostgresDropDomainConstraintAction) DomainActionClause added in v1.2.0

func (a *PostgresDropDomainConstraintAction) DomainActionClause() string

type PostgresDropDomainDefaultAction added in v1.2.0

type PostgresDropDomainDefaultAction struct{}

func (*PostgresDropDomainDefaultAction) DomainActionClause added in v1.2.0

func (a *PostgresDropDomainDefaultAction) DomainActionClause() string

type PostgresDropDomainInstruction added in v1.2.0

type PostgresDropDomainInstruction struct {
	Name string
}

func (*PostgresDropDomainInstruction) Comment added in v1.2.0

func (*PostgresDropDomainInstruction) String added in v1.2.0

type PostgresDropDomainNotNullAction added in v1.2.0

type PostgresDropDomainNotNullAction struct{}

func (*PostgresDropDomainNotNullAction) DomainActionClause added in v1.2.0

func (a *PostgresDropDomainNotNullAction) DomainActionClause() string

type PostgresDropExtensionInstruction added in v1.2.0

type PostgresDropExtensionInstruction struct {
	Name string
}

func (*PostgresDropExtensionInstruction) Comment added in v1.2.0

func (*PostgresDropExtensionInstruction) String added in v1.2.0

type PostgresDropFunctionInstruction added in v1.2.0

type PostgresDropFunctionInstruction struct {
	Name      string
	Arguments string
}

func (*PostgresDropFunctionInstruction) Comment added in v1.2.0

func (*PostgresDropFunctionInstruction) String added in v1.2.0

type PostgresDropIdentityAction added in v1.2.0

type PostgresDropIdentityAction struct {
	ColumnName string
}

func (*PostgresDropIdentityAction) TableActionClause added in v1.2.0

func (a *PostgresDropIdentityAction) TableActionClause() string

type PostgresDropMaterializedViewInstruction added in v1.2.0

type PostgresDropMaterializedViewInstruction struct {
	Name string
}

func (*PostgresDropMaterializedViewInstruction) Comment added in v1.2.0

func (*PostgresDropMaterializedViewInstruction) String added in v1.2.0

type PostgresDropNotNullAction added in v1.2.0

type PostgresDropNotNullAction struct {
	ColumnName string
}

func (*PostgresDropNotNullAction) TableActionClause added in v1.2.0

func (a *PostgresDropNotNullAction) TableActionClause() string

type PostgresDropOperatorInstruction added in v1.2.0

type PostgresDropOperatorInstruction struct {
	Name          string
	LeftArgument  sql.NullString
	RightArgument sql.NullString
}

func (*PostgresDropOperatorInstruction) Comment added in v1.2.0

func (*PostgresDropOperatorInstruction) String added in v1.2.0

type PostgresDropPolicyInstruction added in v1.2.0

type PostgresDropPolicyInstruction struct {
	Name      string
	TableName string
}

func (*PostgresDropPolicyInstruction) Comment added in v1.2.0

func (*PostgresDropPolicyInstruction) String added in v1.2.0

type PostgresDropProcedureInstruction added in v1.2.0

type PostgresDropProcedureInstruction struct {
	Name      string
	Arguments string
}

func (*PostgresDropProcedureInstruction) Comment added in v1.2.0

func (*PostgresDropProcedureInstruction) String added in v1.2.0

type PostgresDropRuleInstruction added in v1.2.0

type PostgresDropRuleInstruction struct {
	Name      string
	TableName string
}

func (*PostgresDropRuleInstruction) Comment added in v1.2.0

func (i *PostgresDropRuleInstruction) Comment() string

func (*PostgresDropRuleInstruction) String added in v1.2.0

func (i *PostgresDropRuleInstruction) String() string

type PostgresDropSequenceInstruction added in v1.2.0

type PostgresDropSequenceInstruction struct {
	Name string
}

func (*PostgresDropSequenceInstruction) Comment added in v1.2.0

func (*PostgresDropSequenceInstruction) String added in v1.2.0

type PostgresDropStatisticsInstruction added in v1.2.0

type PostgresDropStatisticsInstruction struct {
	Name string
}

func (*PostgresDropStatisticsInstruction) Comment added in v1.2.0

func (*PostgresDropStatisticsInstruction) String added in v1.2.0

type PostgresDropTriggerInstruction added in v1.2.0

type PostgresDropTriggerInstruction struct {
	Name      string
	TableName string
}

func (*PostgresDropTriggerInstruction) Comment added in v1.2.0

func (*PostgresDropTriggerInstruction) String added in v1.2.0

type PostgresDropTypeInstruction added in v1.2.0

type PostgresDropTypeInstruction struct {
	Name string
}

func (*PostgresDropTypeInstruction) Comment added in v1.2.0

func (i *PostgresDropTypeInstruction) Comment() string

func (*PostgresDropTypeInstruction) String added in v1.2.0

func (i *PostgresDropTypeInstruction) String() string

type PostgresExtension added in v1.2.0

type PostgresExtension struct {
	Name    string
	Version string
}

func (*PostgresExtension) CreateInstruction added in v1.2.0

func (e *PostgresExtension) CreateInstruction() *PostgresCreateExtensionInstruction

func (*PostgresExtension) DropInstruction added in v1.2.0

func (*PostgresExtension) UpdateInstruction added in v1.2.0

func (e *PostgresExtension) UpdateInstruction() *PostgresAlterExtensionInstruction

type PostgresFunction added in v1.2.0

type PostgresFunction struct {
	Name          string
	Arguments     string
	ArgumentTypes string
	ReturnType    string
	Kind          string
	Def           string
	Comment       string
}

func (*PostgresFunction) CommentInstruction added in v1.2.0

func (f *PostgresFunction) CommentInstruction() *PostgresCommentOnRoutineInstruction

func (*PostgresFunction) CreateInstruction added in v1.2.0

func (f *PostgresFunction) CreateInstruction() Instruction

func (*PostgresFunction) DropInstruction added in v1.2.0

func (f *PostgresFunction) DropInstruction() Instruction

func (*PostgresFunction) MatchKey added in v1.2.0

func (f *PostgresFunction) MatchKey() string

func (*PostgresFunction) Signature added in v1.2.0

func (f *PostgresFunction) Signature() string

type PostgresGrantInstruction added in v1.2.0

type PostgresGrantInstruction struct {
	Privileges []string
	ObjectType string
	ObjectName string
	Grantee    string
}

func (*PostgresGrantInstruction) Comment added in v1.2.0

func (i *PostgresGrantInstruction) Comment() string

func (*PostgresGrantInstruction) String added in v1.2.0

func (i *PostgresGrantInstruction) String() string

type PostgresIndex added in v1.2.0

type PostgresIndex struct {
	Name    string
	Def     string
	Comment string
}

func (*PostgresIndex) CreateInstruction added in v1.2.0

func (i *PostgresIndex) CreateInstruction() *PostgresCreateIndexInstruction

func (*PostgresIndex) Instructions added in v1.2.0

func (i *PostgresIndex) Instructions() []Instruction

CREATE INDEX accepts no comment, so the comment takes its own statement.

type PostgresInheritAction added in v1.2.0

type PostgresInheritAction struct {
	ParentName string
}

func (*PostgresInheritAction) TableActionClause added in v1.2.0

func (a *PostgresInheritAction) TableActionClause() string

type PostgresInsertOverridingInstruction added in v1.2.0

type PostgresInsertOverridingInstruction struct {
	TableName   string
	ColumnNames []string
	Expressions []string
}

func (*PostgresInsertOverridingInstruction) Comment added in v1.2.0

func (*PostgresInsertOverridingInstruction) String added in v1.2.0

type PostgresMaterializedView added in v1.2.0

type PostgresMaterializedView struct {
	Name    string
	Def     string
	Columns []*PostgresViewColumn
	Indexes []*PostgresIndex
	Comment string
}

A materialized view reads a table, a view, or a second materialized view, so the diff keeps the order of the dependency.

func (*PostgresMaterializedView) CreateInstruction added in v1.2.0

func (*PostgresMaterializedView) DropInstruction added in v1.2.0

func (*PostgresMaterializedView) HasEqualColumns added in v1.2.0

func (v *PostgresMaterializedView) HasEqualColumns(other *PostgresMaterializedView) bool

func (*PostgresMaterializedView) IndexByName added in v1.2.0

func (v *PostgresMaterializedView) IndexByName(name string) (*PostgresIndex, bool)

func (*PostgresMaterializedView) Instructions added in v1.2.0

func (v *PostgresMaterializedView) Instructions() []Instruction

type PostgresNoInheritAction added in v1.2.0

type PostgresNoInheritAction struct {
	ParentName string
}

func (*PostgresNoInheritAction) TableActionClause added in v1.2.0

func (a *PostgresNoInheritAction) TableActionClause() string

type PostgresOperator added in v1.2.0

type PostgresOperator struct {
	Name             string
	LeftArgument     sql.NullString
	RightArgument    sql.NullString
	Function         string
	Commutator       sql.NullString
	Negator          sql.NullString
	RestrictFunction sql.NullString
	JoinFunction     sql.NullString
	CanHash          bool
	CanMerge         bool
}

func (*PostgresOperator) CreateInstruction added in v1.2.0

func (o *PostgresOperator) CreateInstruction() *PostgresCreateOperatorInstruction

func (*PostgresOperator) Diff added in v1.2.0

func (o *PostgresOperator) Diff(other *PostgresOperator) []Instruction

PostgreSQL changes the owner and the support options of an operator only, so a new function needs a recreation.

func (*PostgresOperator) DropInstruction added in v1.2.0

func (o *PostgresOperator) DropInstruction() *PostgresDropOperatorInstruction

func (*PostgresOperator) Equal added in v1.2.0

func (o *PostgresOperator) Equal(other *PostgresOperator) bool

func (*PostgresOperator) Signature added in v1.2.0

func (o *PostgresOperator) Signature() string

type PostgresOwner added in v1.2.0

type PostgresOwner struct {
	ObjectType string
	ObjectName string
	Owner      string
}

func (*PostgresOwner) SetInstruction added in v1.2.0

func (o *PostgresOwner) SetInstruction() *PostgresSetOwnerInstruction

type PostgresPolicy added in v1.2.0

type PostgresPolicy struct {
	Name       string
	Table      string
	Permissive string
	Command    string
	Roles      []string
	Using      string
	WithCheck  string
}

PostgreSQL holds no action that changes a policy, so the diff prints a DROP statement and a CREATE statement.

func (*PostgresPolicy) CreateInstruction added in v1.2.0

func (p *PostgresPolicy) CreateInstruction() *PostgresCreatePolicyInstruction

func (*PostgresPolicy) DropInstruction added in v1.2.0

func (p *PostgresPolicy) DropInstruction() *PostgresDropPolicyInstruction

func (*PostgresPolicy) Equal added in v1.2.0

func (p *PostgresPolicy) Equal(other *PostgresPolicy) bool

type PostgresPrivilege added in v1.2.0

type PostgresPrivilege struct {
	ObjectType string
	ObjectName string
	Grantee    string
	Privileges []string
}

A role belongs to the server and not to the schema. A source server holds other role names in most cases, and a GRANT statement of an absent role fails.

func (*PostgresPrivilege) GrantInstruction added in v1.2.0

func (p *PostgresPrivilege) GrantInstruction(privileges []string) *PostgresGrantInstruction

func (*PostgresPrivilege) Key added in v1.2.0

func (p *PostgresPrivilege) Key() string

func (*PostgresPrivilege) RevokeInstruction added in v1.2.0

func (p *PostgresPrivilege) RevokeInstruction(privileges []string) *PostgresRevokeInstruction

type PostgresRelation added in v1.2.0

type PostgresRelation struct {
	View             *PostgresView
	MaterializedView *PostgresMaterializedView
}

A view can read a materialized view, and a materialized view can read a view, so one section order per kind cannot hold the dependency. A relation joins the two kinds into one dependency order.

func (*PostgresRelation) Columns added in v1.2.0

func (r *PostgresRelation) Columns() []*PostgresViewColumn

func (*PostgresRelation) Name added in v1.2.0

func (r *PostgresRelation) Name() string

type PostgresReplicaIdentityAction added in v1.2.0

type PostgresReplicaIdentityAction struct {
	Mode      string
	IndexName string
}

func (*PostgresReplicaIdentityAction) TableActionClause added in v1.2.0

func (a *PostgresReplicaIdentityAction) TableActionClause() string

type PostgresResetStorageParametersAction added in v1.2.0

type PostgresResetStorageParametersAction struct {
	Names []string
}

func (*PostgresResetStorageParametersAction) TableActionClause added in v1.2.0

func (a *PostgresResetStorageParametersAction) TableActionClause() string

type PostgresRevokeInstruction added in v1.2.0

type PostgresRevokeInstruction struct {
	Privileges []string
	ObjectType string
	ObjectName string
	Grantee    string
}

func (*PostgresRevokeInstruction) Comment added in v1.2.0

func (i *PostgresRevokeInstruction) Comment() string

func (*PostgresRevokeInstruction) String added in v1.2.0

func (i *PostgresRevokeInstruction) String() string

type PostgresRowLevelSecurityAction added in v1.2.0

type PostgresRowLevelSecurityAction struct {
	Mode string
}

func (*PostgresRowLevelSecurityAction) TableActionClause added in v1.2.0

func (a *PostgresRowLevelSecurityAction) TableActionClause() string

type PostgresRule added in v1.2.0

type PostgresRule struct {
	Name  string
	Table string
	Def   string
}

PostgreSQL holds no action that changes a rule, so a new definition prints a DROP statement and a CREATE statement.

func (*PostgresRule) CreateInstruction added in v1.2.0

func (r *PostgresRule) CreateInstruction() *PostgresCreateRuleInstruction

func (*PostgresRule) DropInstruction added in v1.2.0

func (r *PostgresRule) DropInstruction() *PostgresDropRuleInstruction

type PostgresScratchServer added in v1.2.0

type PostgresScratchServer struct {
	// contains filtered or unexported fields
}

func StartPostgresScratchServer added in v1.2.0

func StartPostgresScratchServer(version embeddedpostgres.PostgresVersion) (*PostgresScratchServer, error)

func (*PostgresScratchServer) ConnectionString added in v1.2.0

func (s *PostgresScratchServer) ConnectionString(database string) string

func (*PostgresScratchServer) CreateDatabase added in v1.2.0

func (s *PostgresScratchServer) CreateDatabase(ctx context.Context, name string) (string, error)

func (*PostgresScratchServer) Stop added in v1.2.0

func (s *PostgresScratchServer) Stop() error

type PostgresSequence added in v1.2.0

type PostgresSequence struct {
	Name      string
	DataType  string
	Start     int64
	Min       int64
	Max       int64
	Increment int64
	Cache     int64
	Cycle     bool

	CurrentValue sql.NullInt64
}

func (*PostgresSequence) CreateInstruction added in v1.2.0

func (s *PostgresSequence) CreateInstruction() *PostgresCreateSequenceInstruction

func (*PostgresSequence) Diff added in v1.2.0

func (s *PostgresSequence) Diff(other *PostgresSequence) []Instruction

Separate statements can fail, because a new minimum above the current value is invalid. A restart changes data, so the RESTART WITH clause comes only when the current value falls outside the new range.

func (*PostgresSequence) RestartValue added in v1.2.0

func (s *PostgresSequence) RestartValue() int64

type PostgresSetDefaultAction added in v1.2.0

type PostgresSetDefaultAction struct {
	ColumnName string
	Expression string
}

func (*PostgresSetDefaultAction) TableActionClause added in v1.2.0

func (a *PostgresSetDefaultAction) TableActionClause() string

type PostgresSetDomainDefaultAction added in v1.2.0

type PostgresSetDomainDefaultAction struct {
	Expression string
}

func (*PostgresSetDomainDefaultAction) DomainActionClause added in v1.2.0

func (a *PostgresSetDomainDefaultAction) DomainActionClause() string

type PostgresSetDomainNotNullAction added in v1.2.0

type PostgresSetDomainNotNullAction struct{}

func (*PostgresSetDomainNotNullAction) DomainActionClause added in v1.2.0

func (a *PostgresSetDomainNotNullAction) DomainActionClause() string

type PostgresSetIdentityAction added in v1.2.0

type PostgresSetIdentityAction struct {
	ColumnName string
	Identity   string
}

func (*PostgresSetIdentityAction) TableActionClause added in v1.2.0

func (a *PostgresSetIdentityAction) TableActionClause() string

type PostgresSetIdentityOptionsAction added in v1.2.0

type PostgresSetIdentityOptionsAction struct {
	ColumnName string
	Options    string
}

func (*PostgresSetIdentityOptionsAction) TableActionClause added in v1.2.0

func (a *PostgresSetIdentityOptionsAction) TableActionClause() string

PostgreSQL takes one SET for each sequence option of the identity.

type PostgresSetNotNullAction added in v1.2.0

type PostgresSetNotNullAction struct {
	ColumnName string
}

func (*PostgresSetNotNullAction) TableActionClause added in v1.2.0

func (a *PostgresSetNotNullAction) TableActionClause() string

type PostgresSetOwnerInstruction added in v1.2.0

type PostgresSetOwnerInstruction struct {
	ObjectType string
	ObjectName string
	Owner      string
}

func (*PostgresSetOwnerInstruction) Comment added in v1.2.0

func (i *PostgresSetOwnerInstruction) Comment() string

func (*PostgresSetOwnerInstruction) String added in v1.2.0

func (i *PostgresSetOwnerInstruction) String() string

type PostgresSetPersistenceAction added in v1.2.0

type PostgresSetPersistenceAction struct {
	Persistence string
}

func (*PostgresSetPersistenceAction) TableActionClause added in v1.2.0

func (a *PostgresSetPersistenceAction) TableActionClause() string

type PostgresSetStatisticsAction added in v1.2.0

type PostgresSetStatisticsAction struct {
	ColumnName string
	Source     int64
}

func (*PostgresSetStatisticsAction) TableActionClause added in v1.2.0

func (a *PostgresSetStatisticsAction) TableActionClause() string

type PostgresSetStorageAction added in v1.2.0

type PostgresSetStorageAction struct {
	ColumnName string
	Storage    string
}

func (*PostgresSetStorageAction) TableActionClause added in v1.2.0

func (a *PostgresSetStorageAction) TableActionClause() string

type PostgresSetStorageParametersAction added in v1.2.0

type PostgresSetStorageParametersAction struct {
	Parameters []string
}

func (*PostgresSetStorageParametersAction) TableActionClause added in v1.2.0

func (a *PostgresSetStorageParametersAction) TableActionClause() string

type PostgresStatistics added in v1.2.0

type PostgresStatistics struct {
	Name string

	// Def holds the text of pg_get_statisticsobjdef, with no semicolon.
	Def string
}

PostgreSQL holds no action that changes the columns of such an object, so a new definition prints a DROP statement and a CREATE statement.

func (*PostgresStatistics) CreateInstruction added in v1.2.0

func (*PostgresStatistics) DropInstruction added in v1.2.0

type PostgresTable added in v1.2.0

type PostgresTable struct {
	Name        string
	Columns     []*PostgresColumn
	Indexes     []*PostgresIndex
	Constraints []*PostgresConstraint
	Triggers    []*PostgresTrigger
	Rules       []*PostgresRule

	PartitionKey    string
	PartitionParent string
	PartitionBound  string

	// A table of INHERITS is no partition, so it keeps its own columns and its own statement.
	Inherits []string

	References []string

	Comment string

	Unlogged bool

	StorageParameters []string

	ReplicaIdentity string

	ReplicaIdentityIndex string

	RowLevelSecurity      bool
	ForceRowLevelSecurity bool
	Policies              []*PostgresPolicy
}

func (*PostgresTable) ColumnByName added in v1.2.0

func (t *PostgresTable) ColumnByName(name string) (*PostgresColumn, bool)

func (*PostgresTable) CommentInstructions added in v1.2.0

func (t *PostgresTable) CommentInstructions() []Instruction

PostgreSQL accepts a comment in no CREATE statement.

func (*PostgresTable) ConstraintByName added in v1.2.0

func (t *PostgresTable) ConstraintByName(name string) (*PostgresConstraint, bool)

func (*PostgresTable) CreateTableInstruction added in v1.2.0

func (t *PostgresTable) CreateTableInstruction() *PostgresCreateTableInstruction

func (*PostgresTable) DiffRules added in v1.2.0

func (t *PostgresTable) DiffRules(other *PostgresTable) []Instruction

func (*PostgresTable) DiffTable added in v1.2.0

func (t *PostgresTable) DiffTable(other *PostgresTable, hasAutomaticCast AutomaticCastLookup) ([]Instruction, error)

func (*PostgresTable) ForeignKeyInstructions added in v1.2.0

func (t *PostgresTable) ForeignKeyInstructions() []Instruction

A partition takes the foreign keys of its parent, so a second statement of one fails.

func (*PostgresTable) IndexByName added in v1.2.0

func (t *PostgresTable) IndexByName(name string) (*PostgresIndex, bool)

func (*PostgresTable) Instructions added in v1.2.0

func (t *PostgresTable) Instructions() []Instruction

The action of a rule can name a second table, so DiffTables prints the rules apart.

func (*PostgresTable) IsPartition added in v1.2.0

func (t *PostgresTable) IsPartition() bool

func (*PostgresTable) PolicyByName added in v1.2.0

func (t *PostgresTable) PolicyByName(name string) (*PostgresPolicy, bool)

func (*PostgresTable) ReplicaIdentityInstructions added in v1.2.0

func (t *PostgresTable) ReplicaIdentityInstructions() []Instruction

PostgreSQL accepts no replica identity in a CREATE TABLE statement. The mode DEFAULT needs no statement, because every new table holds that mode.

func (*PostgresTable) RowLevelSecurityInstructions added in v1.2.0

func (t *PostgresTable) RowLevelSecurityInstructions() []Instruction

PostgreSQL accepts no row level security option in a CREATE TABLE statement.

func (*PostgresTable) RuleByName added in v1.2.0

func (t *PostgresTable) RuleByName(name string) (*PostgresRule, bool)

func (*PostgresTable) RuleInstructions added in v1.2.0

func (t *PostgresTable) RuleInstructions() []Instruction

func (*PostgresTable) TriggerByName added in v1.2.0

func (t *PostgresTable) TriggerByName(name string) (*PostgresTrigger, bool)

type PostgresTableData added in v1.2.0

type PostgresTableData struct {
	Keys []string
	Rows map[string]map[string]string
}

type PostgresTrigger added in v1.2.0

type PostgresTrigger struct {
	Name       string
	Def        string
	EnableMode string
}

func (*PostgresTrigger) CreateInstruction added in v1.2.0

func (t *PostgresTrigger) CreateInstruction() *PostgresCreateTriggerInstruction

func (*PostgresTrigger) EnableInstructions added in v1.2.0

func (t *PostgresTrigger) EnableInstructions(tableName string) []Instruction

A CREATE TRIGGER statement accepts no mode, and PostgreSQL builds every trigger with ENABLE, so that mode needs no statement.

type PostgresTriggerEnableAction added in v1.2.0

type PostgresTriggerEnableAction struct {
	Mode string

	TriggerName string
}

func (*PostgresTriggerEnableAction) TableActionClause added in v1.2.0

func (a *PostgresTriggerEnableAction) TableActionClause() string

type PostgresType added in v1.2.0

type PostgresType struct {
	Name    string
	Values  []string
	Comment string
}

func (*PostgresType) CreateInstruction added in v1.2.0

func (t *PostgresType) CreateInstruction() *PostgresCreateEnumTypeInstruction

func (*PostgresType) Diff added in v1.2.0

func (t *PostgresType) Diff(other *PostgresType) []Instruction

PostgreSQL adds a value to an enum, but it removes none and it moves none.

func (*PostgresType) Instructions added in v1.2.0

func (t *PostgresType) Instructions() []Instruction

CREATE TYPE accepts no comment, so the comment takes its own statement.

func (*PostgresType) StartsWith added in v1.2.0

func (t *PostgresType) StartsWith(other *PostgresType) bool

type PostgresView added in v1.2.0

type PostgresView struct {
	Name    string
	Def     string
	Columns []*PostgresViewColumn

	// The query text of the view holds no check option, so the diff compares this field too.
	CheckOption string

	Comment string
}

func (*PostgresView) CreateInstruction added in v1.2.0

func (v *PostgresView) CreateInstruction() *PostgresCreateViewInstruction

func (*PostgresView) HasEqualColumns added in v1.2.0

func (v *PostgresView) HasEqualColumns(other *PostgresView) bool

func (*PostgresView) Instructions added in v1.2.0

func (v *PostgresView) Instructions() []Instruction

CREATE VIEW accepts no comment, so the comment takes its own statement.

type PostgresViewColumn added in v1.2.0

type PostgresViewColumn struct {
	Table  string
	Column string
	Type   string
}

A type change of a column keeps the definition text of the view equal, so the diff compares the columns too.

type SQLCommentInstruction added in v1.2.0

type SQLCommentInstruction struct {
	Text string
}

func (*SQLCommentInstruction) Comment added in v1.2.0

func (i *SQLCommentInstruction) Comment() string

A comment of the output takes no comment of its own.

func (*SQLCommentInstruction) String added in v1.2.0

func (i *SQLCommentInstruction) String() string

type SQLConjunctionCondition added in v1.2.0

type SQLConjunctionCondition struct {
	Conditions []Condition
}

func (*SQLConjunctionCondition) ConditionClause added in v1.2.0

func (c *SQLConjunctionCondition) ConditionClause() string

type SQLDeleteInstruction added in v1.2.0

type SQLDeleteInstruction struct {
	TableName string
	Condition Condition
}

func (*SQLDeleteInstruction) Comment added in v1.2.0

func (i *SQLDeleteInstruction) Comment() string

func (*SQLDeleteInstruction) String added in v1.2.0

func (i *SQLDeleteInstruction) String() string

type SQLDropColumnAction added in v1.2.0

type SQLDropColumnAction struct {
	ColumnName string
}

func (*SQLDropColumnAction) TableActionClause added in v1.2.0

func (a *SQLDropColumnAction) TableActionClause() string

type SQLDropIndexInstruction added in v1.2.0

type SQLDropIndexInstruction struct {
	Name string
}

func (*SQLDropIndexInstruction) Comment added in v1.2.0

func (i *SQLDropIndexInstruction) Comment() string

func (*SQLDropIndexInstruction) String added in v1.2.0

func (i *SQLDropIndexInstruction) String() string

type SQLDropTableInstruction added in v1.2.0

type SQLDropTableInstruction struct {
	Name string
}

func (*SQLDropTableInstruction) Comment added in v1.2.0

func (i *SQLDropTableInstruction) Comment() string

func (*SQLDropTableInstruction) String added in v1.2.0

func (i *SQLDropTableInstruction) String() string

type SQLDropViewInstruction added in v1.2.0

type SQLDropViewInstruction struct {
	Name string
}

func (*SQLDropViewInstruction) Comment added in v1.2.0

func (i *SQLDropViewInstruction) Comment() string

func (*SQLDropViewInstruction) String added in v1.2.0

func (i *SQLDropViewInstruction) String() string

type SQLEqualityCondition added in v1.2.0

type SQLEqualityCondition struct {
	ColumnName string
	Expression string
}

func (*SQLEqualityCondition) ConditionClause added in v1.2.0

func (c *SQLEqualityCondition) ConditionClause() string

type SQLInsertInstruction added in v1.2.0

type SQLInsertInstruction struct {
	TableName   string
	ColumnNames []string
	Expressions []string
}

func (*SQLInsertInstruction) Comment added in v1.2.0

func (i *SQLInsertInstruction) Comment() string

func (*SQLInsertInstruction) String added in v1.2.0

func (i *SQLInsertInstruction) String() string

type SQLInsertSelectInstruction added in v1.2.0

type SQLInsertSelectInstruction struct {
	TableName         string
	ColumnNames       []string
	SelectExpressions []string
	SourceTableName   string
}

func (*SQLInsertSelectInstruction) Comment added in v1.2.0

func (i *SQLInsertSelectInstruction) Comment() string

func (*SQLInsertSelectInstruction) String added in v1.2.0

func (i *SQLInsertSelectInstruction) String() string

type SQLIsNullCondition added in v1.2.0

type SQLIsNullCondition struct {
	ColumnName string
}

func (*SQLIsNullCondition) ConditionClause added in v1.2.0

func (c *SQLIsNullCondition) ConditionClause() string

type SQLRenameColumnAction added in v1.2.0

type SQLRenameColumnAction struct {
	ColumnName    string
	NewColumnName string
}

func (*SQLRenameColumnAction) TableActionClause added in v1.2.0

func (a *SQLRenameColumnAction) TableActionClause() string

type SQLRenameTableAction added in v1.2.0

type SQLRenameTableAction struct {
	NewName string
}

func (*SQLRenameTableAction) TableActionClause added in v1.2.0

func (a *SQLRenameTableAction) TableActionClause() string

type SQLSetClause added in v1.2.0

type SQLSetClause struct {
	ColumnName string
	Expression string
}

func (*SQLSetClause) Clause added in v1.2.0

func (c *SQLSetClause) Clause() string

type SQLSource added in v1.2.0

type SQLSource struct {
	Path  string
	Files []string
}

func NewSQLSource added in v1.2.0

func NewSQLSource(path string) (*SQLSource, error)

func (*SQLSource) ApplyTo added in v1.2.0

func (s *SQLSource) ApplyTo(ctx context.Context, db *sql.DB) error

type SQLUpdateInstruction added in v1.2.0

type SQLUpdateInstruction struct {
	TableName  string
	SetClauses []*SQLSetClause
	Condition  Condition
}

func (*SQLUpdateInstruction) Comment added in v1.2.0

func (i *SQLUpdateInstruction) Comment() string

func (*SQLUpdateInstruction) String added in v1.2.0

func (i *SQLUpdateInstruction) String() string

type SQLiteAddColumnAction added in v1.2.0

type SQLiteAddColumnAction struct {
	Column *SQLiteColumn
}

func (*SQLiteAddColumnAction) TableActionClause added in v1.2.0

func (a *SQLiteAddColumnAction) TableActionClause() string

type SQLiteAlterTableInstruction added in v1.2.0

type SQLiteAlterTableInstruction struct {
	Name   string
	Action AlterTableAction
}

func (*SQLiteAlterTableInstruction) Comment added in v1.2.0

func (i *SQLiteAlterTableInstruction) Comment() string

func (*SQLiteAlterTableInstruction) String added in v1.2.0

func (i *SQLiteAlterTableInstruction) String() string

type SQLiteCheckConstraint added in v1.2.0

type SQLiteCheckConstraint struct {
	Name       string
	Expression string
}

No PRAGMA reports a check, so parseTableDefinition reads it from the CREATE TABLE.

func (*SQLiteCheckConstraint) Clause added in v1.2.0

func (c *SQLiteCheckConstraint) Clause() string

func (*SQLiteCheckConstraint) Equal added in v1.2.0

type SQLiteColumn

type SQLiteColumn struct {
	Name string
	Type string

	NotNull bool

	PrimaryKey bool

	Unique bool

	Default sql.NullString

	// The value holds the enclosing parentheses.
	GeneratedExpression string

	GeneratedStored bool

	AutoIncrement bool

	Collation string

	Check string

	PrimaryKeyConflict string
	UniqueConflict     string
	NotNullConflict    string

	// ForeignKeyDeferrable holds the DEFERRABLE clause of a REFERENCES constraint of this
	// column. The foreign key of the table keeps that clause, and Definition writes none.
	ForeignKeyDeferrable string
}

func (*SQLiteColumn) Copy

func (c *SQLiteColumn) Copy() *SQLiteColumn

func (*SQLiteColumn) Definition added in v1.2.0

func (c *SQLiteColumn) Definition() string

func (*SQLiteColumn) HasEqualAttributes

func (c *SQLiteColumn) HasEqualAttributes(other *SQLiteColumn) bool

func (*SQLiteColumn) IsGenerated added in v1.2.0

func (c *SQLiteColumn) IsGenerated() bool

func (*SQLiteColumn) IsTypeChangeCompatible added in v1.2.0

func (c *SQLiteColumn) IsTypeChangeCompatible(other *SQLiteColumn) bool

type SQLiteCreateIndexInstruction added in v1.2.0

type SQLiteCreateIndexInstruction struct {
	Unique    bool
	Name      string
	TableName string
	Keys      []string
	Condition Condition
}

func (*SQLiteCreateIndexInstruction) Comment added in v1.2.0

func (i *SQLiteCreateIndexInstruction) Comment() string

func (*SQLiteCreateIndexInstruction) String added in v1.2.0

type SQLiteCreateTableInstruction added in v1.2.0

type SQLiteCreateTableInstruction struct {
	Name               string
	Columns            []*SQLiteColumn
	PrimaryKey         []string
	PrimaryKeyName     string
	PrimaryKeyConflict string

	// A key clause holds the quoted column name with its COLLATE clause and its DESC
	// keyword. An empty list keeps the plain names of PrimaryKey.
	PrimaryKeyKeys []string

	UniqueConstraints []*SQLiteUniqueConstraint
	ForeignKeys       []*SQLiteForeignKey
	CheckConstraints  []*SQLiteCheckConstraint
	// SQLite accepts a table option after the closing parenthesis. WITHOUT ROWID comes
	// first, because SQLite refuses the reverse order.
	WithoutRowID bool
	Strict       bool
}

func (*SQLiteCreateTableInstruction) Comment added in v1.2.0

func (i *SQLiteCreateTableInstruction) Comment() string

func (*SQLiteCreateTableInstruction) String added in v1.2.0

type SQLiteCreateTriggerInstruction added in v1.2.0

type SQLiteCreateTriggerInstruction struct {
	Definition string
}

func (*SQLiteCreateTriggerInstruction) Comment added in v1.2.0

func (*SQLiteCreateTriggerInstruction) String added in v1.2.0

type SQLiteCreateViewInstruction added in v1.2.0

type SQLiteCreateViewInstruction struct {
	Definition string
}

func (*SQLiteCreateViewInstruction) Comment added in v1.2.0

func (i *SQLiteCreateViewInstruction) Comment() string

func (*SQLiteCreateViewInstruction) String added in v1.2.0

func (i *SQLiteCreateViewInstruction) String() string

type SQLiteCreateVirtualTableInstruction added in v1.2.0

type SQLiteCreateVirtualTableInstruction struct {
	Definition string
}

func (*SQLiteCreateVirtualTableInstruction) Comment added in v1.2.0

func (*SQLiteCreateVirtualTableInstruction) String added in v1.2.0

type SQLiteDriver

type SQLiteDriver struct {
	TargetDatabaseConnection *sql.DB
	SourceDatabaseConnection *sql.DB
	CompareData              bool
	// contains filtered or unexported fields
}

func NewSQLiteDriver

func NewSQLiteDriver(ctx context.Context, config *SQLiteDriverConfig) (*SQLiteDriver, error)

func (*SQLiteDriver) Close

func (d *SQLiteDriver) Close() error

func (*SQLiteDriver) Diff

func (d *SQLiteDriver) Diff(ctx context.Context) ([]Instruction, error)

func (*SQLiteDriver) DiffData added in v1.2.0

func (d *SQLiteDriver) DiffData(ctx context.Context) ([]Instruction, error)

The schema section already creates or drops the other tables.

func (*SQLiteDriver) DiffTableData added in v1.2.0

func (d *SQLiteDriver) DiffTableData(ctx context.Context, targetTable *SQLiteTable, sourceTable *SQLiteTable) ([]Instruction, []Instruction, error)

func (*SQLiteDriver) DiffTables added in v1.2.0

func (d *SQLiteDriver) DiffTables(ctx context.Context) ([]Instruction, error)

func (*SQLiteDriver) DiffViews added in v1.2.0

func (d *SQLiteDriver) DiffViews(ctx context.Context) ([]Instruction, error)

func (*SQLiteDriver) DiffVirtualTables added in v1.2.0

func (d *SQLiteDriver) DiffVirtualTables(ctx context.Context) ([]Instruction, error)

func (*SQLiteDriver) GetIndexColumnNames added in v1.2.0

func (d *SQLiteDriver) GetIndexColumnNames(ctx context.Context, db *sql.DB, indexName string) ([]string, error)

func (*SQLiteDriver) GetIndexDefinitions added in v1.2.0

func (d *SQLiteDriver) GetIndexDefinitions(ctx context.Context, db *sql.DB, tableName string) (map[string]string, error)

An index that a UNIQUE constraint or a PRIMARY KEY builds holds no text.

func (*SQLiteDriver) GetIndexKeys added in v1.2.0

func (d *SQLiteDriver) GetIndexKeys(ctx context.Context, db *sql.DB, indexName string, definitionKeys []string) ([]string, error)

PRAGMA index_info gives no name for an expression key, no direction, and no collation, so definitionKeys and indexKeyModifiers read those parts from the text.

func (*SQLiteDriver) GetTable added in v1.2.0

func (d *SQLiteDriver) GetTable(ctx context.Context, db *sql.DB, tableName string) (*SQLiteTable, error)

func (*SQLiteDriver) GetTableColumns added in v1.2.0

func (d *SQLiteDriver) GetTableColumns(ctx context.Context, db *sql.DB, tableName string) ([]*SQLiteColumn, error)

PRAGMA table_info gives no generated column, so this method reads PRAGMA table_xinfo. That PRAGMA gives no expression, so parseTableDefinition reads it.

func (*SQLiteDriver) GetTableData added in v1.2.0

func (d *SQLiteDriver) GetTableData(ctx context.Context, db *sql.DB, tableName string, columnNames []string, primaryKeyColumnNames []string) (*SQLiteTableData, error)

func (*SQLiteDriver) GetTableDefinition added in v1.2.0

func (d *SQLiteDriver) GetTableDefinition(ctx context.Context, db *sql.DB, tableName string) (string, error)

func (*SQLiteDriver) GetTableForeignKeys added in v1.2.0

func (d *SQLiteDriver) GetTableForeignKeys(ctx context.Context, db *sql.DB, tableName string) ([]*SQLiteForeignKey, error)

func (*SQLiteDriver) GetTableIndexes added in v1.2.0

func (d *SQLiteDriver) GetTableIndexes(ctx context.Context, db *sql.DB, tableName string) ([]*SQLiteIndex, error)

func (*SQLiteDriver) GetTablePrimaryKey added in v1.2.0

func (d *SQLiteDriver) GetTablePrimaryKey(ctx context.Context, db *sql.DB, tableName string) ([]string, error)

func (*SQLiteDriver) GetTableUniqueKeys added in v1.2.0

func (d *SQLiteDriver) GetTableUniqueKeys(ctx context.Context, db *sql.DB, tableName string) ([][]string, error)

This method sorts the keys, because SQLite gives no stable order.

func (*SQLiteDriver) GetTables added in v1.2.0

func (d *SQLiteDriver) GetTables(ctx context.Context, db *sql.DB) ([]*SQLiteTable, error)

A virtual table takes its own statement, and a shadow table belongs to its module. The order of sqlite_master is the order of the creation, so a table that holds a foreign key comes after the table that it names. Keep that order.

func (*SQLiteDriver) GetTriggers added in v1.2.0

func (d *SQLiteDriver) GetTriggers(ctx context.Context, db *sql.DB, objectName string) ([]*SQLiteTrigger, error)

func (*SQLiteDriver) GetViews added in v1.2.0

func (d *SQLiteDriver) GetViews(ctx context.Context, db *sql.DB) ([]*SQLiteView, error)

func (*SQLiteDriver) GetVirtualTables added in v1.2.0

func (d *SQLiteDriver) GetVirtualTables(ctx context.Context, db *sql.DB) ([]*SQLiteVirtualTable, error)

func (*SQLiteDriver) OpenSide added in v1.2.0

func (d *SQLiteDriver) OpenSide(ctx context.Context, path string, role string) (*sql.DB, error)

func (*SQLiteDriver) RemoveTemporaryDirectory added in v1.2.0

func (d *SQLiteDriver) RemoveTemporaryDirectory() error

func (*SQLiteDriver) TableDataInstructions added in v1.2.0

func (d *SQLiteDriver) TableDataInstructions(ctx context.Context, targetTable *SQLiteTable) ([]Instruction, error)

The schema section creates this table with no row, so every target row becomes an INSERT statement.

func (*SQLiteDriver) TemporaryDirectory added in v1.2.0

func (d *SQLiteDriver) TemporaryDirectory() (string, error)

type SQLiteDriverConfig added in v1.2.0

type SQLiteDriverConfig struct {
	TargetDatabasePath string
	SourceDatabasePath string
	CompareData        bool
}

type SQLiteDropTriggerInstruction added in v1.2.0

type SQLiteDropTriggerInstruction struct {
	Name string
}

func (*SQLiteDropTriggerInstruction) Comment added in v1.2.0

func (i *SQLiteDropTriggerInstruction) Comment() string

func (*SQLiteDropTriggerInstruction) String added in v1.2.0

type SQLiteForeignKey added in v1.2.0

type SQLiteForeignKey struct {
	Name string

	Table    string
	From     []string
	To       []string
	OnUpdate string
	OnDelete string

	Deferrable string
}

func (*SQLiteForeignKey) Clause added in v1.2.0

func (fk *SQLiteForeignKey) Clause() string

func (*SQLiteForeignKey) Equal added in v1.2.0

func (fk *SQLiteForeignKey) Equal(other *SQLiteForeignKey) bool

type SQLiteIndex

type SQLiteIndex struct {
	Table string
	Name  string

	// A key holds the SQL text of one key part, so an expression key keeps its text.
	Keys  []string
	Where string

	Unique bool
}

func (*SQLiteIndex) CreateInstruction added in v1.2.0

func (i *SQLiteIndex) CreateInstruction() *SQLiteCreateIndexInstruction

func (*SQLiteIndex) Equal

func (i *SQLiteIndex) Equal(other *SQLiteIndex) bool

type SQLiteIndexPredicateCondition added in v1.2.0

type SQLiteIndexPredicateCondition struct {
	Expression string
}

func (*SQLiteIndexPredicateCondition) ConditionClause added in v1.2.0

func (c *SQLiteIndexPredicateCondition) ConditionClause() string

type SQLitePragmaForeignKeysInstruction added in v1.2.0

type SQLitePragmaForeignKeysInstruction struct {
	Enabled bool
}

func (*SQLitePragmaForeignKeysInstruction) Comment added in v1.2.0

func (*SQLitePragmaForeignKeysInstruction) String added in v1.2.0

type SQLiteTable

type SQLiteTable struct {
	Name    string
	Columns []*SQLiteColumn

	// These two fields hold a key or a constraint of two or more columns only.
	PrimaryKey         []string
	PrimaryKeyName     string
	PrimaryKeyConflict string
	UniqueConstraints  []*SQLiteUniqueConstraint

	// A key clause holds the quoted column name with its COLLATE clause and its DESC
	// keyword, which no PRAGMA reports.
	PrimaryKeyKeys []string

	Indexes     []*SQLiteIndex
	Triggers    []*SQLiteTrigger
	ForeignKeys []*SQLiteForeignKey

	CheckConstraints []*SQLiteCheckConstraint

	WithoutRowID bool
	Strict       bool
}

func (*SQLiteTable) ColumnByName

func (t *SQLiteTable) ColumnByName(name string) (*SQLiteColumn, bool)

func (*SQLiteTable) Copy

func (t *SQLiteTable) Copy() *SQLiteTable

func (*SQLiteTable) CreateTableInstruction added in v1.2.0

func (t *SQLiteTable) CreateTableInstruction() *SQLiteCreateTableInstruction

func (*SQLiteTable) DiffColumns added in v1.2.0

func (t *SQLiteTable) DiffColumns(other *SQLiteTable) *SQLiteTableColumnsDiff

func (*SQLiteTable) DiffIndexes added in v1.2.0

func (t *SQLiteTable) DiffIndexes(other *SQLiteTable) ([]Instruction, error)

func (*SQLiteTable) DiffTable added in v1.2.0

func (t *SQLiteTable) DiffTable(other *SQLiteTable) ([]Instruction, error)

func (*SQLiteTable) DiffTriggers added in v1.2.0

func (t *SQLiteTable) DiffTriggers(other *SQLiteTable) ([]Instruction, error)

func (*SQLiteTable) IndexByName

func (t *SQLiteTable) IndexByName(name string) (*SQLiteIndex, bool)

func (*SQLiteTable) IndexInstructions added in v1.2.0

func (t *SQLiteTable) IndexInstructions() []Instruction

func (*SQLiteTable) Instructions added in v1.2.0

func (t *SQLiteTable) Instructions() []Instruction

func (*SQLiteTable) PrimaryKeyColumnNames added in v1.2.0

func (t *SQLiteTable) PrimaryKeyColumnNames() []string

func (*SQLiteTable) TriggerByName

func (t *SQLiteTable) TriggerByName(name string) (*SQLiteTrigger, bool)

func (*SQLiteTable) TriggerInstructions added in v1.2.0

func (t *SQLiteTable) TriggerInstructions() []Instruction

type SQLiteTableColumnsDiff added in v1.2.0

type SQLiteTableColumnsDiff struct {
	Added    []string
	Modified []string
	Removed  []string
	Renamed  map[string]string

	ForeignKeysChanged  bool
	ConstraintsChanged  bool
	TableOptionsChanged bool
	ColumnOrderChanged  bool

	AddsStoredGeneratedColumn bool
}

func (*SQLiteTableColumnsDiff) NeedsRecreation added in v1.2.0

func (d *SQLiteTableColumnsDiff) NeedsRecreation() bool

SQLite supports no ALTER COLUMN, so a modified column, a changed foreign key, a changed table constraint, or a changed table option needs a new table. SQLite also refuses an ADD COLUMN action that holds a STORED generated column.

type SQLiteTableData added in v1.2.0

type SQLiteTableData struct {
	Keys []string
	Rows map[string]map[string]string
}

type SQLiteTableDefinition added in v1.2.0

type SQLiteTableDefinition struct {
	Columns            map[string]*SQLiteColumn
	CheckConstraints   []*SQLiteCheckConstraint
	UniqueNames        map[string]string
	ForeignKeyNames    map[string]string
	UniqueConflicts    map[string]string
	UniqueKeys         map[string][]string
	ForeignKeyDefers   map[string]string
	PrimaryKeyName     string
	PrimaryKeyConflict string
	PrimaryKeyKeys     []string
	WithoutRowID       bool
	Strict             bool
}

PRAGMA table_xinfo gives no expression of a generated column, and no PRAGMA reports a collation, the keyword AUTOINCREMENT, or a check.

func (*SQLiteTableDefinition) ColumnByName added in v1.2.0

func (d *SQLiteTableDefinition) ColumnByName(name string) (*SQLiteColumn, bool)

func (*SQLiteTableDefinition) DeferrableOf added in v1.2.0

func (d *SQLiteTableDefinition) DeferrableOf(columns []string) string

func (*SQLiteTableDefinition) ForeignKeyNameOf added in v1.2.0

func (d *SQLiteTableDefinition) ForeignKeyNameOf(columns []string) string

func (*SQLiteTableDefinition) UniqueConflictOf added in v1.2.0

func (d *SQLiteTableDefinition) UniqueConflictOf(columns []string) string

func (*SQLiteTableDefinition) UniqueKeysOf added in v1.2.0

func (d *SQLiteTableDefinition) UniqueKeysOf(columns []string) []string

func (*SQLiteTableDefinition) UniqueNameOf added in v1.2.0

func (d *SQLiteTableDefinition) UniqueNameOf(columns []string) string

type SQLiteTrigger

type SQLiteTrigger struct {
	Name string
	SQL  string
}

type SQLiteUniqueConstraint added in v1.2.0

type SQLiteUniqueConstraint struct {
	Name string

	Columns []string

	// A key clause holds the quoted column name with its COLLATE clause and its DESC
	// keyword, which no PRAGMA reports. An empty list keeps the plain names of Columns.
	Keys []string

	Conflict string
}

func (*SQLiteUniqueConstraint) Clause added in v1.2.0

func (c *SQLiteUniqueConstraint) Clause() string

func (*SQLiteUniqueConstraint) Equal added in v1.2.0

type SQLiteView added in v1.2.0

type SQLiteView struct {
	Name     string
	SQL      string
	Triggers []*SQLiteTrigger
}

func (*SQLiteView) Diff added in v1.2.0

func (v *SQLiteView) Diff(other *SQLiteView) ([]Instruction, error)

A DROP VIEW statement removes every trigger of the view.

func (*SQLiteView) DiffTriggers added in v1.2.0

func (v *SQLiteView) DiffTriggers(other *SQLiteView) []Instruction

func (*SQLiteView) Instructions added in v1.2.0

func (v *SQLiteView) Instructions() []Instruction

func (*SQLiteView) TriggerByName added in v1.2.0

func (v *SQLiteView) TriggerByName(name string) (*SQLiteTrigger, bool)

func (*SQLiteView) TriggerInstructions added in v1.2.0

func (v *SQLiteView) TriggerInstructions() []Instruction

type SQLiteVirtualTable added in v1.2.0

type SQLiteVirtualTable struct {
	Name string

	// The statement holds no semicolon.
	SQL string
}

SQLite holds no ALTER statement for a virtual table, so a new definition prints a DROP statement and a CREATE statement. The module builds the shadow tables.

func (*SQLiteVirtualTable) CreateInstruction added in v1.2.0

func (*SQLiteVirtualTable) DropInstruction added in v1.2.0

func (t *SQLiteVirtualTable) DropInstruction() *SQLDropTableInstruction

type SectionDiff added in v1.2.0

type SectionDiff struct {
	EarlyRemovals []Instruction
	Additions     []Instruction
	Removals      []Instruction
}

An early removal covers the object that blocks an addition of another section.

Jump to

Keyboard shortcuts

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