dbmigrations-2.1.0: An implementation of relational database "migrations"
Safe HaskellNone
LanguageHaskell2010

Database.Schema.Migrations.Store

Description

This module provides an abstraction for a migration store, a facility in which Migrations can be stored and from which they can be loaded. This module also provides functions for taking Migrations from a store and converting them into the appropriate intermediate types for use with the rest of this library.

Synopsis

Documentation

data MigrationStore Source #

The type of migration storage facilities. A MigrationStore is a facility in which new migrations can be created, and from which existing migrations can be loaded.

Constructors

MigrationStore 

Fields

data MapValidationError Source #

A type for types of validation errors for migration maps.

Constructors

DependencyReferenceError Text Text

A migration claims a dependency on a migration that does not exist.

DependencyGraphError String

An error was encountered when constructing the dependency graph for this store.

InvalidMigration String

The specified migration is invalid.

type MigrationMap = Map Text Migration Source #

A mapping from migration name to Migration. This is exported for testing purposes, but you'll want to interface with this through the encapsulating StoreData type.

High-level Store API

loadMigrations :: MigrationStore -> IO (Either [MapValidationError] StoreData) Source #

Load migrations from the specified MigrationStore, validate the loaded migrations, and return errors or a MigrationMap on success. Generally speaking, this will be the first thing you should call once you have constructed a MigrationStore.

storeMigrations :: StoreData -> [Migration] Source #

A convenience function for extracting the list of Migrations extant in the specified StoreData.

storeLookup :: StoreData -> Text -> Maybe Migration Source #

A convenience function for looking up a Migration by name in the specified StoreData.

Miscellaneous Functions

depGraphFromMapping :: MigrationMap -> Either String (DependencyGraph Migration) Source #

Create a DependencyGraph from a MigrationMap; returns Left if the dependency graph cannot be constructed (e.g., due to a dependency cycle) or Right on success. Generally speaking, you won't want to use this directly; use loadMigrations instead.

validateMigrationMap :: MigrationMap -> [MapValidationError] Source #

Validate a migration map. Returns zero or more validation errors.

validateSingleMigration :: MigrationMap -> Migration -> [MapValidationError] Source #

Validate a single migration. Looks up the migration's dependencies in the specified MigrationMap and returns a MapValidationError for each one that does not exist in the map.

leafMigrations :: StoreData -> [Text] Source #

Finds migrations that no other migration depends on (effectively finds all vertices with in-degree equal to zero).