Documentation ¶
Overview ¶
Package schema offers utilities to create and maintain a database schema.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema captures the schema of a database in terms of a series of ordered updates.
func NewFromMap ¶
NewFromMap creates a new schema Schema with the updates specified in the given map. The keys of the map are schema versions that when upgraded will trigger the associated Update value. It's required that the minimum key in the map is 1, and if key N is present then N-1 is present too, with N>1 (i.e. there are no missing versions).
NOTE: the regular New() constructor would be formally enough, but for extra
clarity we also support a map that indicates the version explicitely, see also PR #3704.
func (*Schema) Add ¶
Add a new update to the schema. It will be appended at the end of the existing series.
func (*Schema) Dump ¶
Dump returns a text of SQL commands that can be used to create this schema from scratch in one go, without going thorugh individual patches (essentially flattening them).
It requires that all patches in this schema have been applied, otherwise an error will be returned.
func (*Schema) Ensure ¶
Ensure makes sure that the actual schema in the given database matches the one defined by our updates.
All updates are applied transactionally. In case any error occurs the transaction will be rolled back and the database will remain unchanged.
A update will be applied only if it hasn't been before (currently applied updates are tracked in the a 'shema' table, which gets automatically created).
func (*Schema) Hook ¶
Hook instructs the schema to invoke the given function whenever a update is about to be applied. The function gets passed the update version number and the running transaction, and if it returns an error it will cause the schema transaction to be rolled back. Any previously installed hook will be replaced.