Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Database.Migrant
Synopsis
- class Driver d where
- withTransaction :: (d -> IO a) -> d -> IO a
- initMigrations :: d -> IO ()
- markUp :: MigrationName -> d -> IO ()
- markDown :: MigrationName -> d -> IO ()
- getMigrations :: d -> IO [MigrationName]
- data MigrationName
- data MigrationDirection
- migrate :: Driver d => [MigrationName] -> (MigrationName -> d -> IO ()) -> (MigrationName -> d -> IO ()) -> d -> IO ()
- plan :: Driver d => [MigrationName] -> d -> IO [(MigrationDirection, MigrationName)]
Documentation
A migrations driver abstracts over the database to run over and the associated migration mechanism.
Methods
withTransaction :: (d -> IO a) -> d -> IO a Source #
initMigrations :: d -> IO () Source #
Initialize the migrations system on the backend. This should generally
involve creating a table of ordered migration names, e.g.:
@@
CREATE TABLE IF NOT EXISTS _migrations (id SERIAL PRIMARY KEY, name TEXT);
@@
- *Note** that
initMigrations
should be idempotent, that is, executing it when the migrations system has already been initialized should be a no-op.
markUp :: MigrationName -> d -> IO () Source #
Mark a migration as "executed". Typically, this will INSERT
a row
into the migrations table.
markDown :: MigrationName -> d -> IO () Source #
Mark a migration as "not executed" / "rolled back". Typically, this
will DELETE
a row from the migrations table.
getMigrations :: d -> IO [MigrationName] Source #
Get the list of migrations applied to the backend, in the order they were applied.
Instances
Driver DummyDriver Source # | |
Defined in Database.Migrant.Driver.Class Methods withTransaction :: (DummyDriver -> IO a) -> DummyDriver -> IO a Source # initMigrations :: DummyDriver -> IO () Source # markUp :: MigrationName -> DummyDriver -> IO () Source # markDown :: MigrationName -> DummyDriver -> IO () Source # getMigrations :: DummyDriver -> IO [MigrationName] Source # |
data MigrationName Source #
Instances
IsString MigrationName Source # | |
Defined in Database.Migrant.MigrationName Methods fromString :: String -> MigrationName # | |
Show MigrationName Source # | |
Defined in Database.Migrant.MigrationName Methods showsPrec :: Int -> MigrationName -> ShowS # show :: MigrationName -> String # showList :: [MigrationName] -> ShowS # | |
PrintfArg MigrationName Source # | |
Defined in Database.Migrant.MigrationName Methods | |
Eq MigrationName Source # | |
Defined in Database.Migrant.MigrationName Methods (==) :: MigrationName -> MigrationName -> Bool # (/=) :: MigrationName -> MigrationName -> Bool # |
data MigrationDirection Source #
Instances
Arguments
:: Driver d | |
=> [MigrationName] | Target situation |
-> (MigrationName -> d -> IO ()) | Factory for 'up' migration actions |
-> (MigrationName -> d -> IO ()) | Factory for 'down' migration actions |
-> d | |
-> IO () |
Safely (transactionally) infer and execute a migration.
plan :: Driver d => [MigrationName] -> d -> IO [(MigrationDirection, MigrationName)] Source #
Create a migration plan based on the current situation on the database, and the specified target.