migration

package
v0.0.0-...-22030c0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2020 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package migration provides facilities for mutating database schema in a controlled manner.

Index

Constants

This section is empty.

Variables

View Source
var BaseMigrations = []*Migration{
	&Migration{
		Version: 1,
		Queries: []*db.QueryPair{
			&db.QueryPair{
				Query: `CREATE TABLE IF NOT EXISTS killmail (
							id INTEGER PRIMARY KEY,

							esi_hash        TEXT     NOT NULL,
							solar_system_id INTEGER  NOT NULL,
							ship_type_id    INTEGER,

							killmail_time           INTEGER  NOT NULL,
							killmail_time_agg_day   INTEGER  NOT NULL,
							killmail_time_agg_week  INTEGER  NOT NULL,
							killmail_time_agg_month INTEGER  NOT NULL,

							character_id   INTEGER,
							corporation_id INTEGER,
							alliance_id    INTEGER,
							damage_taken   INTEGER,

							position_x REAL,
							position_y REAL,
							position_z REAL,

							is_awox      INTEGER,
							is_npc       INTEGER,
							is_solo      INTEGER,
							location_id  INTEGER,
							zkb_points   INTEGER,
							value_fitted REAL,
							value_total  REAL
					);`,
			},
			&db.QueryPair{
				Query: `CREATE TABLE IF NOT EXISTS attacker (
							id INTEGER PRIMARY KEY AUTOINCREMENT,

							killmail_id    INTEGER NOT NULL
								REFERENCES killmail(id)
									ON UPDATE CASCADE
									ON DELETE CASCADE,

							character_id   INTEGER,
							corporation_id INTEGER,
							alliance_id    INTEGER,

							damage_done     INTEGER,
							final_blow      INTEGER,
							security_status REAL,
							ship_type_id    INTEGER,
							weapon_type_id  INTEGER
						);`,
			},
			&db.QueryPair{
				Query: `CREATE TABLE IF NOT EXISTS item (
							id INTEGER PRIMARY KEY AUTOINCREMENT,

							killmail_id    INTEGER NOT NULL
								REFERENCES killmail(id)
									ON UPDATE CASCADE
									ON DELETE CASCADE,

							item_type_id       INTEGER,
							flag               INTEGER,
							quantity_destroyed INTEGER,
							singleton          INTEGER
						);`,
			},
		},
	},
}

BaseMigrations is the set of migrations that create the core schema that powers the base product.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager provides methods for querying the current database schema state and applying needed upgrades.

func NewManager

func NewManager(db *sql.DB, options ...Option) (*Manager, error)

NewManager returns a new Manager for the given db. A nil db returns an error.

func (*Manager) Apply

func (m *Manager) Apply(ctx context.Context, migrations []*Migration) error

Apply applies any unapplied migrations the given list in an exclusive transaction. The migrations must be sorted ascending by version.

type Migration

type Migration struct {
	Version int

	Queries []*db.QueryPair
}

A Migration is a collection of queries that will alter the database from one known schema to another.

type Option

type Option func(*Manager) error

An Option mutates potentially unexported fields of the manager in a defined way. Options are provided as an optional slice to NewManager.

func WithLogger

func WithLogger(logger *logging.Logger) Option

WithLogger applies the given logger to the new Manager instance. A nil logger value returns an error.

Jump to

Keyboard shortcuts

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