genesis-0.0.1.0: Opinionated bootstrapping for Haskell web services.

Safe HaskellNone
LanguageHaskell2010

Genesis.Persist.Migrate

Description

This module provides functions for creating and running migrations written as plain SQL files. By using runMigrations, the migrations will be compiled directly into your Haskell application using Template Haskell, so the files will not need to be present in the eventual runtime environment.

For more information, see the documentation for runMigrations.

Synopsis

Documentation

runMigrations :: FilePath -> Q Exp Source #

Compiles a set of .sql files in a particular directory into your application, then runs them against a database at runtime. This function is implemented with Template Haskell so that it can read the migration files at compile-time, but it semantically has the type (MonadLogger m, MonadSqlPersist m) => FilePath -> m (). Migrations will be executed in order based on their filename, according to sort.

The FilePath provided should be relative to your project root, and it will detect all files within the immediate directory (that is, not in subdirectories) with the suffix .sql.

Example:

 main :: IO ()
 main = runStderrLoggingT $ withSqliteConn ":memory:" (runSqlPersistT $(runMigrations "db/migrations"))
 

runMigrations' :: (MonadLogger m, MonadSqlPersist m) => [(FilePath, Text)] -> m () Source #

The low-level API that underlies runMigrations. It is unlikely that you will need to use this.

Unlike runMigrations, this function does not use Template Haskell. Migrations are passed as a list of tuples, where the first element is the name of the migration (which must be unique) and the second element is the SQL to be run. The migrations will be run in the order they are provided, from left to right.