Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
.
- runMigrations :: FilePath -> Q Exp
- runMigrations' :: (MonadLogger m, MonadSqlPersist m) => [(FilePath, Text)] -> m ()
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
(
. Migrations
will be executed in order based on their filename, according to MonadLogger
m, MonadSqlPersist
m) => FilePath
-> m ()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.