edition

package
v0.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2022 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package edition provides internal structs for the schema package for defining and organizing database migration editions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dialect

type Dialect string

Dialect is a specific SQL language variant. This generally is the same as a specific SQL server implementation.

func (Dialect) String

func (d Dialect) String() string

type Edition

type Edition struct {
	// The identifier of an edition. The Name and Dialect pair should be unique.
	Name string
	// The specific SQL language variant that the Migrtions are for. The Name
	// and Dialect pair should be unique.
	Dialect Dialect

	// The latest version of the schema for this edition that this binary supports.
	LatestVersion int

	// The set of migrations that should be applied to a database to reach the latest version.
	// This is a map of schema versions to sql.
	Migrations map[int][]byte

	// Priority is used to determine the order that multiple Editions should be applied.
	Priority int
}

Edition is a collection of sql statements along with a version number. It is used to apply changes to the database instance.

func New

func New(name string, dialect Dialect, m embed.FS, priority int) Edition

New creates an Edition with the provided parameters. The embed.FS m will be walked to extract the sql statements. The priority is used to determine when this Edition's migrations are applied relative to other Editions. A lower number indicates a higher priority. New will panic if the structure of the embed.FS is not correct. The files must be structured as follows:

<majorVersion>/
    <minorVersion>_<description>.up.sql

Where majorVersion and minorVersion are integers. There can be any number of leading directories prior to the major versions. For example a directory structure like the following is correct:

migrations/oss/postgres/
 0/
   01_initial.up.sql
 1/
   01_add_columns.up.sql
   02_rename_table.up.sql
 2/
   01_add_new_table.up.sql
   02_refactor_views.up.sql

type Editions

type Editions []Edition

Editions is a collection of Edition

func (Editions) Sort

func (e Editions) Sort()

Sort orders the Editions by priority.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL