IHP Api Reference
Copyright(c) digitally induced GmbH 2020
Safe HaskellNone

IHP.SchemaMigration

Description

 
Synopsis

Documentation

data Migration Source #

Constructors

Migration 

Instances

Instances details
Show Migration Source # 
Instance details

Defined in IHP.SchemaMigration

Methods

showsPrec :: Int -> Migration -> ShowS #

show :: Migration -> String

showList :: [Migration] -> ShowS #

Eq Migration Source # 
Instance details

Defined in IHP.SchemaMigration

data MigrateOptions Source #

Constructors

MigrateOptions 

Fields

  • minimumRevision :: !(Maybe Int)

    When deploying a fresh install of an existing app that has existing migrations, it might be useful to ignore older migrations as they're already part of the existing schema

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" }