Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Relocant.DB
Description
This module manages PostgreSQL connections and relocant's DB schema.
Synopsis
- data ConnectionString
- data Table
- defaultTable :: Table
- connect :: ConnectionString -> Table -> IO Connection
- init :: Table -> Connection -> IO ()
- withLock :: Table -> Connection -> IO a -> IO a
- withTryLock :: Table -> Connection -> (Bool -> IO a) -> IO a
- lock :: Table -> Connection -> IO ()
- tryLock :: Table -> Connection -> IO Bool
- unlock :: Table -> Connection -> IO Bool
- dumpSchema :: Table -> IO ()
Documentation
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 # |
relocant's migration table name.
defaultTable :: Table Source #
The default table name, which is "public.relocant_migration".
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 #
lock :: Table -> Connection -> IO () Source #
Use pg_advisory_lock to lock the database, restricting 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.
dumpSchema :: Table -> IO () Source #