peregrin-0.1.0: Database migration support for use in other libraries.

Safe HaskellNone
LanguageHaskell2010

Database.Peregrin

Synopsis

Documentation

migrate :: Connection -> Schema -> [(Text, Text)] -> IO () Source #

Apply a list of migrations to a database. For example,

migrate conn schema [("a", "CREATE TABLE ...")]
                    [("b", "INSERT INTO TABLE ...")]

will apply the given SQL statements in order and track them by the identifiers "a" and "b". It is recommended to use fixed, randomly generated UUIDs to identify migrations, though you are free to use whatever identifiers you like as long as they are unique within the given schema. For example, on a Linux system you can run the command `uuidgen -r` on the command line and paste that into your migration list.

The given Schema parameter indicates the schema used for the metadata stored to track which migrations have been applied. It does not affect the migrations themselves in any way. Therefore, ALL migrations should ALWAYS specify their schema explicitly in the SQL.

Any migrations that have already been applied will be skipped. If the SQL text for any given migration changes, a MigrationModifiedError exception will be thrown.

Migrations are tracked using two tables, namely "__peregrin_migration_meta__" and "__peregrin_migration__", which will automatically be created in the given Schema.

data MigrationError Source #

Exception happened running migrations.

Constructors

MigrationModifiedError Text

The migration with the given ID has been modified in the program code since it was applied. Since this can have very unpredictable effects it is considered an error.