dbmigrations-0.1.1: An implementation of relational database "migrations"

Database.Schema.Migrations.Store

Contents

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

class Monad m => MigrationStore s m whereSource

A type class for types which represent a storage facility (and a monad context in which to operate on the store). A MigrationStore is a facility in which new migrations can be created, and from which existing migrations can be loaded.

Methods

loadMigration :: s -> String -> m (Maybe Migration)Source

Load a migration from the store.

saveMigration :: s -> Migration -> m ()Source

Save a migration to the store.

getMigrations :: s -> m [String]Source

Return a list of all available migrations' names.

fullMigrationName :: s -> String -> m StringSource

Return the full representation of a given migration name; mostly for filesystem stores, where the full representation includes the store path.

data MapValidationError Source

A type for types of validation errors for migration maps.

Constructors

DependencyReferenceError String String

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.

type MigrationMap = Map String MigrationSource

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 s m => s -> m (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 -> String -> Maybe MigrationSource

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.