Documentation
¶
Index ¶
- Variables
- type BaselineMigration
- type HistoryEntry
- type State
- func (s *State) Close() error
- func (s *State) Complete(ctx context.Context, schema, name string) error
- func (s *State) CreateBaseline(ctx context.Context, schemaName, baselineVersion string) error
- func (s *State) GetActiveMigration(ctx context.Context, schema string) (*migrations.Migration, error)
- func (s *State) HasExistingSchemaWithoutHistory(ctx context.Context, schemaName string) (bool, error)
- func (s *State) Init(ctx context.Context) error
- func (s *State) IsActiveMigrationPeriod(ctx context.Context, schema string) (bool, error)
- func (s *State) IsInitialized(ctx context.Context) (bool, error)
- func (s *State) LatestBaseline(ctx context.Context, schemaName string) (*BaselineMigration, error)
- func (s *State) LatestMigration(ctx context.Context, schema string) (*string, error)
- func (s *State) LatestVersion(ctx context.Context, schema string) (*string, error)
- func (s *State) PgConn() *sql.DB
- func (s *State) PreviousMigration(ctx context.Context, schema string) (*string, error)
- func (s *State) PreviousVersion(ctx context.Context, schema string) (*string, error)
- func (s *State) ReadSchema(ctx context.Context, schemaName string) (*schema.Schema, error)
- func (s *State) Rollback(ctx context.Context, schema, name string) error
- func (s *State) Schema() string
- func (s *State) SchemaAfterMigration(ctx context.Context, schemaName, version string) (*schema.Schema, error)
- func (s *State) SchemaHistory(ctx context.Context, schema string) ([]HistoryEntry, error)
- func (s *State) SchemaVersion(ctx context.Context) (string, error)
- func (s *State) Start(ctx context.Context, schemaname string, migration *migrations.Migration) error
- func (s *State) VersionCompatibility(ctx context.Context) (VersionCompatibility, error)
- type StateOpt
- type VersionCompatibility
Constants ¶
This section is empty.
Variables ¶
var ErrNewPgrollSchema = errors.New("pgroll binary version is older than pgroll schema version")
var ErrNoActiveMigration = errors.New("no active migration")
Functions ¶
This section is empty.
Types ¶
type BaselineMigration ¶ added in v0.13.0
BaselineMigration represents a baseline migration record
type HistoryEntry ¶ added in v0.12.0
type HistoryEntry struct {
Migration migrations.RawMigration
CreatedAt time.Time
}
HistoryEntry represents a single migration in the migration history of a schema
type State ¶
type State struct {
// contains filtered or unexported fields
}
func (*State) CreateBaseline ¶ added in v0.13.0
CreateBaseline creates a baseline migration that captures the current state of the schema. It marks the migration as 'baseline' type and completed (done=true). This is used when you want to start using pgroll with an existing database.
func (*State) GetActiveMigration ¶
func (s *State) GetActiveMigration(ctx context.Context, schema string) (*migrations.Migration, error)
GetActiveMigration returns the name & raw content of the active migration (if any), errors out otherwise
func (*State) HasExistingSchemaWithoutHistory ¶ added in v0.13.0
func (s *State) HasExistingSchemaWithoutHistory(ctx context.Context, schemaName string) (bool, error)
HasExistingSchemaWithoutHistory checks if there's an existing schema with tables but no migration history. Returns true if the schema exists, has tables, but has no pgroll migration history
func (*State) IsActiveMigrationPeriod ¶
IsActiveMigrationPeriod returns true if there is an active migration
func (*State) IsInitialized ¶ added in v0.11.0
IsInitialized checks if the pgroll state schema is initialized.
func (*State) LatestBaseline ¶ added in v0.13.0
LatestBaseline returns the most recent baseline migration for a schema, or nil if no baseline exists
func (*State) LatestMigration ¶ added in v0.14.0
LatestMigration returns the name of the latest migration, or nil if there is none.
func (*State) LatestVersion ¶
LatestVersion returns the name of the latest version schema, or nil if there is none.
func (*State) PreviousMigration ¶ added in v0.14.0
PreviousMigration returns the name of the previous migration, or nil if there is none.
func (*State) PreviousVersion ¶
PreviousVersion returns the name of the previous version schema
func (*State) ReadSchema ¶
ReadSchema reads the schema for the specified schema name
func (*State) Rollback ¶
Rollback removes a migration from the state (we consider it rolled back, as if it never started)
func (*State) SchemaAfterMigration ¶ added in v0.9.0
func (s *State) SchemaAfterMigration(ctx context.Context, schemaName, version string) (*schema.Schema, error)
SchemaAfterMigration reads the schema after the migration `version` was applied to `schemaName`
func (*State) SchemaHistory ¶ added in v0.8.0
SchemaHistory returns all migrations applied to a schema since the most recent baseline in ascending timestamp order
func (*State) SchemaVersion ¶ added in v0.14.0
SchemaVersion retrieves the version stored in the pgroll_version table.
func (*State) Start ¶
func (s *State) Start(ctx context.Context, schemaname string, migration *migrations.Migration) error
Start creates a new migration, storing its name and raw content this will effectively activate a new migration period, so `IsActiveMigrationPeriod` will return true until the migration is completed This method will return the current schema (before the migration is applied)
func (*State) VersionCompatibility ¶ added in v0.14.0
func (s *State) VersionCompatibility(ctx context.Context) (VersionCompatibility, error)
VersionCompatibility compares the pgroll version that was used to initialize the `State` instance with the version of the pgroll state schema.
type StateOpt ¶ added in v0.14.0
type StateOpt func(s *State)
func WithPgrollVersion ¶ added in v0.14.0
WithPgrollVersion sets the version of `pgroll` that is constructing the State instance
type VersionCompatibility ¶ added in v0.14.0
type VersionCompatibility int
VersionCompatibility represents the result of comparing pgroll binary and state schema versions
const ( VersionCompatCheckSkipped VersionCompatibility = iota VersionCompatNotInitialized VersionCompatVersionSchemaOlder VersionCompatVersionSchemaEqual VersionCompatVersionSchemaNewer )