Documentation ¶
Overview ¶
Package sch1v1 provides the top-level Migrator type for database schema version 1.1.x which can be used for starting a multi-database migration operation. This package contains the main logic for querying of v1.1 schema and converting them to the latest supported minor version within the major version 1 series.
Since schXvY packages only depend on their highest minor version implementation for creation of their corresponding upwards/downwards migrators and settlers, they can be adapted to a version-independent interface using a common Adapter interface which is provided by the schi.Adapter generic type (in contrast to the upwards/downwards migrator types in upmigN/dnmigN packages which have to ship their distinct Adapter types).
Each schema minor-version specific package contains (and embeds) a file, namely lmv.sql, standing for the last-minor-version which contains the required DDL statements in order to create views in an intermediate migration schema, representing the last supported minor version within the same major version, based on the current minor version views which are prepared by the Load method. That is, lmv.sql specifies how we may migrate upwards from this minor version to the last supported minor version without switching the major version.
Index ¶
Constants ¶
const ( Major = 1 Minor = 1 Patch = 0 )
These constants define the major, minor, and patch version of the database schema which is managed by Migrator struct in this package.
Variables ¶
This section is empty.
Functions ¶
func LoadSettings ¶ added in v1.2.0
LoadSettings loads the serialized mutable settings from the database using the given `c` connection, assuming that the database schema version is equal to v1.1 as specified by the Major and Minor consts.
func New ¶
New creates a Migrator struct wrapping the given `tx` transaction from the destination database and `url` URL representing the source database connection information. The created Migrator instance is then wrapped by a schi.Adapter in order to adapt its version dependent interface (see Type type alias) to a version independent repo.Migrator[repo.SchemaSettler] interface.
Types ¶
type Migrator ¶
type Migrator struct {
// contains filtered or unexported fields
}
Migrator implements Type generic interface in order to provide high-level database schema migration logic for the v1.1 schema. It may be created with an open transaction of the destination database and a URL containing the source database connection info. The migration logic starts by calling the Load method which makes source database schema (having v1.1 format) accessible from the destination database. Then UpMigrator or DownMigrator method should be called in order to convert them (by creating relevant views and without actual transfer of data items as far as possible) into the latest available minor version within the v1 major version. Obtained upwards/downwards migrator object (having the U/D type) may be used for changing the major version (keeping the minor version at its latest supported version in each major version). Finally, the settler object is used to persist the migration. If the ultimate major version is v1 too, the Settler method may be used as a shortcut for migrating from the current minor version to the latest supported minor version and returning an instance of the settler object (having the S type) for persisting it.
func (*Migrator) DownMigrator ¶
DownMigrator expects the fdw1_1 schema to contain the source database contents (created by the Load method) and it fills the mig1 local schema using a series of views, keeping the v1.1 schema unchanged. Finally, it returns an instance of the downwards migrator object (having the D type) which can be used to migrate schema to the previous major versions (if any) or obtain the settler object.
func (*Migrator) Load ¶
Load creates a Foreign Data Wrapper (FDW) link from the destination database to the source database (having the connection information of the source database) and imports the source database schema into a local schema. Thereafter, queries in the destination database transaction may access the source database contents. This method must be called (and returned without error) before it is possible to call any other method of the Migrator struct.
func (*Migrator) Settler ¶
Settler returns a settler object for the database schema v1 major version. Beforehand, it migrates the database schema from its current minor version (represented by Minor const) to the latest available minor version. This upwards migration is also applicable to the latest supported minor version itself, because the Load method (which must be called before calling Settler method) will put the remote tables in a schema such as fdw1_1 while the settler object expects a schema such as mig1 for its data persistence queries.
func (*Migrator) UpMigrator ¶
UpMigrator expects the fdw1_1 schema to contain the source database contents (created by the Load method) and it fills the mig1 local schema using a series of views, keeping the v1.1 schema unchanged. Finally, it returns an instance of the upwards migrator object (having the U type) which can be used to migrate schema to the next major versions (if any) or obtain the settler object.