Documentation
¶
Overview ¶
Package migration renumbers a branch's own schema migrations. The pipeline's guard and bedrock check refuse a migrations directory that is not one sequence the migrate command applies in order: six-digit indexes, one up file each, contiguous, and in a pull-request build read together with the default branch's, so an index the default branch took since the branch was cut is refused. A branch opens two holes in that sequence, an index taken twice and a gap, and this closes both: the files the branch added move, up and down together, to follow the default branch's highest index with no gap, keeping their order. A committed schema migration is never touched once the repository has a release tag: a migration that ran somewhere is never rewritten. Before the first release nothing has run the migrations but disposable environments, so the whole schema sequence is packed from 000001 instead, committed files included. The seed directory's files are editable, so a committed seed file may be removed: the committed seed files after it move down to close the gap, and the branch's own follow them. It also folds the whole schema sequence into one file at the latest index (consolidate.go).
Index ¶
- Constants
- Variables
- func BlobSHA(content []byte) string
- func IsReleaseTag(name string) bool
- func Released(ctx context.Context, root string) (bool, error)
- func Sequence(entries []Entry) ([]Problem, Span)
- type ConsolidateOptions
- type Consolidation
- type Entry
- type Options
- type Problem
- type Rename
- type Result
- type Span
Constants ¶
const ConsolidatedName = "Consolidated"
ConsolidatedName is the fixed name of the folded file, after its index: the migrator reads the index alone, the pipeline reads the directory's shape, and the name tells the reader of the listing what the file is.
Variables ¶
var NameRE = regexp.MustCompile(`^(\d{6})_([A-Za-z0-9_-]+)\.(up|down)\.sql$`)
NameRE is a migration file name: a six-digit index, an underscore, a name, and .up.sql or .down.sql. The index is the first group, the name the second, the kind the third.
var ReleaseTagRE = regexp.MustCompile(`^v\d+\.\d+\.\d+($|-)`)
ReleaseTagRE is a release tag as release-please cuts them: v<major>.<minor>.<patch>, a prerelease suffix allowed.
Functions ¶
func BlobSHA ¶
BlobSHA is the name git gives a file with the content (git hash-object): what the GitHub API lists for a file at a commit, so a file in the tree is compared with the one committed without reading the committed content.
func IsReleaseTag ¶
IsReleaseTag says whether the tag name is a release's.
func Released ¶
Released says whether the repository holds a release tag: the freeze on committed schema migrations starts at the first release, and before it the whole sequence may be packed. The tags are the ones the checkout has, so fetch first.
Types ¶
type ConsolidateOptions ¶
type ConsolidateOptions struct {
// Root is the repository root; Dir the schema migrations directory, root-relative.
Root string
Dir string
// Branch is the default branch, whose committed sequence is folded; a branch cut from
// a patch line follows the line instead (followedBranch).
Branch string
}
ConsolidateOptions names the repository, the schema migrations directory and the branch.
type Consolidation ¶
type Consolidation struct {
// Ref is the ref the committed sequence was read from, at Commit (short).
Ref string
Commit string
Dir string
// Index is the latest index, which the folded file carries; Up and Down name the
// files written (Down is empty when no folded migration had a down file), and Folded
// the stems folded into them, in order. Nothing was done when Folded is empty.
Index int
Up string
Down string
Folded []string
// WithoutDown names the folded stems that had no down file: the down file reverses
// the others.
WithoutDown []string
}
Consolidation is what the fold read and did.
func Consolidate ¶
func Consolidate(ctx context.Context, opts ConsolidateOptions) (*Consolidation, error)
Consolidate folds the directory's sequence, as the followed branch holds it, into one up file and one down file at the latest index, removes the folded files and stages the change. It refuses a directory that is not as the followed branch holds it (a change under it in the working tree, or a migration of the branch's own): a consolidation is a pull request of its own, cut from the branch it folds. A sequence of one file is left alone.
type Entry ¶
Entry is one file of a migrations directory as the rule reads it: its name, and a note saying where it was found when that is not the tree being checked ("on master, not in this pull request").
type Options ¶
type Options struct {
// Root is the repository root; Dirs are the migration directories, root-relative:
// the schema migrations and the seed directory beside them.
Root string
Dirs []string
// Branch is the default branch, whose committed sequence the branch's own files
// follow; a working branch cut from a patch line follows the line instead, which
// Renumber finds (followedBranch). The followed branch's tree is read from origin's
// copy of it when the repository has one, else from the local branch.
Branch string
// Editable names the directories of Dirs whose committed files may move: the seed
// directory, whose files are editable, where the files after a removed one move
// down to close its gap. A committed file elsewhere is never touched.
Editable []string
}
Options names the repository, the directories and the branch.
type Problem ¶
Problem is one way the entries break the rule: the file it is about (its name and note; empty for the directory as a whole) and what is wrong, the way a person reads it.
type Rename ¶
Rename is one migration moved: its stem (NNNNNN_name) before and after, in Dir, and which of its files (up, down) moved with it.
type Result ¶
type Result struct {
// Ref is the ref the committed sequence was read from, at Commit (short).
Ref string
Commit string
Renames []Rename
// Notes name the files left alone, and why.
Notes []string
// Unreleased says the repository has no release tag, so the schema directories were
// packed from 000001, committed migrations included.
Unreleased bool
}
Result is what the renumber read and did.