Documentation ¶
Overview ¶
Package stlmig1 provides Settler type for database schema major version 1 with two main usages. First, it can be used to initialize a database with major version 1 schema, having development or production suitable sample data. Second, it can be used to settle a multi-database schema migration operation by reading views from an intermediate schema and filling tables in the target schema without converting their format (e.g., column names) in order to persist the migration results.
Each settlement package contains (and embeds) four .sql files. The schema.sql contains DDL statements for creating database schema tables with Major major version. The dev.sql and prod.sql files contain data insertion statements and may be executed after feeding the schema.sql file in order to insert initial sample data which are suitable for a development or production environment respectively. Fourth and last file is settle.sql which is used to settle views of an intermediate migration schema, filling the Major major version tables (which must be created by schema.sql previously) with the data rows which were prepared by the migration process.
Index ¶
- Constants
- type Settler
- func (sm1 *Settler) InitDevSchema(ctx context.Context) error
- func (sm1 *Settler) InitProdSchema(ctx context.Context) error
- func (sm1 *Settler) MajorVersion() uint
- func (sm1 *Settler) PersistSettings(ctx context.Context, mutableSettings, minb, maxb []byte) error
- func (sm1 *Settler) SettleSchema(ctx context.Context) error
Constants ¶
const ( Major = 1 Minor = 2 Patch = 0 )
These constants indicate the major, minor, and patch components of the database schema migration settler implementation. Each major version has a separate stlmigN package and the Minor is the latest supported minor version within the Major major version series.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Settler ¶
type Settler struct {
// contains filtered or unexported fields
}
Settler struct provides the database schema migration settlement logic for the major version 1. Settlement is the last phase of migration which persists the prepared database views contents into their corresponding tables. See the SettleSchema method for this use case. It can also be used for creation and filling of tables with the development and production suitable initial data. Check the InitDevSchema and InitProdSchema methods for this purpose.
Each instance of Settler wraps and uses a single transaction of the destination database, but the caller is responsible to commit that transaction in order to finalize the settlement or initialization operation results.
func New ¶
New creates a new Settler instance, wrapping the given `tx` database transaction. The settler object expects the database schema to exist and only tries to create relevant tables in that schema.
func (*Settler) InitDevSchema ¶
InitDevSchema creates major version 1 tables in caweb1 schema and fills them with the development suitable initial data.
func (*Settler) InitProdSchema ¶
InitProdSchema creates major version 1 tables in caweb1 schema and fills them with the production suitable initial data.
func (*Settler) MajorVersion ¶
MajorVersion returns the major semantic version of this Settler instance. This value matches with the Major constant which is defined in this package. Indeed, this method can be called with a nil instance too because it only depends on the Settler type (not its instance).
func (*Settler) PersistSettings ¶ added in v1.2.0
func (sm1 *Settler) PersistSettings( ctx context.Context, mutableSettings, minb, maxb []byte, ) error
PersistSettings persists the given mutableSettings byte slice as the serialized form of the system mutable configuration settings, using the transaction which is hold by `sm1` object. This persistence will take effect whenever the caller could commit its transaction. The minb and maxb are also persisted as the minimum and maximum boundary values for all (mutable and immutable) settings, serialized with the same format which is used for mutableSettings.
func (*Settler) SettleSchema ¶
SettleSchema creates major version 1 tables in the caweb1 schema (representing the v1.x schema) and fills them with the contents of those database views which are prepared in the mig1 schema. The mig1 schema and caweb1 schema have views and tables with the same format, so no conversion will happen. Ideally, this is the only operation which copies all user data from the source database and converts them by passing through the fdwN, migN, ..., migM, to this mig1 and then persists them in tables of caweb1 schema.