Copyright | (c) digitally induced GmbH 2020 |
---|---|
Safe Haskell | None |
Synopsis
- data Migration = Migration {
- revision :: Int
- migrationFile :: Text
- data MigrateOptions = MigrateOptions {
- minimumRevision :: !(Maybe Int)
- migrate :: (?modelContext :: ModelContext) => MigrateOptions -> IO ()
- runMigration :: (?modelContext :: ModelContext) => Migration -> IO ()
- createSchemaMigrationsTable :: (?modelContext :: ModelContext) => IO ()
- findOpenMigrations :: (?modelContext :: ModelContext) => Int -> IO [Migration]
- findMigratedRevisions :: (?modelContext :: ModelContext) => IO [Int]
- findAllMigrations :: IO [Migration]
- pathToMigration :: Text -> Maybe Migration
- migrationPath :: Migration -> Text
Documentation
Migration | |
|
Instances
data MigrateOptions Source #
MigrateOptions | |
|
migrate :: (?modelContext :: ModelContext) => MigrateOptions -> IO () Source #
Migrates the database schema to the latest version
runMigration :: (?modelContext :: ModelContext) => Migration -> IO () Source #
The sql statements contained in the migration file are executed. Then the revision is inserted into the schema_migrations
table.
All queries are executed inside a database transaction to make sure that it can be restored when something goes wrong.
createSchemaMigrationsTable :: (?modelContext :: ModelContext) => IO () Source #
Creates the schema_migrations
table if it doesn't exist yet
findOpenMigrations :: (?modelContext :: ModelContext) => Int -> IO [Migration] Source #
Returns all migrations that haven't been executed yet. The result is sorted so that the oldest revision is first.
findMigratedRevisions :: (?modelContext :: ModelContext) => IO [Int] Source #
Returns all migration revisions applied to the database schema
>>>
findMigratedRevisions
[ 1604850570, 1604850660 ]
findAllMigrations :: IO [Migration] Source #
Returns all migrations found in Application/Migration
>>>
findAllMigrations
[ Migration { revision = 1604850570, migrationFile = "Application/Migration/1604850570-create-projects.sql" } ]
The result is sorted so that the oldest revision is first.
pathToMigration :: Text -> Maybe Migration Source #
Given a path such as ApplicationMigrate00-initial-migration.sql it returns a Migration
Returns Nothing if the path is not following the usual migration file path convention.
>>>
pathToMigration "Application/Migration/1604850570-create-projects.sql"
Migration { revision = 1604850570, migrationFile = "Application/Migration/1604850570-create-projects.sql" }
migrationPath :: Migration -> Text Source #