| Safe Haskell | Safe-Inferred | 
|---|---|
| Language | Haskell2010 | 
Relocant
Contents
Description
A PostgreSQL migration library
Synopsis
- data Script = Script {}
 - readScripts :: FilePath -> IO [Script]
 - readScript :: FilePath -> IO Script
 - data ConnectionString
 - connect :: ConnectionString -> Table -> IO Connection
 - withLock :: Table -> Connection -> IO a -> IO a
 - withTryLock :: Table -> Connection -> (Bool -> IO a) -> IO a
 - data Applied = Applied {}
 - data ID
 - data Name
 - data Content
 - data Duration
 - data Table
 - defaultTable :: Table
 - getApplied :: Table -> Connection -> IO [Applied]
 - getAppliedByID :: ID -> Table -> Connection -> IO (Maybe Applied)
 - merge :: [Applied] -> [Script] -> Merged
 - mergeAll :: FilePath -> Table -> Connection -> IO Merged
 - data Merged = Merged {
- unrecorded :: [Script]
 - scriptMissing :: [Applied]
 - contentMismatch :: [ContentMismatch]
 - unapplied :: [Script]
 
 - data ContentMismatch = ContentMismatch {}
 - canApply :: Merged -> Bool
 - converged :: Merged -> Bool
 - apply :: Script -> Connection -> IO Applied
 - record :: Applied -> Table -> Connection -> IO ()
 - applyAll :: Merged -> Table -> Connection -> IO ()
 - data Connection
 - withTransaction :: Connection -> IO a -> IO a
 
Documentation
A migration script. Most users would get them by running readScripts,
 but those wanting a more fine-grained control would use readScript.
Constructors
| Script | |
readScripts :: FilePath -> IO [Script] Source #
Read migration Scripts from a directory. It only tries to read paths
 ending with the .sql extension and doesn't recurse into subdirectories.
Note: the directory must exist
readScript :: FilePath -> IO Script Source #
Read migration Scripts from a file. Useful when you need a more fine-grained
 control over which paths are read then what readScripts provides.
data ConnectionString Source #
PostgreSQL connection string. (This is a newtype over ByteString)
for syntax, see: https://hackage.haskell.org/package/postgresql-simple/docs/Database-PostgreSQL-Simple.html#v:connectPostgreSQL
Instances
| ToJSON ConnectionString Source # | |
Defined in Relocant.DB Methods toJSON :: ConnectionString -> Value # toEncoding :: ConnectionString -> Encoding # toJSONList :: [ConnectionString] -> Value # toEncodingList :: [ConnectionString] -> Encoding #  | |
| IsString ConnectionString Source # | |
Defined in Relocant.DB Methods fromString :: String -> ConnectionString #  | |
| Show ConnectionString Source # | |
Defined in Relocant.DB Methods showsPrec :: Int -> ConnectionString -> ShowS # show :: ConnectionString -> String # showList :: [ConnectionString] -> ShowS #  | |
| Eq ConnectionString Source # | |
Defined in Relocant.DB Methods (==) :: ConnectionString -> ConnectionString -> Bool # (/=) :: ConnectionString -> ConnectionString -> Bool #  | |
connect :: ConnectionString -> Table -> IO Connection Source #
Connect to the DB using the given ConnectionString and
 initialize the migrations table.
Note: If you get your Connection from elsewhere,
 remember to call init yourself.
withLock :: Table -> Connection -> IO a -> IO a Source #
Use pg_advisory_{lock,unlock} to restrict access to the migrations table. The given table is used to generate the lock's ID, so that in the unlikely case where you have multiple migrations tables in your database you can lock them separately.
withTryLock :: Table -> Connection -> (Bool -> IO a) -> IO a Source #
An applied migration. Generally, it's created be either running a
 migration Script with apply or getting the records
 from the DB with getApplied or getAppliedByID.
Constructors
| Applied | |
Migration ID.
Instances
| ToJSON ID Source # | |
Defined in Relocant.ID  | |
| IsString ID Source # | |
Defined in Relocant.ID Methods fromString :: String -> ID #  | |
| Show ID Source # | |
| PrintfArg ID Source # | |
Defined in Relocant.ID  | |
| Eq ID Source # | |
| Ord ID Source # | |
| FromField ID Source # | |
Defined in Relocant.ID Methods fromField :: FieldParser ID #  | |
| ToField ID Source # | |
Defined in Relocant.ID  | |
Migration Name.
Instances
| ToJSON Name Source # | |
Defined in Relocant.Name  | |
| IsString Name Source # | |
Defined in Relocant.Name Methods fromString :: String -> Name #  | |
| Show Name Source # | |
| PrintfArg Name Source # | |
Defined in Relocant.Name  | |
| Eq Name Source # | |
| FromField Name Source # | |
Defined in Relocant.Name Methods  | |
| ToField Name Source # | |
Defined in Relocant.Name  | |
Migration content and its checksum.
Instances
| ToJSON Duration Source # | |
Defined in Relocant.Duration  | |
| Monoid Duration Source # | |
| Semigroup Duration Source # | |
| Show Duration Source # | |
| PrintfArg Duration Source # | |
Defined in Relocant.Duration  | |
| Eq Duration Source # | |
| FromField Duration Source # | |
Defined in Relocant.Duration Methods  | |
| ToField Duration Source # | |
Defined in Relocant.Duration  | |
relocant's migration table name.
defaultTable :: Table Source #
The default table name, which is "public.relocant_migration".
getApplied :: Table -> Connection -> IO [Applied] Source #
Retrieve all Applied migrations' records from the DB.
getAppliedByID :: ID -> Table -> Connection -> IO (Maybe Applied) Source #
Retrieve the specific Applied migration's record from the DB.
merge :: [Applied] -> [Script] -> Merged Source #
Merge scripts and applied migrations, trying to discover inconsistencies and/or migration scripts to apply.
mergeAll :: FilePath -> Table -> Connection -> IO Merged Source #
A convenience function that gets all applied migrations' records from the DB and merges them together with the migration scripts from a given directory.
Constructors
| Merged | |
Fields 
  | |
data ContentMismatch Source #
The applied migration and its purported script differ in content.
Constructors
| ContentMismatch | |
Instances
| ToJSON ContentMismatch Source # | |
Defined in Relocant.Merge Methods toJSON :: ContentMismatch -> Value # toEncoding :: ContentMismatch -> Encoding # toJSONList :: [ContentMismatch] -> Value # toEncodingList :: [ContentMismatch] -> Encoding #  | |
| Show ContentMismatch Source # | |
Defined in Relocant.Merge Methods showsPrec :: Int -> ContentMismatch -> ShowS # show :: ContentMismatch -> String # showList :: [ContentMismatch] -> ShowS #  | |
| Eq ContentMismatch Source # | |
Defined in Relocant.Merge Methods (==) :: ContentMismatch -> ContentMismatch -> Bool # (/=) :: ContentMismatch -> ContentMismatch -> Bool #  | |
converged :: Merged -> Bool Source #
No problems have been discovered after the merge, and there are no migration scripts to apply.
applyAll :: Merged -> Table -> Connection -> IO () Source #
A convenience function that applies all unapplied migrations' scripts and records their application in the DB. Each script is run in a separate transaction.
Re-exports (postgresql-simple)
data Connection #
Instances
| Eq Connection | |
Defined in Database.PostgreSQL.Simple.Internal  | |
withTransaction :: Connection -> IO a -> IO a #
Execute an action inside a SQL transaction.
This function initiates a transaction with a "begin
 transaction" statement, then executes the supplied action.  If
 the action succeeds, the transaction will be completed with
 commit before this function returns.
If the action throws any kind of exception (not just a
 PostgreSQL-related exception), the transaction will be rolled back using
 rollback, then the exception will be rethrown.
For nesting transactions, see withSavepoint.