relocant-1.0.0: A PostgreSQL migration CLI tool and library
Safe HaskellSafe-Inferred
LanguageHaskell2010

Relocant

Description

A PostgreSQL migration library

Synopsis

Documentation

data Script Source #

A migration script. Most users would get them by running readScripts, but those wanting a more fine-grained control would use readScript.

Constructors

Script 

Fields

Instances

Instances details
ToJSON Script Source #

The content (as in actual bytes) is skipped.

Instance details

Defined in Relocant.Script

Show Script Source # 
Instance details

Defined in Relocant.Script

Eq Script Source # 
Instance details

Defined in Relocant.Script

Methods

(==) :: Script -> Script -> Bool #

(/=) :: Script -> Script -> Bool #

HasField "bytes" Script ByteString Source # 
Instance details

Defined in Relocant.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.

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 #

A non-blocking version of withLock. True is passed to the callback if the lock was successfully acquired, False otherwise.

data Applied 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 

Fields

Instances

Instances details
ToJSON Applied Source #

The content (as in actual bytes) is skipped.

Instance details

Defined in Relocant.Applied

Show Applied Source # 
Instance details

Defined in Relocant.Applied

Eq Applied Source # 
Instance details

Defined in Relocant.Applied

Methods

(==) :: Applied -> Applied -> Bool #

(/=) :: Applied -> Applied -> Bool #

HasField "bytes" Applied ByteString Source # 
Instance details

Defined in Relocant.Applied

data ID Source #

Migration ID.

Instances

Instances details
ToJSON ID Source # 
Instance details

Defined in Relocant.ID

IsString ID Source # 
Instance details

Defined in Relocant.ID

Methods

fromString :: String -> ID #

Show ID Source # 
Instance details

Defined in Relocant.ID

Methods

showsPrec :: Int -> ID -> ShowS #

show :: ID -> String #

showList :: [ID] -> ShowS #

PrintfArg ID Source # 
Instance details

Defined in Relocant.ID

Eq ID Source # 
Instance details

Defined in Relocant.ID

Methods

(==) :: ID -> ID -> Bool #

(/=) :: ID -> ID -> Bool #

Ord ID Source # 
Instance details

Defined in Relocant.ID

Methods

compare :: ID -> ID -> Ordering #

(<) :: ID -> ID -> Bool #

(<=) :: ID -> ID -> Bool #

(>) :: ID -> ID -> Bool #

(>=) :: ID -> ID -> Bool #

max :: ID -> ID -> ID #

min :: ID -> ID -> ID #

FromField ID Source # 
Instance details

Defined in Relocant.ID

ToField ID Source # 
Instance details

Defined in Relocant.ID

Methods

toField :: ID -> Action #

data Name Source #

Migration Name.

Instances

Instances details
ToJSON Name Source # 
Instance details

Defined in Relocant.Name

IsString Name Source # 
Instance details

Defined in Relocant.Name

Methods

fromString :: String -> Name #

Show Name Source # 
Instance details

Defined in Relocant.Name

Methods

showsPrec :: Int -> Name -> ShowS #

show :: Name -> String #

showList :: [Name] -> ShowS #

PrintfArg Name Source # 
Instance details

Defined in Relocant.Name

Eq Name Source # 
Instance details

Defined in Relocant.Name

Methods

(==) :: Name -> Name -> Bool #

(/=) :: Name -> Name -> Bool #

FromField Name Source # 
Instance details

Defined in Relocant.Name

ToField Name Source # 
Instance details

Defined in Relocant.Name

Methods

toField :: Name -> Action #

data Content Source #

Migration content and its checksum.

Instances

Instances details
IsString Content Source # 
Instance details

Defined in Relocant.Content

Methods

fromString :: String -> Content #

Show Content Source # 
Instance details

Defined in Relocant.Content

Eq Content Source # 
Instance details

Defined in Relocant.Content

Methods

(==) :: Content -> Content -> Bool #

(/=) :: Content -> Content -> Bool #

data Duration Source #

How long something took, in seconds. Use mempty for a 0 seconds Duration.

Instances

Instances details
ToJSON Duration Source # 
Instance details

Defined in Relocant.Duration

Monoid Duration Source # 
Instance details

Defined in Relocant.Duration

Semigroup Duration Source # 
Instance details

Defined in Relocant.Duration

Show Duration Source # 
Instance details

Defined in Relocant.Duration

PrintfArg Duration Source # 
Instance details

Defined in Relocant.Duration

Eq Duration Source # 
Instance details

Defined in Relocant.Duration

FromField Duration Source # 
Instance details

Defined in Relocant.Duration

ToField Duration Source # 
Instance details

Defined in Relocant.Duration

Methods

toField :: Duration -> Action #

data Table Source #

relocant's migration table name.

Instances

Instances details
ToJSON Table Source # 
Instance details

Defined in Relocant.DB.Table

IsString Table Source # 
Instance details

Defined in Relocant.DB.Table

Methods

fromString :: String -> Table #

Show Table Source #

Return a String that can be fromStringed back to a Table.

Instance details

Defined in Relocant.DB.Table

Methods

showsPrec :: Int -> Table -> ShowS #

show :: Table -> String #

showList :: [Table] -> ShowS #

Eq Table Source # 
Instance details

Defined in Relocant.DB.Table

Methods

(==) :: Table -> Table -> Bool #

(/=) :: Table -> Table -> Bool #

ToField Table Source # 
Instance details

Defined in Relocant.DB.Table

Methods

toField :: Table -> Action #

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.

data Merged Source #

The result of merging Scripts and Applied migrations.

Constructors

Merged 

Fields

  • unrecorded :: [Script]

    A script that does not have a corresponding recorded migration, when there is a recorded migration with a higher ID

  • scriptMissing :: [Applied]

    A recorded migration that does not have a corresponding script

  • contentMismatch :: [ContentMismatch]

    A recorded migration and a script have the same ID but different content

  • unapplied :: [Script]

    An unapplied script that has a higher ID than any recorded migration

Instances

Instances details
ToJSON Merged Source # 
Instance details

Defined in Relocant.Merge

Show Merged Source # 
Instance details

Defined in Relocant.Merge

Eq Merged Source # 
Instance details

Defined in Relocant.Merge

Methods

(==) :: Merged -> Merged -> Bool #

(/=) :: Merged -> Merged -> Bool #

data ContentMismatch Source #

The applied migration and its purported script differ in content.

Constructors

ContentMismatch 

Fields

canApply :: Merged -> Bool Source #

No problems have been discovered after the merge.

converged :: Merged -> Bool Source #

No problems have been discovered after the merge, and there are no migration scripts to apply.

apply :: Script -> Connection -> IO Applied Source #

Run a Script against the database, get an Applied migration back if successful.

Note: You probably want to run this together with record in a single transaction.

record :: Applied -> Table -> Connection -> IO () Source #

Record a successfully Applied migration.

Note: You probably want to run this together with apply in a single transaction.

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

Instances details
Eq Connection 
Instance details

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.