Copyright(c) digitally induced GmbH 2020
Safe HaskellNone

IHP.SchemaMigration

Description

 
Synopsis

Documentation

data Migration Source #

Constructors

Migration 

Instances

Instances details
Eq Migration Source # 
Instance details

Defined in IHP.SchemaMigration

Show Migration Source # 
Instance details

Defined in IHP.SchemaMigration

Methods

showsPrec :: Int -> Migration -> ShowS #

show :: Migration -> String

showList :: [Migration] -> ShowS #

migrate :: (?modelContext :: ModelContext) => 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.

withTransaction :: (?modelContext :: ModelContext) => IO a -> IO a Source #

createSchemaMigrationsTable :: (?modelContext :: ModelContext) => IO () Source #

Creates the schema_migrations table if it doesn't exist yet

findOpenMigrations :: (?modelContext :: ModelContext) => 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" }

createMigration :: Text -> IO Migration Source #

Generates a new migration .sql file in Application/Migration