{-|
Module: Squeal.PostgreSQL.Session.Migration
Description: migrations
Copyright: (c) Eitan Chatav, 2019
Maintainer: eitan@morphism.tech
Stability: experimental

This module defines a `Migration` type to safely
change the schema of your database over time. Let's see an example!

First turn on some extensions.

>>> :set -XDataKinds -XOverloadedLabels
>>> :set -XOverloadedStrings -XFlexibleContexts -XTypeOperators

Next, let's define our `TableType`s.

>>> :{
type UsersTable =
  '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=>
  '[ "id" ::: 'Def :=> 'NotNull 'PGint4
   , "name" ::: 'NoDef :=> 'NotNull 'PGtext
   ]
:}

>>> :{
type EmailsTable =
  '[ "pk_emails" ::: 'PrimaryKey '["id"]
   , "fk_user_id" ::: 'ForeignKey '["user_id"] "public" "users" '["id"]
   ] :=>
  '[ "id" ::: 'Def :=> 'NotNull 'PGint4
   , "user_id" ::: 'NoDef :=> 'NotNull 'PGint4
   , "email" ::: 'NoDef :=> 'Null 'PGtext
   ]
:}

Now we can define some `Migration`s to make our tables.

`Migration`s are parameterized giving the option of a

* pure one-way `Migration` `Definition`
* impure one-way `Migration` @(@`Indexed` `PQ` `IO`@)@
* pure reversible `Migration` @(@`IsoQ` `Definition`@)@
* impure reversible `Migration` @(@`IsoQ` @(@`Indexed` `PQ` `IO`@)@@)@

For this example, we'll use pure reversible `Migration`s.

>>> :{
let
  makeUsers :: Migration (IsoQ Definition)
    '["public" ::: '[]]
    '["public" ::: '["users" ::: 'Table UsersTable]]
  makeUsers = Migration "make users table" IsoQ
    { up = createTable #users
        ( serial `as` #id :*
          notNullable text `as` #name )
        ( primaryKey #id `as` #pk_users )
    , down = dropTable #users
    }
:}

>>> :{
let
  makeEmails :: Migration (IsoQ Definition)
    '["public" ::: '["users" ::: 'Table UsersTable]]
    '["public" ::: '["users" ::: 'Table UsersTable, "emails" ::: 'Table EmailsTable]]
  makeEmails = Migration "make emails table" IsoQ
    { up = createTable #emails
          ( serial `as` #id :*
            notNullable int `as` #user_id :*
            nullable text `as` #email )
          ( primaryKey #id `as` #pk_emails :*
            foreignKey #user_id #users #id
              (OnDelete Cascade) (OnUpdate Cascade) `as` #fk_user_id )
    , down = dropTable #emails
    }
:}

Now that we have a couple migrations we can chain them together into a `Path`.

>>> let migrations = makeUsers :>> makeEmails :>> Done

Now run the migrations.

>>> import Control.Monad.IO.Class
>>> :{
withConnection "host=localhost port=5432 dbname=exampledb user=postgres password=postgres" $
  manipulate_ (UnsafeManipulation "SET client_min_messages TO WARNING;")
    -- suppress notices
  & pqThen (liftIO (putStrLn "Migrate"))
  & pqThen (migrateUp migrations)
  & pqThen (liftIO (putStrLn "Rollback"))
  & pqThen (migrateDown migrations)
:}
Migrate
Rollback

We can also create a simple executable using `mainMigrateIso`.

>>> let main = mainMigrateIso "host=localhost port=5432 dbname=exampledb user=postgres password=postgres" migrations

>>> withArgs [] main
Invalid command: "". Use:
migrate    to run all available migrations
rollback   to rollback all available migrations
status     to display migrations run and migrations left to run

>>> withArgs ["status"] main
Migrations already run:
  None
Migrations left to run:
  - make users table
  - make emails table

>>> withArgs ["migrate"] main
Migrations already run:
  - make users table
  - make emails table
Migrations left to run:
  None

>>> withArgs ["rollback"] main
Migrations already run:
  None
Migrations left to run:
  - make users table
  - make emails table

In addition to enabling `Migration`s using pure SQL `Definition`s for
the `up` and `down` migrations, you can also perform impure `IO` actions
by using a `Migration`s over the `Indexed` `PQ` `IO` category.
-}

{-# LANGUAGE
    DataKinds
  , DeriveGeneric
  , FlexibleContexts
  , FlexibleInstances
  , FunctionalDependencies
  , GADTs
  , LambdaCase
  , MultiParamTypeClasses
  , OverloadedLabels
  , OverloadedStrings
  , PolyKinds
  , QuantifiedConstraints
  , RankNTypes
  , TypeApplications
  , TypeOperators
#-}

module Squeal.PostgreSQL.Session.Migration
  ( -- * Migration
    Migration (..)
  , Migratory (..)
  , migrate
  , migrateUp
  , migrateDown
  , MigrationsTable
    -- * Executable
  , mainMigrate
  , mainMigrateIso
    -- * Re-export
  , IsoQ (..)
  ) where

import Control.Category
import Control.Category.Free
import Control.Monad
import Control.Monad.IO.Class
import Data.ByteString (ByteString)
import Data.Foldable (traverse_)
import Data.Function ((&))
import Data.List ((\\))
import Data.Quiver
import Data.Quiver.Functor
import Data.Text (Text)
import Data.Time (UTCTime)
import Prelude hiding ((.), id)
import System.Environment

import qualified Data.Text.IO as Text (putStrLn)
import qualified Generics.SOP as SOP
import qualified GHC.Generics as GHC

import Squeal.PostgreSQL.Definition
import Squeal.PostgreSQL.Definition.Constraint
import Squeal.PostgreSQL.Definition.Table
import Squeal.PostgreSQL.Expression.Comparison
import Squeal.PostgreSQL.Expression.Default
import Squeal.PostgreSQL.Expression.Parameter
import Squeal.PostgreSQL.Expression.Time
import Squeal.PostgreSQL.Expression.Type
import Squeal.PostgreSQL.Manipulation
import Squeal.PostgreSQL.Manipulation.Delete
import Squeal.PostgreSQL.Manipulation.Insert
import Squeal.PostgreSQL.Session
import Squeal.PostgreSQL.Session.Decode
import Squeal.PostgreSQL.Session.Encode
import Squeal.PostgreSQL.Session.Indexed
import Squeal.PostgreSQL.Session.Monad
import Squeal.PostgreSQL.Session.Result
import Squeal.PostgreSQL.Session.Statement
import Squeal.PostgreSQL.Session.Transaction.Unsafe
import Squeal.PostgreSQL.Query.From
import Squeal.PostgreSQL.Query.Select
import Squeal.PostgreSQL.Query.Table
import Squeal.PostgreSQL.Type.Alias
import Squeal.PostgreSQL.Type.List
import Squeal.PostgreSQL.Type.Schema

-- | A `Migration` consists of a name and a migration definition.
data Migration def db0 db1 = Migration
  { Migration def db0 db1 -> Text
migrationName :: Text -- ^ The name of a `Migration`.
    -- Each `migrationName` should be unique.
  , Migration def db0 db1 -> def db0 db1
migrationDef :: def db0 db1 -- ^ The migration of a `Migration`.
  } deriving ((forall x. Migration def db0 db1 -> Rep (Migration def db0 db1) x)
-> (forall x.
    Rep (Migration def db0 db1) x -> Migration def db0 db1)
-> Generic (Migration def db0 db1)
forall x. Rep (Migration def db0 db1) x -> Migration def db0 db1
forall x. Migration def db0 db1 -> Rep (Migration def db0 db1) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall k k (def :: k -> k -> *) (db0 :: k) (db1 :: k) x.
Rep (Migration def db0 db1) x -> Migration def db0 db1
forall k k (def :: k -> k -> *) (db0 :: k) (db1 :: k) x.
Migration def db0 db1 -> Rep (Migration def db0 db1) x
$cto :: forall k k (def :: k -> k -> *) (db0 :: k) (db1 :: k) x.
Rep (Migration def db0 db1) x -> Migration def db0 db1
$cfrom :: forall k k (def :: k -> k -> *) (db0 :: k) (db1 :: k) x.
Migration def db0 db1 -> Rep (Migration def db0 db1) x
GHC.Generic)
instance QFunctor Migration where
  qmap :: (forall (x1 :: k2) (y1 :: k3). p x1 y1 -> q x1 y1)
-> Migration p x y -> Migration q x y
qmap forall (x1 :: k2) (y1 :: k3). p x1 y1 -> q x1 y1
f (Migration Text
n p x y
i) = Text -> q x y -> Migration q x y
forall k k (def :: k -> k -> *) (db0 :: k) (db1 :: k).
Text -> def db0 db1 -> Migration def db0 db1
Migration Text
n (p x y -> q x y
forall (x1 :: k2) (y1 :: k3). p x1 y1 -> q x1 y1
f p x y
i)

{- |
A `Migratory` `Category` can run or
possibly rewind a `Path` of `Migration`s.
-}
class (Category def, Category run) => Migratory def run | def -> run where
  {- | Run a `Path` of `Migration`s.-}
  runMigrations :: Path (Migration def) db0 db1 -> run db0 db1
-- | impure migrations
instance Migratory (Indexed PQ IO ()) (Indexed PQ IO ()) where
  runMigrations :: Path (Migration (Indexed PQ IO ())) db0 db1
-> Indexed PQ IO () db0 db1
runMigrations Path (Migration (Indexed PQ IO ())) db0 db1
path = PQ db0 db1 IO () -> Indexed PQ IO () db0 db1
forall k k k k (t :: k -> k -> k -> k -> *) (m :: k) (r :: k)
       (i :: k) (j :: k).
t i j m r -> Indexed t m r i j
Indexed (PQ db0 db1 IO () -> Indexed PQ IO () db0 db1)
-> (PQ
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      IO
      ()
    -> PQ db0 db1 IO ())
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     IO
     ()
-> Indexed PQ IO () db0 db1
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. PQ
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  IO
  ()
-> PQ db0 db1 IO ()
forall (m :: * -> *) (db0 :: SchemasType) (db1 :: SchemasType) x
       (db0' :: SchemasType) (db1' :: SchemasType).
Functor m =>
PQ db0 db1 m x -> PQ db0' db1' m x
unsafePQ (PQ
   '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
   '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
   IO
   ()
 -> PQ db0 db1 IO ())
-> (PQ
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      IO
      ()
    -> PQ
         '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
         '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
         IO
         ())
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     IO
     ()
-> PQ db0 db1 IO ()
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. PQ
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  IO
  ()
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     IO
     ()
forall (tx :: * -> *) (db :: SchemasType) x.
(MonadMask tx, MonadPQ db tx) =>
tx x -> tx x
transactionally_ (PQ
   '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
   '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
   IO
   ()
 -> Indexed PQ IO () db0 db1)
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     IO
     ()
-> Indexed PQ IO () db0 db1
forall a b. (a -> b) -> a -> b
$ do
    Definition
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     IO
     ()
forall (pq :: SchemasType -> SchemasType -> (* -> *) -> * -> *)
       (io :: * -> *) (db0 :: SchemasType) (db1 :: SchemasType).
(IndexedMonadTransPQ pq, MonadIO io) =>
Definition db0 db1 -> pq db0 db1 io ()
define Definition
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
Definition MigrationsSchemas MigrationsSchemas
createMigrations
    (forall (x1 :: SchemasType) (y1 :: SchemasType).
 Migration (Indexed PQ IO ()) x1 y1
 -> PQ
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      IO
      ())
-> Path (Migration (Indexed PQ IO ())) db0 db1
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     IO
     ()
forall k (c :: (k -> k -> *) -> k -> k -> *) m (p :: k -> k -> *)
       (x :: k) (y :: k).
(QFoldable c, Monoid m) =>
(forall (x1 :: k) (y1 :: k). p x1 y1 -> m) -> c p x y -> m
qtoMonoid forall (x1 :: SchemasType) (y1 :: SchemasType).
Migration (Indexed PQ IO ()) x1 y1
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     IO
     ()
forall (m :: * -> *) a (db0 :: SchemasType) (db1 :: SchemasType).
MonadIO m =>
Migration (Indexed PQ m a) db0 db1
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     m
     ()
upMigration Path (Migration (Indexed PQ IO ())) db0 db1
path
    where
      upMigration :: Migration (Indexed PQ m a) db0 db1
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     m
     ()
upMigration Migration (Indexed PQ m a) db0 db1
step = do
        Row
executed <- do
          Result UTCTime
result <- Statement
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  Text
  UTCTime
-> Text
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     m
     (Result UTCTime)
forall (db :: SchemasType) (pq :: * -> *) x y.
MonadPQ db pq =>
Statement db x y -> x -> pq (Result y)
executeParams Statement
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  Text
  UTCTime
Statement MigrationsSchemas Text UTCTime
selectMigration (Migration (Indexed PQ m a) db0 db1 -> Text
forall k k (def :: k -> k -> *) (db0 :: k) (db1 :: k).
Migration def db0 db1 -> Text
migrationName Migration (Indexed PQ m a) db0 db1
step)
          Result UTCTime
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     m
     Row
forall (m :: * -> *) y. MonadResult m => Result y -> m Row
ntuples (Result UTCTime
result :: Result UTCTime)
        Bool
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     m
     ()
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     m
     ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Row
executed Row -> Row -> Bool
forall a. Eq a => a -> a -> Bool
== Row
1) (PQ
   '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
   '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
   m
   ()
 -> PQ
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      m
      ())
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     m
     ()
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     m
     ()
forall a b. (a -> b) -> a -> b
$ do
          a
_ <- PQ db0 db1 m a
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     m
     a
forall (m :: * -> *) (db0 :: SchemasType) (db1 :: SchemasType) x
       (db0' :: SchemasType) (db1' :: SchemasType).
Functor m =>
PQ db0 db1 m x -> PQ db0' db1' m x
unsafePQ (PQ db0 db1 m a
 -> PQ
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      m
      a)
-> (Indexed PQ m a db0 db1 -> PQ db0 db1 m a)
-> Indexed PQ m a db0 db1
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     m
     a
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Indexed PQ m a db0 db1 -> PQ db0 db1 m a
forall k k k k (t :: k -> k -> k -> k -> *) (m :: k) (r :: k)
       (i :: k) (j :: k).
Indexed t m r i j -> t i j m r
runIndexed (Indexed PQ m a db0 db1
 -> PQ
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      m
      a)
-> Indexed PQ m a db0 db1
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     m
     a
forall a b. (a -> b) -> a -> b
$ Migration (Indexed PQ m a) db0 db1 -> Indexed PQ m a db0 db1
forall k k (def :: k -> k -> *) (db0 :: k) (db1 :: k).
Migration def db0 db1 -> def db0 db1
migrationDef Migration (Indexed PQ m a) db0 db1
step
          Statement
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  Text
  ()
-> Text
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     m
     ()
forall (db :: SchemasType) (pq :: * -> *) x.
MonadPQ db pq =>
Statement db x () -> x -> pq ()
executeParams_ Statement
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  Text
  ()
Statement MigrationsSchemas Text ()
insertMigration (Migration (Indexed PQ m a) db0 db1 -> Text
forall k k (def :: k -> k -> *) (db0 :: k) (db1 :: k).
Migration def db0 db1 -> Text
migrationName Migration (Indexed PQ m a) db0 db1
step)
-- | pure migrations
instance Migratory Definition (Indexed PQ IO ()) where
  runMigrations :: Path (Migration Definition) db0 db1 -> Indexed PQ IO () db0 db1
runMigrations = Path (Migration (Indexed PQ IO ())) db0 db1
-> Indexed PQ IO () db0 db1
forall k (def :: k -> k -> *) (run :: k -> k -> *) (db0 :: k)
       (db1 :: k).
Migratory def run =>
Path (Migration def) db0 db1 -> run db0 db1
runMigrations (Path (Migration (Indexed PQ IO ())) db0 db1
 -> Indexed PQ IO () db0 db1)
-> (Path (Migration Definition) db0 db1
    -> Path (Migration (Indexed PQ IO ())) db0 db1)
-> Path (Migration Definition) db0 db1
-> Indexed PQ IO () db0 db1
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (forall (x1 :: SchemasType) (y1 :: SchemasType).
 Migration Definition x1 y1 -> Migration (Indexed PQ IO ()) x1 y1)
-> Path (Migration Definition) db0 db1
-> Path (Migration (Indexed PQ IO ())) db0 db1
forall k k1 k2 k3 (c :: (k -> k1 -> *) -> k2 -> k3 -> *)
       (p :: k -> k1 -> *) (q :: k -> k1 -> *) (x :: k2) (y :: k3).
QFunctor c =>
(forall (x1 :: k) (y1 :: k1). p x1 y1 -> q x1 y1)
-> c p x y -> c q x y
qmap ((forall (x1 :: SchemasType) (y1 :: SchemasType).
 Definition x1 y1 -> Indexed PQ IO () x1 y1)
-> Migration Definition x1 y1 -> Migration (Indexed PQ IO ()) x1 y1
forall k k1 k2 k3 (c :: (k -> k1 -> *) -> k2 -> k3 -> *)
       (p :: k -> k1 -> *) (q :: k -> k1 -> *) (x :: k2) (y :: k3).
QFunctor c =>
(forall (x1 :: k) (y1 :: k1). p x1 y1 -> q x1 y1)
-> c p x y -> c q x y
qmap forall (x1 :: SchemasType) (y1 :: SchemasType).
Definition x1 y1 -> Indexed PQ IO () x1 y1
ixDefine)
-- | impure rewinds
instance Migratory (OpQ (Indexed PQ IO ())) (OpQ (Indexed PQ IO ())) where
  runMigrations :: Path (Migration (OpQ (Indexed PQ IO ()))) db0 db1
-> OpQ (Indexed PQ IO ()) db0 db1
runMigrations Path (Migration (OpQ (Indexed PQ IO ()))) db0 db1
path = Indexed PQ IO () db1 db0 -> OpQ (Indexed PQ IO ()) db0 db1
forall k k1 (c :: k -> k1 -> *) (x :: k1) (y :: k).
c y x -> OpQ c x y
OpQ (Indexed PQ IO () db1 db0 -> OpQ (Indexed PQ IO ()) db0 db1)
-> (PQ
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      IO
      ()
    -> Indexed PQ IO () db1 db0)
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     IO
     ()
-> OpQ (Indexed PQ IO ()) db0 db1
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. PQ db1 db0 IO () -> Indexed PQ IO () db1 db0
forall k k k k (t :: k -> k -> k -> k -> *) (m :: k) (r :: k)
       (i :: k) (j :: k).
t i j m r -> Indexed t m r i j
Indexed (PQ db1 db0 IO () -> Indexed PQ IO () db1 db0)
-> (PQ
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      IO
      ()
    -> PQ db1 db0 IO ())
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     IO
     ()
-> Indexed PQ IO () db1 db0
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. PQ
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  IO
  ()
-> PQ db1 db0 IO ()
forall (m :: * -> *) (db0 :: SchemasType) (db1 :: SchemasType) x
       (db0' :: SchemasType) (db1' :: SchemasType).
Functor m =>
PQ db0 db1 m x -> PQ db0' db1' m x
unsafePQ (PQ
   '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
   '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
   IO
   ()
 -> PQ db1 db0 IO ())
-> (PQ
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      IO
      ()
    -> PQ
         '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
         '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
         IO
         ())
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     IO
     ()
-> PQ db1 db0 IO ()
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. PQ
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  IO
  ()
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     IO
     ()
forall (tx :: * -> *) (db :: SchemasType) x.
(MonadMask tx, MonadPQ db tx) =>
tx x -> tx x
transactionally_ (PQ
   '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
   '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
   IO
   ()
 -> OpQ (Indexed PQ IO ()) db0 db1)
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     IO
     ()
-> OpQ (Indexed PQ IO ()) db0 db1
forall a b. (a -> b) -> a -> b
$ do
    Definition
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     IO
     ()
forall (pq :: SchemasType -> SchemasType -> (* -> *) -> * -> *)
       (io :: * -> *) (db0 :: SchemasType) (db1 :: SchemasType).
(IndexedMonadTransPQ pq, MonadIO io) =>
Definition db0 db1 -> pq db0 db1 io ()
define Definition
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
Definition MigrationsSchemas MigrationsSchemas
createMigrations
    (forall (x1 :: SchemasType) (y1 :: SchemasType).
 OpQ (Migration (OpQ (Indexed PQ IO ()))) x1 y1
 -> PQ
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      IO
      ())
-> FoldPath (OpQ (Migration (OpQ (Indexed PQ IO ())))) db1 db0
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     IO
     ()
forall k (c :: (k -> k -> *) -> k -> k -> *) m (p :: k -> k -> *)
       (x :: k) (y :: k).
(QFoldable c, Monoid m) =>
(forall (x1 :: k) (y1 :: k). p x1 y1 -> m) -> c p x y -> m
qtoMonoid @FoldPath forall (x1 :: SchemasType) (y1 :: SchemasType).
OpQ (Migration (OpQ (Indexed PQ IO ()))) x1 y1
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     IO
     ()
forall (m :: * -> *) a (db1 :: SchemasType) (db0 :: SchemasType).
MonadIO m =>
OpQ (Migration (OpQ (Indexed PQ m a))) db1 db0
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     m
     ()
downMigration (Path (Migration (OpQ (Indexed PQ IO ()))) db0 db1
-> FoldPath (OpQ (Migration (OpQ (Indexed PQ IO ())))) db1 db0
forall k (c :: (k -> k -> *) -> k -> k -> *)
       (path :: (k -> k -> *) -> k -> k -> *) (p :: k -> k -> *) (x :: k)
       (y :: k).
(QFoldable c, CFree path) =>
c p x y -> path (OpQ p) y x
reversePath Path (Migration (OpQ (Indexed PQ IO ()))) db0 db1
path)
    where
      downMigration :: OpQ (Migration (OpQ (Indexed PQ m a))) db1 db0
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     m
     ()
downMigration (OpQ Migration (OpQ (Indexed PQ m a)) db0 db1
step) = do
        Row
executed <- do
          Result UTCTime
result <- Statement
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  Text
  UTCTime
-> Text
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     m
     (Result UTCTime)
forall (db :: SchemasType) (pq :: * -> *) x y.
MonadPQ db pq =>
Statement db x y -> x -> pq (Result y)
executeParams Statement
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  Text
  UTCTime
Statement MigrationsSchemas Text UTCTime
selectMigration (Migration (OpQ (Indexed PQ m a)) db0 db1 -> Text
forall k k (def :: k -> k -> *) (db0 :: k) (db1 :: k).
Migration def db0 db1 -> Text
migrationName Migration (OpQ (Indexed PQ m a)) db0 db1
step)
          Result UTCTime
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     m
     Row
forall (m :: * -> *) y. MonadResult m => Result y -> m Row
ntuples (Result UTCTime
result :: Result UTCTime)
        Bool
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     m
     ()
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     m
     ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Row
executed Row -> Row -> Bool
forall a. Eq a => a -> a -> Bool
== Row
0) (PQ
   '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
   '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
   m
   ()
 -> PQ
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      m
      ())
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     m
     ()
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     m
     ()
forall a b. (a -> b) -> a -> b
$ do
          a
_ <- PQ db1 db0 m a
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     m
     a
forall (m :: * -> *) (db0 :: SchemasType) (db1 :: SchemasType) x
       (db0' :: SchemasType) (db1' :: SchemasType).
Functor m =>
PQ db0 db1 m x -> PQ db0' db1' m x
unsafePQ (PQ db1 db0 m a
 -> PQ
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      m
      a)
-> (OpQ (Indexed PQ m a) db0 db1 -> PQ db1 db0 m a)
-> OpQ (Indexed PQ m a) db0 db1
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     m
     a
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Indexed PQ m a db1 db0 -> PQ db1 db0 m a
forall k k k k (t :: k -> k -> k -> k -> *) (m :: k) (r :: k)
       (i :: k) (j :: k).
Indexed t m r i j -> t i j m r
runIndexed (Indexed PQ m a db1 db0 -> PQ db1 db0 m a)
-> (OpQ (Indexed PQ m a) db0 db1 -> Indexed PQ m a db1 db0)
-> OpQ (Indexed PQ m a) db0 db1
-> PQ db1 db0 m a
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. OpQ (Indexed PQ m a) db0 db1 -> Indexed PQ m a db1 db0
forall k1 k2 (c :: k2 -> k1 -> *) (x :: k1) (y :: k2).
OpQ c x y -> c y x
getOpQ (OpQ (Indexed PQ m a) db0 db1
 -> PQ
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      m
      a)
-> OpQ (Indexed PQ m a) db0 db1
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     m
     a
forall a b. (a -> b) -> a -> b
$ Migration (OpQ (Indexed PQ m a)) db0 db1
-> OpQ (Indexed PQ m a) db0 db1
forall k k (def :: k -> k -> *) (db0 :: k) (db1 :: k).
Migration def db0 db1 -> def db0 db1
migrationDef Migration (OpQ (Indexed PQ m a)) db0 db1
step
          Statement
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  Text
  ()
-> Text
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     m
     ()
forall (db :: SchemasType) (pq :: * -> *) x.
MonadPQ db pq =>
Statement db x () -> x -> pq ()
executeParams_ Statement
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  Text
  ()
Statement MigrationsSchemas Text ()
deleteMigration (Migration (OpQ (Indexed PQ m a)) db0 db1 -> Text
forall k k (def :: k -> k -> *) (db0 :: k) (db1 :: k).
Migration def db0 db1 -> Text
migrationName Migration (OpQ (Indexed PQ m a)) db0 db1
step)
-- | pure rewinds
instance Migratory (OpQ Definition) (OpQ (Indexed PQ IO ())) where
  runMigrations :: Path (Migration (OpQ Definition)) db0 db1
-> OpQ (Indexed PQ IO ()) db0 db1
runMigrations = Path (Migration (OpQ (Indexed PQ IO ()))) db0 db1
-> OpQ (Indexed PQ IO ()) db0 db1
forall k (def :: k -> k -> *) (run :: k -> k -> *) (db0 :: k)
       (db1 :: k).
Migratory def run =>
Path (Migration def) db0 db1 -> run db0 db1
runMigrations (Path (Migration (OpQ (Indexed PQ IO ()))) db0 db1
 -> OpQ (Indexed PQ IO ()) db0 db1)
-> (Path (Migration (OpQ Definition)) db0 db1
    -> Path (Migration (OpQ (Indexed PQ IO ()))) db0 db1)
-> Path (Migration (OpQ Definition)) db0 db1
-> OpQ (Indexed PQ IO ()) db0 db1
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (forall (x1 :: SchemasType) (y1 :: SchemasType).
 Migration (OpQ Definition) x1 y1
 -> Migration (OpQ (Indexed PQ IO ())) x1 y1)
-> Path (Migration (OpQ Definition)) db0 db1
-> Path (Migration (OpQ (Indexed PQ IO ()))) db0 db1
forall k k1 k2 k3 (c :: (k -> k1 -> *) -> k2 -> k3 -> *)
       (p :: k -> k1 -> *) (q :: k -> k1 -> *) (x :: k2) (y :: k3).
QFunctor c =>
(forall (x1 :: k) (y1 :: k1). p x1 y1 -> q x1 y1)
-> c p x y -> c q x y
qmap ((forall (x1 :: SchemasType) (y1 :: SchemasType).
 OpQ Definition x1 y1 -> OpQ (Indexed PQ IO ()) x1 y1)
-> Migration (OpQ Definition) x1 y1
-> Migration (OpQ (Indexed PQ IO ())) x1 y1
forall k k1 k2 k3 (c :: (k -> k1 -> *) -> k2 -> k3 -> *)
       (p :: k -> k1 -> *) (q :: k -> k1 -> *) (x :: k2) (y :: k3).
QFunctor c =>
(forall (x1 :: k) (y1 :: k1). p x1 y1 -> q x1 y1)
-> c p x y -> c q x y
qmap ((forall (x1 :: SchemasType) (y1 :: SchemasType).
 Definition x1 y1 -> Indexed PQ IO () x1 y1)
-> OpQ Definition x1 y1 -> OpQ (Indexed PQ IO ()) x1 y1
forall k k1 k2 k3 (c :: (k -> k1 -> *) -> k2 -> k3 -> *)
       (p :: k -> k1 -> *) (q :: k -> k1 -> *) (x :: k2) (y :: k3).
QFunctor c =>
(forall (x1 :: k) (y1 :: k1). p x1 y1 -> q x1 y1)
-> c p x y -> c q x y
qmap forall (x1 :: SchemasType) (y1 :: SchemasType).
Definition x1 y1 -> Indexed PQ IO () x1 y1
ixDefine))
-- | impure rewindable migrations
instance Migratory
  (IsoQ (Indexed PQ IO ()))
  (IsoQ (Indexed PQ IO ())) where
    runMigrations :: Path (Migration (IsoQ (Indexed PQ IO ()))) db0 db1
-> IsoQ (Indexed PQ IO ()) db0 db1
runMigrations Path (Migration (IsoQ (Indexed PQ IO ()))) db0 db1
path = Indexed PQ IO () db0 db1
-> Indexed PQ IO () db1 db0 -> IsoQ (Indexed PQ IO ()) db0 db1
forall k (c :: k -> k -> *) (x :: k) (y :: k).
c x y -> c y x -> IsoQ c x y
IsoQ
      (Path (Migration (Indexed PQ IO ())) db0 db1
-> Indexed PQ IO () db0 db1
forall k (def :: k -> k -> *) (run :: k -> k -> *) (db0 :: k)
       (db1 :: k).
Migratory def run =>
Path (Migration def) db0 db1 -> run db0 db1
runMigrations ((forall (x1 :: SchemasType) (y1 :: SchemasType).
 Migration (IsoQ (Indexed PQ IO ())) x1 y1
 -> Migration (Indexed PQ IO ()) x1 y1)
-> Path (Migration (IsoQ (Indexed PQ IO ()))) db0 db1
-> Path (Migration (Indexed PQ IO ())) db0 db1
forall k k1 k2 k3 (c :: (k -> k1 -> *) -> k2 -> k3 -> *)
       (p :: k -> k1 -> *) (q :: k -> k1 -> *) (x :: k2) (y :: k3).
QFunctor c =>
(forall (x1 :: k) (y1 :: k1). p x1 y1 -> q x1 y1)
-> c p x y -> c q x y
qmap ((forall (x1 :: SchemasType) (y1 :: SchemasType).
 IsoQ (Indexed PQ IO ()) x1 y1 -> Indexed PQ IO () x1 y1)
-> Migration (IsoQ (Indexed PQ IO ())) x1 y1
-> Migration (Indexed PQ IO ()) x1 y1
forall k k1 k2 k3 (c :: (k -> k1 -> *) -> k2 -> k3 -> *)
       (p :: k -> k1 -> *) (q :: k -> k1 -> *) (x :: k2) (y :: k3).
QFunctor c =>
(forall (x1 :: k) (y1 :: k1). p x1 y1 -> q x1 y1)
-> c p x y -> c q x y
qmap forall (x1 :: SchemasType) (y1 :: SchemasType).
IsoQ (Indexed PQ IO ()) x1 y1 -> Indexed PQ IO () x1 y1
forall k (c :: k -> k -> *) (x :: k) (y :: k). IsoQ c x y -> c x y
up) Path (Migration (IsoQ (Indexed PQ IO ()))) db0 db1
path))
      (OpQ (Indexed PQ IO ()) db0 db1 -> Indexed PQ IO () db1 db0
forall k1 k2 (c :: k2 -> k1 -> *) (x :: k1) (y :: k2).
OpQ c x y -> c y x
getOpQ (Path (Migration (OpQ (Indexed PQ IO ()))) db0 db1
-> OpQ (Indexed PQ IO ()) db0 db1
forall k (def :: k -> k -> *) (run :: k -> k -> *) (db0 :: k)
       (db1 :: k).
Migratory def run =>
Path (Migration def) db0 db1 -> run db0 db1
runMigrations ((forall (x1 :: SchemasType) (y1 :: SchemasType).
 Migration (IsoQ (Indexed PQ IO ())) x1 y1
 -> Migration (OpQ (Indexed PQ IO ())) x1 y1)
-> Path (Migration (IsoQ (Indexed PQ IO ()))) db0 db1
-> Path (Migration (OpQ (Indexed PQ IO ()))) db0 db1
forall k k1 k2 k3 (c :: (k -> k1 -> *) -> k2 -> k3 -> *)
       (p :: k -> k1 -> *) (q :: k -> k1 -> *) (x :: k2) (y :: k3).
QFunctor c =>
(forall (x1 :: k) (y1 :: k1). p x1 y1 -> q x1 y1)
-> c p x y -> c q x y
qmap ((forall (x1 :: SchemasType) (y1 :: SchemasType).
 IsoQ (Indexed PQ IO ()) x1 y1 -> OpQ (Indexed PQ IO ()) x1 y1)
-> Migration (IsoQ (Indexed PQ IO ())) x1 y1
-> Migration (OpQ (Indexed PQ IO ())) x1 y1
forall k k1 k2 k3 (c :: (k -> k1 -> *) -> k2 -> k3 -> *)
       (p :: k -> k1 -> *) (q :: k -> k1 -> *) (x :: k2) (y :: k3).
QFunctor c =>
(forall (x1 :: k) (y1 :: k1). p x1 y1 -> q x1 y1)
-> c p x y -> c q x y
qmap (Indexed PQ IO () y1 x1 -> OpQ (Indexed PQ IO ()) x1 y1
forall k k1 (c :: k -> k1 -> *) (x :: k1) (y :: k).
c y x -> OpQ c x y
OpQ (Indexed PQ IO () y1 x1 -> OpQ (Indexed PQ IO ()) x1 y1)
-> (IsoQ (Indexed PQ IO ()) x1 y1 -> Indexed PQ IO () y1 x1)
-> IsoQ (Indexed PQ IO ()) x1 y1
-> OpQ (Indexed PQ IO ()) x1 y1
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. IsoQ (Indexed PQ IO ()) x1 y1 -> Indexed PQ IO () y1 x1
forall k (c :: k -> k -> *) (x :: k) (y :: k). IsoQ c x y -> c y x
down)) Path (Migration (IsoQ (Indexed PQ IO ()))) db0 db1
path)))
-- | pure rewindable migrations
instance Migratory (IsoQ Definition) (IsoQ (Indexed PQ IO ())) where
  runMigrations :: Path (Migration (IsoQ Definition)) db0 db1
-> IsoQ (Indexed PQ IO ()) db0 db1
runMigrations = Path (Migration (IsoQ (Indexed PQ IO ()))) db0 db1
-> IsoQ (Indexed PQ IO ()) db0 db1
forall k (def :: k -> k -> *) (run :: k -> k -> *) (db0 :: k)
       (db1 :: k).
Migratory def run =>
Path (Migration def) db0 db1 -> run db0 db1
runMigrations (Path (Migration (IsoQ (Indexed PQ IO ()))) db0 db1
 -> IsoQ (Indexed PQ IO ()) db0 db1)
-> (Path (Migration (IsoQ Definition)) db0 db1
    -> Path (Migration (IsoQ (Indexed PQ IO ()))) db0 db1)
-> Path (Migration (IsoQ Definition)) db0 db1
-> IsoQ (Indexed PQ IO ()) db0 db1
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (forall (x1 :: SchemasType) (y1 :: SchemasType).
 Migration (IsoQ Definition) x1 y1
 -> Migration (IsoQ (Indexed PQ IO ())) x1 y1)
-> Path (Migration (IsoQ Definition)) db0 db1
-> Path (Migration (IsoQ (Indexed PQ IO ()))) db0 db1
forall k k1 k2 k3 (c :: (k -> k1 -> *) -> k2 -> k3 -> *)
       (p :: k -> k1 -> *) (q :: k -> k1 -> *) (x :: k2) (y :: k3).
QFunctor c =>
(forall (x1 :: k) (y1 :: k1). p x1 y1 -> q x1 y1)
-> c p x y -> c q x y
qmap ((forall (x1 :: SchemasType) (y1 :: SchemasType).
 IsoQ Definition x1 y1 -> IsoQ (Indexed PQ IO ()) x1 y1)
-> Migration (IsoQ Definition) x1 y1
-> Migration (IsoQ (Indexed PQ IO ())) x1 y1
forall k k1 k2 k3 (c :: (k -> k1 -> *) -> k2 -> k3 -> *)
       (p :: k -> k1 -> *) (q :: k -> k1 -> *) (x :: k2) (y :: k3).
QFunctor c =>
(forall (x1 :: k) (y1 :: k1). p x1 y1 -> q x1 y1)
-> c p x y -> c q x y
qmap ((forall (x1 :: SchemasType) (y1 :: SchemasType).
 Definition x1 y1 -> Indexed PQ IO () x1 y1)
-> IsoQ Definition x1 y1 -> IsoQ (Indexed PQ IO ()) x1 y1
forall k k1 k2 k3 (c :: (k -> k1 -> *) -> k2 -> k3 -> *)
       (p :: k -> k1 -> *) (q :: k -> k1 -> *) (x :: k2) (y :: k3).
QFunctor c =>
(forall (x1 :: k) (y1 :: k1). p x1 y1 -> q x1 y1)
-> c p x y -> c q x y
qmap forall (x1 :: SchemasType) (y1 :: SchemasType).
Definition x1 y1 -> Indexed PQ IO () x1 y1
ixDefine))

unsafePQ :: (Functor m) => PQ db0 db1 m x -> PQ db0' db1' m x
unsafePQ :: PQ db0 db1 m x -> PQ db0' db1' m x
unsafePQ (PQ K Connection db0 -> m (K x db1)
pq) = (K Connection db0' -> m (K x db1')) -> PQ db0' db1' m x
forall (db0 :: SchemasType) (db1 :: SchemasType) (m :: * -> *) x.
(K Connection db0 -> m (K x db1)) -> PQ db0 db1 m x
PQ ((K Connection db0' -> m (K x db1')) -> PQ db0' db1' m x)
-> (K Connection db0' -> m (K x db1')) -> PQ db0' db1' m x
forall a b. (a -> b) -> a -> b
$ (K x db1 -> K x db1') -> m (K x db1) -> m (K x db1')
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (x -> K x db1'
forall k a (b :: k). a -> K a b
SOP.K (x -> K x db1') -> (K x db1 -> x) -> K x db1 -> K x db1'
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. K x db1 -> x
forall k a (b :: k). K a b -> a
SOP.unK) (m (K x db1) -> m (K x db1'))
-> (K Connection db0' -> m (K x db1))
-> K Connection db0'
-> m (K x db1')
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. K Connection db0 -> m (K x db1)
pq (K Connection db0 -> m (K x db1))
-> (K Connection db0' -> K Connection db0)
-> K Connection db0'
-> m (K x db1)
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Connection -> K Connection db0
forall k a (b :: k). a -> K a b
SOP.K (Connection -> K Connection db0)
-> (K Connection db0' -> Connection)
-> K Connection db0'
-> K Connection db0
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. K Connection db0' -> Connection
forall k a (b :: k). K a b -> a
SOP.unK

-- | Run migrations.
migrate
  :: Migratory def (Indexed PQ IO ())
  => Path (Migration def) db0 db1
  -> PQ db0 db1 IO ()
migrate :: Path (Migration def) db0 db1 -> PQ db0 db1 IO ()
migrate = Indexed PQ IO () db0 db1 -> PQ db0 db1 IO ()
forall k k k k (t :: k -> k -> k -> k -> *) (m :: k) (r :: k)
       (i :: k) (j :: k).
Indexed t m r i j -> t i j m r
runIndexed (Indexed PQ IO () db0 db1 -> PQ db0 db1 IO ())
-> (Path (Migration def) db0 db1 -> Indexed PQ IO () db0 db1)
-> Path (Migration def) db0 db1
-> PQ db0 db1 IO ()
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Path (Migration def) db0 db1 -> Indexed PQ IO () db0 db1
forall k (def :: k -> k -> *) (run :: k -> k -> *) (db0 :: k)
       (db1 :: k).
Migratory def run =>
Path (Migration def) db0 db1 -> run db0 db1
runMigrations

-- | Run rewindable migrations.
migrateUp
  :: Migratory def (IsoQ (Indexed PQ IO ()))
  => Path (Migration def) db0 db1
  -> PQ db0 db1 IO ()
migrateUp :: Path (Migration def) db0 db1 -> PQ db0 db1 IO ()
migrateUp = Indexed PQ IO () db0 db1 -> PQ db0 db1 IO ()
forall k k k k (t :: k -> k -> k -> k -> *) (m :: k) (r :: k)
       (i :: k) (j :: k).
Indexed t m r i j -> t i j m r
runIndexed (Indexed PQ IO () db0 db1 -> PQ db0 db1 IO ())
-> (Path (Migration def) db0 db1 -> Indexed PQ IO () db0 db1)
-> Path (Migration def) db0 db1
-> PQ db0 db1 IO ()
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. IsoQ (Indexed PQ IO ()) db0 db1 -> Indexed PQ IO () db0 db1
forall k (c :: k -> k -> *) (x :: k) (y :: k). IsoQ c x y -> c x y
up (IsoQ (Indexed PQ IO ()) db0 db1 -> Indexed PQ IO () db0 db1)
-> (Path (Migration def) db0 db1
    -> IsoQ (Indexed PQ IO ()) db0 db1)
-> Path (Migration def) db0 db1
-> Indexed PQ IO () db0 db1
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Path (Migration def) db0 db1 -> IsoQ (Indexed PQ IO ()) db0 db1
forall k (def :: k -> k -> *) (run :: k -> k -> *) (db0 :: k)
       (db1 :: k).
Migratory def run =>
Path (Migration def) db0 db1 -> run db0 db1
runMigrations

-- | Rewind migrations.
migrateDown
  :: Migratory def (IsoQ (Indexed PQ IO ()))
  => Path (Migration def) db0 db1
  -> PQ db1 db0 IO ()
migrateDown :: Path (Migration def) db0 db1 -> PQ db1 db0 IO ()
migrateDown = Indexed PQ IO () db1 db0 -> PQ db1 db0 IO ()
forall k k k k (t :: k -> k -> k -> k -> *) (m :: k) (r :: k)
       (i :: k) (j :: k).
Indexed t m r i j -> t i j m r
runIndexed (Indexed PQ IO () db1 db0 -> PQ db1 db0 IO ())
-> (Path (Migration def) db0 db1 -> Indexed PQ IO () db1 db0)
-> Path (Migration def) db0 db1
-> PQ db1 db0 IO ()
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. IsoQ (Indexed PQ IO ()) db0 db1 -> Indexed PQ IO () db1 db0
forall k (c :: k -> k -> *) (x :: k) (y :: k). IsoQ c x y -> c y x
down (IsoQ (Indexed PQ IO ()) db0 db1 -> Indexed PQ IO () db1 db0)
-> (Path (Migration def) db0 db1
    -> IsoQ (Indexed PQ IO ()) db0 db1)
-> Path (Migration def) db0 db1
-> Indexed PQ IO () db1 db0
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Path (Migration def) db0 db1 -> IsoQ (Indexed PQ IO ()) db0 db1
forall k (def :: k -> k -> *) (run :: k -> k -> *) (db0 :: k)
       (db1 :: k).
Migratory def run =>
Path (Migration def) db0 db1 -> run db0 db1
runMigrations

ixDefine :: Definition db0 db1 -> Indexed PQ IO () db0 db1
ixDefine :: Definition db0 db1 -> Indexed PQ IO () db0 db1
ixDefine = Definition db0 db1 -> Indexed PQ IO () db0 db1
forall (pq :: SchemasType -> SchemasType -> (* -> *) -> * -> *)
       (io :: * -> *) (db0 :: SchemasType) (db1 :: SchemasType).
(IndexedMonadTransPQ pq, MonadIO io) =>
Definition db0 db1 -> Indexed pq io () db0 db1
indexedDefine

-- | The `TableType` for a Squeal migration.
type MigrationsTable =
  '[ "migrations_unique_name" ::: 'Unique '["name"]] :=>
  '[ "name"        ::: 'NoDef :=> 'NotNull 'PGtext
   , "executed_at" :::   'Def :=> 'NotNull 'PGtimestamptz
   ]

data MigrationRow =
  MigrationRow { MigrationRow -> Text
name :: Text
               , MigrationRow -> UTCTime
executed_at :: UTCTime }
  deriving ((forall x. MigrationRow -> Rep MigrationRow x)
-> (forall x. Rep MigrationRow x -> MigrationRow)
-> Generic MigrationRow
forall x. Rep MigrationRow x -> MigrationRow
forall x. MigrationRow -> Rep MigrationRow x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MigrationRow x -> MigrationRow
$cfrom :: forall x. MigrationRow -> Rep MigrationRow x
GHC.Generic, Int -> MigrationRow -> ShowS
[MigrationRow] -> ShowS
MigrationRow -> String
(Int -> MigrationRow -> ShowS)
-> (MigrationRow -> String)
-> ([MigrationRow] -> ShowS)
-> Show MigrationRow
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MigrationRow] -> ShowS
$cshowList :: [MigrationRow] -> ShowS
show :: MigrationRow -> String
$cshow :: MigrationRow -> String
showsPrec :: Int -> MigrationRow -> ShowS
$cshowsPrec :: Int -> MigrationRow -> ShowS
Show)

instance SOP.Generic MigrationRow
instance SOP.HasDatatypeInfo MigrationRow

type MigrationsSchema = '["schema_migrations" ::: 'Table MigrationsTable]
type MigrationsSchemas = Public MigrationsSchema

-- | Creates a `MigrationsTable` if it does not already exist.
createMigrations :: Definition MigrationsSchemas MigrationsSchemas
createMigrations :: Definition MigrationsSchemas MigrationsSchemas
createMigrations =
  QualifiedAlias "public" "schema_migrations"
-> NP
     (Aliased
        (ColumnTypeExpression
           '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]))
     '["name" ::: '( 'NoDef, 'NotNull 'PGtext),
       "executed_at" ::: '( 'Def, 'NotNull 'PGtimestamptz)]
-> NP
     (Aliased
        (TableConstraintExpression
           "public"
           "schema_migrations"
           '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]))
     '["migrations_unique_name" ::: 'Unique '["name"]]
-> Definition
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
forall (sch :: Symbol) (tab :: Symbol)
       (columns :: [(Symbol, ColumnType)]) (col :: (Symbol, ColumnType))
       (cols :: [(Symbol, ColumnType)])
       (constraints :: [(Symbol, TableConstraint)]) (db0 :: SchemasType)
       (schema0 :: SchemaType) (db1 :: SchemasType).
(KnownSymbol sch, KnownSymbol tab, columns ~ (col : cols),
 SListI columns, SListI constraints, Has sch db0 schema0,
 db1
 ~ Alter
     sch
     (CreateIfNotExists tab ('Table (constraints :=> columns)) schema0)
     db0) =>
QualifiedAlias sch tab
-> NP (Aliased (ColumnTypeExpression db0)) columns
-> NP (Aliased (TableConstraintExpression sch tab db1)) constraints
-> Definition db0 db1
createTableIfNotExists IsLabel
  "schema_migrations" (QualifiedAlias "public" "schema_migrations")
QualifiedAlias "public" "schema_migrations"
#schema_migrations
    ( (TypeExpression
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  (Any 'PGtext)
forall (db :: SchemasType) (null :: PGType -> NullType).
TypeExpression db (null 'PGtext)
text TypeExpression
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  (Any 'PGtext)
-> (TypeExpression
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      (Any 'PGtext)
    -> ColumnTypeExpression
         '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
         '( 'NoDef, 'NotNull 'PGtext))
-> ColumnTypeExpression
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '( 'NoDef, 'NotNull 'PGtext)
forall a b. a -> (a -> b) -> b
& TypeExpression
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  (Any 'PGtext)
-> ColumnTypeExpression
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '( 'NoDef, 'NotNull 'PGtext)
forall (db :: SchemasType) (null :: PGType -> NullType)
       (ty :: PGType).
TypeExpression db (null ty)
-> ColumnTypeExpression db ('NoDef :=> 'NotNull ty)
notNullable) `as` IsLabel "name" (Alias "name")
Alias "name"
#name Aliased
  (ColumnTypeExpression
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]])
  ("name" ::: '( 'NoDef, 'NotNull 'PGtext))
-> NP
     (Aliased
        (ColumnTypeExpression
           '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]))
     '["executed_at" ::: '( 'Def, 'NotNull 'PGtimestamptz)]
-> NP
     (Aliased
        (ColumnTypeExpression
           '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]))
     '["name" ::: '( 'NoDef, 'NotNull 'PGtext),
       "executed_at" ::: '( 'Def, 'NotNull 'PGtimestamptz)]
forall k (a :: k -> *) (x :: k) (xs :: [k]).
a x -> NP a xs -> NP a (x : xs)
:*
      (TypeExpression
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  (Any 'PGtimestamptz)
forall (db :: SchemasType) (null :: PGType -> NullType).
TypeExpression db (null 'PGtimestamptz)
timestampWithTimeZone TypeExpression
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  (Any 'PGtimestamptz)
-> (TypeExpression
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      (Any 'PGtimestamptz)
    -> ColumnTypeExpression
         '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
         ('NoDef :=> 'NotNull 'PGtimestamptz))
-> ColumnTypeExpression
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     ('NoDef :=> 'NotNull 'PGtimestamptz)
forall a b. a -> (a -> b) -> b
& TypeExpression
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  (Any 'PGtimestamptz)
-> ColumnTypeExpression
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     ('NoDef :=> 'NotNull 'PGtimestamptz)
forall (db :: SchemasType) (null :: PGType -> NullType)
       (ty :: PGType).
TypeExpression db (null ty)
-> ColumnTypeExpression db ('NoDef :=> 'NotNull ty)
notNullable ColumnTypeExpression
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  ('NoDef :=> 'NotNull 'PGtimestamptz)
-> (ColumnTypeExpression
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      ('NoDef :=> 'NotNull 'PGtimestamptz)
    -> ColumnTypeExpression
         '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
         '( 'Def, 'NotNull 'PGtimestamptz))
-> ColumnTypeExpression
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '( 'Def, 'NotNull 'PGtimestamptz)
forall a b. a -> (a -> b) -> b
& Expression
  'Ungrouped
  '[]
  '[]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '[]
  '[]
  ('NotNull 'PGtimestamptz)
-> ColumnTypeExpression
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     ('NoDef :=> 'NotNull 'PGtimestamptz)
-> ColumnTypeExpression
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '( 'Def, 'NotNull 'PGtimestamptz)
forall (db :: SchemasType) (ty :: NullType).
Expression 'Ungrouped '[] '[] db '[] '[] ty
-> ColumnTypeExpression db ('NoDef :=> ty)
-> ColumnTypeExpression db ('Def :=> ty)
default_ Expression
  'Ungrouped
  '[]
  '[]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '[]
  '[]
  ('NotNull 'PGtimestamptz)
forall (null :: PGType -> NullType). Expr (null 'PGtimestamptz)
currentTimestamp)
        `as` IsLabel "executed_at" (Alias "executed_at")
Alias "executed_at"
#executed_at )
    ( NP Alias '["name"]
-> TableConstraintExpression
     "public"
     "schema_migrations"
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     ('Unique '["name"])
forall (sch :: Symbol) (db :: SchemasType) (schema :: SchemaType)
       (tab :: Symbol) (table :: TableType) (aliases :: [Symbol])
       (subcolumns :: RowType).
(Has sch db schema, Has tab schema ('Table table),
 HasAll aliases (TableToRow table) subcolumns) =>
NP Alias aliases
-> TableConstraintExpression sch tab db ('Unique aliases)
unique IsLabel "name" (NP Alias '["name"])
NP Alias '["name"]
#name `as` IsLabel "migrations_unique_name" (Alias "migrations_unique_name")
Alias "migrations_unique_name"
#migrations_unique_name )

-- | Inserts a `Migration` into the `MigrationsTable`, returning
-- the time at which it was inserted.
insertMigration :: Statement MigrationsSchemas Text ()
insertMigration :: Statement MigrationsSchemas Text ()
insertMigration = EncodeParams
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '[ 'NotNull 'PGtext]
  Text
-> DecodeRow '[] ()
-> Manipulation
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '[]
-> Statement
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     Text
     ()
forall (db :: SchemasType) (params :: [NullType]) (row :: RowType)
       x y.
(All (OidOfNull db) params, SListI row) =>
EncodeParams db params x
-> DecodeRow row y
-> Manipulation '[] db params row
-> Statement db x y
Manipulation EncodeParams
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '[ 'NotNull 'PGtext]
  Text
forall (db :: SchemasType) x (ty :: NullType).
(ToParam db ty x, ty ~ NullPG x) =>
EncodeParams db '[ty] x
aParam DecodeRow '[] ()
forall (row :: RowType) y (ys :: RecordCode).
GenericRow row y ys =>
DecodeRow row y
genericRow (Manipulation
   '[]
   '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
   '[ 'NotNull 'PGtext]
   '[]
 -> Statement
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      Text
      ())
-> Manipulation
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '[]
-> Statement
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     Text
     ()
forall a b. (a -> b) -> a -> b
$
  Aliased
  (QualifiedAlias "public")
  ("schema_migrations" ::: "schema_migrations")
-> QueryClause
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     (TableToColumns MigrationsTable)
-> Manipulation
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '[]
forall (sch :: Symbol) (db :: SchemasType) (schema :: SchemaType)
       (tab0 :: Symbol) (table :: TableType) (tab :: Symbol)
       (with :: FromType) (params :: [NullType]).
(Has sch db schema, Has tab0 schema ('Table table),
 SListI (TableToColumns table)) =>
Aliased (QualifiedAlias sch) (tab ::: tab0)
-> QueryClause with db params (TableToColumns table)
-> Manipulation with db params '[]
insertInto_ IsLabel
  "schema_migrations"
  (Aliased
     (QualifiedAlias "public")
     ("schema_migrations" ::: "schema_migrations"))
Aliased
  (QualifiedAlias "public")
  ("schema_migrations" ::: "schema_migrations")
#schema_migrations (QueryClause
   '[]
   '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
   '[ 'NotNull 'PGtext]
   (TableToColumns MigrationsTable)
 -> Manipulation
      '[]
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      '[ 'NotNull 'PGtext]
      '[])
-> QueryClause
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     (TableToColumns MigrationsTable)
-> Manipulation
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '[]
forall a b. (a -> b) -> a -> b
$
    NP
  (Aliased
     (Optional
        (Expression
           'Ungrouped
           '[]
           '[]
           '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
           '[ 'NotNull 'PGtext]
           Any)))
  '["name" ::: '( 'NoDef, 'NotNull 'PGtext),
    "executed_at" ::: '( 'Def, 'NotNull 'PGtimestamptz)]
-> QueryClause
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '["name" ::: '( 'NoDef, 'NotNull 'PGtext),
       "executed_at" ::: '( 'Def, 'NotNull 'PGtimestamptz)]
forall (columns :: [(Symbol, ColumnType)]) (with :: FromType)
       (db :: SchemasType) (params :: [NullType]) (from :: FromType).
SListI columns =>
NP
  (Aliased
     (Optional (Expression 'Ungrouped '[] with db params from)))
  columns
-> QueryClause with db params columns
Values_ (Expression
  'Ungrouped
  '[]
  '[]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '[ 'NotNull 'PGtext]
  Any
  ('NotNull 'PGtext)
-> Optional
     (Expression
        'Ungrouped
        '[]
        '[]
        '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
        '[ 'NotNull 'PGtext]
        Any)
     '( 'NoDef, 'NotNull 'PGtext)
forall k (expr :: k -> *) (ty :: k) (def :: Optionality).
expr ty -> Optional expr (def :=> ty)
Set (forall (n :: Nat) (ty :: NullType) (lat :: FromType)
       (with :: FromType) (db :: SchemasType) (params :: [NullType])
       (from :: FromType) (grp :: Grouping).
(NullTyped db ty, HasParameter n params ty) =>
Expression grp lat with db params from ty
forall (ty :: NullType) (lat :: FromType) (with :: FromType)
       (db :: SchemasType) (params :: [NullType]) (from :: FromType)
       (grp :: Grouping).
(NullTyped db ty, HasParameter 1 params ty) =>
Expression grp lat with db params from ty
param @1) `as` IsLabel "name" (Alias "name")
Alias "name"
#name Aliased
  (Optional
     (Expression
        'Ungrouped
        '[]
        '[]
        '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
        '[ 'NotNull 'PGtext]
        Any))
  ("name" ::: '( 'NoDef, 'NotNull 'PGtext))
-> NP
     (Aliased
        (Optional
           (Expression
              'Ungrouped
              '[]
              '[]
              '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
              '[ 'NotNull 'PGtext]
              Any)))
     '["executed_at" ::: '( 'Def, 'NotNull 'PGtimestamptz)]
-> NP
     (Aliased
        (Optional
           (Expression
              'Ungrouped
              '[]
              '[]
              '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
              '[ 'NotNull 'PGtext]
              Any)))
     '["name" ::: '( 'NoDef, 'NotNull 'PGtext),
       "executed_at" ::: '( 'Def, 'NotNull 'PGtimestamptz)]
forall k (a :: k -> *) (x :: k) (xs :: [k]).
a x -> NP a xs -> NP a (x : xs)
:* Optional
  (Expression
     'Ungrouped
     '[]
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     Any)
  '( 'Def, 'NotNull 'PGtimestamptz)
forall k (expr :: k -> *) (ty :: k). Optional expr ('Def :=> ty)
Default `as` IsLabel "executed_at" (Alias "executed_at")
Alias "executed_at"
#executed_at)

-- | Deletes a `Migration` from the `MigrationsTable`, returning
-- the time at which it was inserted.
deleteMigration :: Statement MigrationsSchemas Text ()
deleteMigration :: Statement MigrationsSchemas Text ()
deleteMigration = EncodeParams
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '[ 'NotNull 'PGtext]
  Text
-> DecodeRow '[] ()
-> Manipulation
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '[]
-> Statement
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     Text
     ()
forall (db :: SchemasType) (params :: [NullType]) (row :: RowType)
       x y.
(All (OidOfNull db) params, SListI row) =>
EncodeParams db params x
-> DecodeRow row y
-> Manipulation '[] db params row
-> Statement db x y
Manipulation EncodeParams
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '[ 'NotNull 'PGtext]
  Text
forall (db :: SchemasType) x (ty :: NullType).
(ToParam db ty x, ty ~ NullPG x) =>
EncodeParams db '[ty] x
aParam DecodeRow '[] ()
forall (row :: RowType) y (ys :: RecordCode).
GenericRow row y ys =>
DecodeRow row y
genericRow (Manipulation
   '[]
   '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
   '[ 'NotNull 'PGtext]
   '[]
 -> Statement
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      Text
      ())
-> Manipulation
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '[]
-> Statement
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     Text
     ()
forall a b. (a -> b) -> a -> b
$
  Aliased
  (QualifiedAlias "public")
  ("schema_migrations" ::: "schema_migrations")
-> Condition
     'Ungrouped
     '[]
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '["schema_migrations" ::: TableToRow MigrationsTable]
-> Manipulation
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '[]
forall (sch :: Symbol) (db :: SchemasType) (schema :: SchemaType)
       (tab0 :: Symbol) (table :: TableType) (tab :: Symbol)
       (with :: FromType) (params :: [NullType]).
(Has sch db schema, Has tab0 schema ('Table table)) =>
Aliased (QualifiedAlias sch) (tab ::: tab0)
-> Condition
     'Ungrouped '[] with db params '[tab ::: TableToRow table]
-> Manipulation with db params '[]
deleteFrom_ IsLabel
  "schema_migrations"
  (Aliased
     (QualifiedAlias "public")
     ("schema_migrations" ::: "schema_migrations"))
Aliased
  (QualifiedAlias "public")
  ("schema_migrations" ::: "schema_migrations")
#schema_migrations (IsLabel
  "name"
  (Expression
     'Ungrouped
     '[]
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '["schema_migrations"
       ::: '["name" ::: 'NotNull 'PGtext,
             "executed_at" ::: 'NotNull 'PGtimestamptz]]
     ('NotNull 'PGtext))
Expression
  'Ungrouped
  '[]
  '[]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '[ 'NotNull 'PGtext]
  '["schema_migrations"
    ::: '["name" ::: 'NotNull 'PGtext,
          "executed_at" ::: 'NotNull 'PGtimestamptz]]
  ('NotNull 'PGtext)
#name Expression
  'Ungrouped
  '[]
  '[]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '[ 'NotNull 'PGtext]
  '["schema_migrations"
    ::: '["name" ::: 'NotNull 'PGtext,
          "executed_at" ::: 'NotNull 'PGtimestamptz]]
  ('NotNull 'PGtext)
-> Expression
     'Ungrouped
     '[]
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '["schema_migrations"
       ::: '["name" ::: 'NotNull 'PGtext,
             "executed_at" ::: 'NotNull 'PGtimestamptz]]
     ('NotNull 'PGtext)
-> Expression
     'Ungrouped
     '[]
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '["schema_migrations"
       ::: '["name" ::: 'NotNull 'PGtext,
             "executed_at" ::: 'NotNull 'PGtimestamptz]]
     ('Null 'PGbool)
forall k (null0 :: k -> NullType) (ty :: k)
       (null1 :: k -> NullType).
Operator (null0 ty) (null1 ty) ('Null 'PGbool)
.== forall (n :: Nat) (ty :: NullType) (lat :: FromType)
       (with :: FromType) (db :: SchemasType) (params :: [NullType])
       (from :: FromType) (grp :: Grouping).
(NullTyped db ty, HasParameter n params ty) =>
Expression grp lat with db params from ty
forall (ty :: NullType) (lat :: FromType) (with :: FromType)
       (db :: SchemasType) (params :: [NullType]) (from :: FromType)
       (grp :: Grouping).
(NullTyped db ty, HasParameter 1 params ty) =>
Expression grp lat with db params from ty
param @1)

-- | Selects a `Migration` from the `MigrationsTable`, returning
-- the time at which it was inserted.
selectMigration :: Statement MigrationsSchemas Text UTCTime
selectMigration :: Statement MigrationsSchemas Text UTCTime
selectMigration = EncodeParams
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '[ 'NotNull 'PGtext]
  Text
-> DecodeRow '["executed_at" ::: 'NotNull 'PGtimestamptz] UTCTime
-> Query
     '[]
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '["executed_at" ::: 'NotNull 'PGtimestamptz]
-> Statement
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     Text
     UTCTime
forall (db :: SchemasType) (params :: [NullType]) (row :: RowType)
       x y.
(All (OidOfNull db) params, SListI row) =>
EncodeParams db params x
-> DecodeRow row y
-> Query '[] '[] db params row
-> Statement db x y
Query EncodeParams
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '[ 'NotNull 'PGtext]
  Text
forall (db :: SchemasType) x (ty :: NullType).
(ToParam db ty x, ty ~ NullPG x) =>
EncodeParams db '[ty] x
aParam IsLabel
  "executed_at"
  (DecodeRow '["executed_at" ::: 'NotNull 'PGtimestamptz] UTCTime)
DecodeRow '["executed_at" ::: 'NotNull 'PGtimestamptz] UTCTime
#executed_at (Query
   '[]
   '[]
   '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
   '[ 'NotNull 'PGtext]
   '["executed_at" ::: 'NotNull 'PGtimestamptz]
 -> Statement
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      Text
      UTCTime)
-> Query
     '[]
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '["executed_at" ::: 'NotNull 'PGtimestamptz]
-> Statement
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     Text
     UTCTime
forall a b. (a -> b) -> a -> b
$
  NP
  (Aliased
     (Expression
        'Ungrouped
        '[]
        '[]
        '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
        '[ 'NotNull 'PGtext]
        '["schema_migrations"
          ::: '["name" ::: 'NotNull 'PGtext,
                "executed_at" ::: 'NotNull 'PGtimestamptz]]))
  '["executed_at" ::: 'NotNull 'PGtimestamptz]
-> TableExpression
     'Ungrouped
     '[]
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '["schema_migrations"
       ::: '["name" ::: 'NotNull 'PGtext,
             "executed_at" ::: 'NotNull 'PGtimestamptz]]
-> Query
     '[]
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '["executed_at" ::: 'NotNull 'PGtimestamptz]
forall (row :: RowType) (x :: (Symbol, NullType)) (xs :: RowType)
       (grp :: Grouping) (lat :: FromType) (with :: FromType)
       (db :: SchemasType) (params :: [NullType]) (from :: FromType).
(SListI row, row ~ (x : xs)) =>
NP (Aliased (Expression grp lat with db params from)) row
-> TableExpression grp lat with db params from
-> Query lat with db params row
select_ IsLabel
  "executed_at"
  (NP
     (Aliased
        (Expression
           'Ungrouped
           '[]
           '[]
           '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
           '[ 'NotNull 'PGtext]
           '["schema_migrations"
             ::: '["name" ::: 'NotNull 'PGtext,
                   "executed_at" ::: 'NotNull 'PGtimestamptz]]))
     '["executed_at" ::: 'NotNull 'PGtimestamptz])
NP
  (Aliased
     (Expression
        'Ungrouped
        '[]
        '[]
        '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
        '[ 'NotNull 'PGtext]
        '["schema_migrations"
          ::: '["name" ::: 'NotNull 'PGtext,
                "executed_at" ::: 'NotNull 'PGtimestamptz]]))
  '["executed_at" ::: 'NotNull 'PGtimestamptz]
#executed_at
    (TableExpression
   'Ungrouped
   '[]
   '[]
   '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
   '[ 'NotNull 'PGtext]
   '["schema_migrations"
     ::: '["name" ::: 'NotNull 'PGtext,
           "executed_at" ::: 'NotNull 'PGtimestamptz]]
 -> Query
      '[]
      '[]
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      '[ 'NotNull 'PGtext]
      '["executed_at" ::: 'NotNull 'PGtimestamptz])
-> TableExpression
     'Ungrouped
     '[]
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '["schema_migrations"
       ::: '["name" ::: 'NotNull 'PGtext,
             "executed_at" ::: 'NotNull 'PGtimestamptz]]
-> Query
     '[]
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '["executed_at" ::: 'NotNull 'PGtimestamptz]
forall a b. (a -> b) -> a -> b
$ FromClause
  '[]
  '[]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '[ 'NotNull 'PGtext]
  '["schema_migrations"
    ::: '["name" ::: 'NotNull 'PGtext,
          "executed_at" ::: 'NotNull 'PGtimestamptz]]
-> TableExpression
     'Ungrouped
     '[]
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '["schema_migrations"
       ::: '["name" ::: 'NotNull 'PGtext,
             "executed_at" ::: 'NotNull 'PGtimestamptz]]
forall (lat :: FromType) (with :: FromType) (db :: SchemasType)
       (params :: [NullType]) (from :: FromType).
FromClause lat with db params from
-> TableExpression 'Ungrouped lat with db params from
from (Aliased
  (QualifiedAlias "public")
  ("schema_migrations" ::: "schema_migrations")
-> FromClause
     '[]
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '["schema_migrations" ::: TableToRow MigrationsTable]
forall (sch :: Symbol) (db :: SchemasType) (schema :: SchemaType)
       (tab :: Symbol) (table :: TableType) (alias :: Symbol)
       (lat :: FromType) (with :: FromType) (params :: [NullType]).
(Has sch db schema, Has tab schema ('Table table)) =>
Aliased (QualifiedAlias sch) (alias ::: tab)
-> FromClause lat with db params '[alias ::: TableToRow table]
table (IsLabel
  "schema_migrations"
  (Aliased
     (QualifiedAlias "public")
     ("schema_migrations" ::: "schema_migrations"))
Aliased
  (QualifiedAlias "public")
  ("schema_migrations" ::: "schema_migrations")
#schema_migrations))
    TableExpression
  'Ungrouped
  '[]
  '[]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '[ 'NotNull 'PGtext]
  '["schema_migrations"
    ::: '["name" ::: 'NotNull 'PGtext,
          "executed_at" ::: 'NotNull 'PGtimestamptz]]
-> (TableExpression
      'Ungrouped
      '[]
      '[]
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      '[ 'NotNull 'PGtext]
      '["schema_migrations"
        ::: '["name" ::: 'NotNull 'PGtext,
              "executed_at" ::: 'NotNull 'PGtimestamptz]]
    -> TableExpression
         'Ungrouped
         '[]
         '[]
         '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
         '[ 'NotNull 'PGtext]
         '["schema_migrations"
           ::: '["name" ::: 'NotNull 'PGtext,
                 "executed_at" ::: 'NotNull 'PGtimestamptz]])
-> TableExpression
     'Ungrouped
     '[]
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '["schema_migrations"
       ::: '["name" ::: 'NotNull 'PGtext,
             "executed_at" ::: 'NotNull 'PGtimestamptz]]
forall a b. a -> (a -> b) -> b
& Expression
  'Ungrouped
  '[]
  '[]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '[ 'NotNull 'PGtext]
  '["schema_migrations"
    ::: '["name" ::: 'NotNull 'PGtext,
          "executed_at" ::: 'NotNull 'PGtimestamptz]]
  ('Null 'PGbool)
-> TableExpression
     'Ungrouped
     '[]
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '["schema_migrations"
       ::: '["name" ::: 'NotNull 'PGtext,
             "executed_at" ::: 'NotNull 'PGtimestamptz]]
-> TableExpression
     'Ungrouped
     '[]
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '["schema_migrations"
       ::: '["name" ::: 'NotNull 'PGtext,
             "executed_at" ::: 'NotNull 'PGtimestamptz]]
forall (lat :: FromType) (with :: FromType) (db :: SchemasType)
       (params :: [NullType]) (from :: FromType) (grp :: Grouping).
Condition 'Ungrouped lat with db params from
-> TableExpression grp lat with db params from
-> TableExpression grp lat with db params from
where_ (IsLabel
  "name"
  (Expression
     'Ungrouped
     '[]
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '["schema_migrations"
       ::: '["name" ::: 'NotNull 'PGtext,
             "executed_at" ::: 'NotNull 'PGtimestamptz]]
     ('NotNull 'PGtext))
Expression
  'Ungrouped
  '[]
  '[]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '[ 'NotNull 'PGtext]
  '["schema_migrations"
    ::: '["name" ::: 'NotNull 'PGtext,
          "executed_at" ::: 'NotNull 'PGtimestamptz]]
  ('NotNull 'PGtext)
#name Expression
  'Ungrouped
  '[]
  '[]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '[ 'NotNull 'PGtext]
  '["schema_migrations"
    ::: '["name" ::: 'NotNull 'PGtext,
          "executed_at" ::: 'NotNull 'PGtimestamptz]]
  ('NotNull 'PGtext)
-> Expression
     'Ungrouped
     '[]
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '["schema_migrations"
       ::: '["name" ::: 'NotNull 'PGtext,
             "executed_at" ::: 'NotNull 'PGtimestamptz]]
     ('NotNull 'PGtext)
-> Expression
     'Ungrouped
     '[]
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[ 'NotNull 'PGtext]
     '["schema_migrations"
       ::: '["name" ::: 'NotNull 'PGtext,
             "executed_at" ::: 'NotNull 'PGtimestamptz]]
     ('Null 'PGbool)
forall k (null0 :: k -> NullType) (ty :: k)
       (null1 :: k -> NullType).
Operator (null0 ty) (null1 ty) ('Null 'PGbool)
.== forall (n :: Nat) (ty :: NullType) (lat :: FromType)
       (with :: FromType) (db :: SchemasType) (params :: [NullType])
       (from :: FromType) (grp :: Grouping).
(NullTyped db ty, HasParameter n params ty) =>
Expression grp lat with db params from ty
forall (ty :: NullType) (lat :: FromType) (with :: FromType)
       (db :: SchemasType) (params :: [NullType]) (from :: FromType)
       (grp :: Grouping).
(NullTyped db ty, HasParameter 1 params ty) =>
Expression grp lat with db params from ty
param @1)

selectMigrations :: Statement MigrationsSchemas () MigrationRow
selectMigrations :: Statement MigrationsSchemas () MigrationRow
selectMigrations = Query
  '[]
  '[]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '[]
  '["name" ::: 'NotNull 'PGtext,
    "executed_at" ::: 'NotNull 'PGtimestamptz]
-> Statement
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     ()
     MigrationRow
forall (db :: SchemasType) (params :: [NullType]) x (xs :: [*])
       (row :: RowType) y (ys :: RecordCode).
(GenericParams db params x xs, GenericRow row y ys) =>
Query '[] '[] db params row -> Statement db x y
query (Query
   '[]
   '[]
   '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
   '[]
   '["name" ::: 'NotNull 'PGtext,
     "executed_at" ::: 'NotNull 'PGtimestamptz]
 -> Statement
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      ()
      MigrationRow)
-> Query
     '[]
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[]
     '["name" ::: 'NotNull 'PGtext,
       "executed_at" ::: 'NotNull 'PGtimestamptz]
-> Statement
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     ()
     MigrationRow
forall a b. (a -> b) -> a -> b
$ Selection
  'Ungrouped
  '[]
  '[]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '[]
  '["schema_migrations"
    ::: '["name" ::: 'NotNull 'PGtext,
          "executed_at" ::: 'NotNull 'PGtimestamptz]]
  '["name" ::: 'NotNull 'PGtext,
    "executed_at" ::: 'NotNull 'PGtimestamptz]
-> TableExpression
     'Ungrouped
     '[]
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[]
     '["schema_migrations"
       ::: '["name" ::: 'NotNull 'PGtext,
             "executed_at" ::: 'NotNull 'PGtimestamptz]]
-> Query
     '[]
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[]
     '["name" ::: 'NotNull 'PGtext,
       "executed_at" ::: 'NotNull 'PGtimestamptz]
forall (row :: RowType) (x :: (Symbol, NullType)) (xs :: RowType)
       (grp :: Grouping) (lat :: FromType) (with :: FromType)
       (db :: SchemasType) (params :: [NullType]) (from :: FromType).
(SListI row, row ~ (x : xs)) =>
Selection grp lat with db params from row
-> TableExpression grp lat with db params from
-> Query lat with db params row
select Selection
  'Ungrouped
  '[]
  '[]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '[]
  '["schema_migrations"
    ::: '["name" ::: 'NotNull 'PGtext,
          "executed_at" ::: 'NotNull 'PGtimestamptz]]
  '["name" ::: 'NotNull 'PGtext,
    "executed_at" ::: 'NotNull 'PGtimestamptz]
forall (tab :: Symbol) (from :: FromType) (row :: RowType)
       (lat :: FromType) (with :: FromType) (db :: SchemasType)
       (params :: [NullType]).
HasUnique tab from row =>
Selection 'Ungrouped lat with db params from row
Star (FromClause
  '[]
  '[]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '[]
  '["schema_migrations"
    ::: '["name" ::: 'NotNull 'PGtext,
          "executed_at" ::: 'NotNull 'PGtimestamptz]]
-> TableExpression
     'Ungrouped
     '[]
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[]
     '["schema_migrations"
       ::: '["name" ::: 'NotNull 'PGtext,
             "executed_at" ::: 'NotNull 'PGtimestamptz]]
forall (lat :: FromType) (with :: FromType) (db :: SchemasType)
       (params :: [NullType]) (from :: FromType).
FromClause lat with db params from
-> TableExpression 'Ungrouped lat with db params from
from (Aliased
  (QualifiedAlias "public")
  ("schema_migrations" ::: "schema_migrations")
-> FromClause
     '[]
     '[]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '[]
     '["schema_migrations" ::: TableToRow MigrationsTable]
forall (sch :: Symbol) (db :: SchemasType) (schema :: SchemaType)
       (tab :: Symbol) (table :: TableType) (alias :: Symbol)
       (lat :: FromType) (with :: FromType) (params :: [NullType]).
(Has sch db schema, Has tab schema ('Table table)) =>
Aliased (QualifiedAlias sch) (alias ::: tab)
-> FromClause lat with db params '[alias ::: TableToRow table]
table IsLabel
  "schema_migrations"
  (Aliased
     (QualifiedAlias "public")
     ("schema_migrations" ::: "schema_migrations"))
Aliased
  (QualifiedAlias "public")
  ("schema_migrations" ::: "schema_migrations")
#schema_migrations))

{- | `mainMigrate` creates a simple executable
from a connection string and a `Path` of `Migration`s. -}
mainMigrate
  :: Migratory p (Indexed PQ IO ())
  => ByteString
  -- ^ connection string
  -> Path (Migration p) db0 db1
  -- ^ migrations
  -> IO ()
mainMigrate :: ByteString -> Path (Migration p) db0 db1 -> IO ()
mainMigrate ByteString
connectTo Path (Migration p) db0 db1
migrations = do
  [String]
command <- IO [String]
getArgs
  [String] -> IO ()
performCommand [String]
command

  where

    performCommand :: [String] -> IO ()
    performCommand :: [String] -> IO ()
performCommand = \case
      [String
"status"] -> ByteString -> PQ Any Any IO () -> IO ()
forall (db0 :: SchemasType) (db1 :: SchemasType) (io :: * -> *) x.
(MonadIO io, MonadMask io) =>
ByteString -> PQ db0 db1 io x -> io x
withConnection ByteString
connectTo (PQ Any Any IO () -> IO ()) -> PQ Any Any IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
        PQ Any Any IO ()
forall (schema :: SchemasType). PQ schema schema IO ()
suppressNotices PQ Any Any IO () -> PQ Any Any IO () -> PQ Any Any IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> PQ Any Any IO ()
forall (schema :: SchemasType). PQ schema schema IO ()
migrateStatus
      [String
"migrate"] -> ByteString -> PQ db0 db1 IO () -> IO ()
forall (db0 :: SchemasType) (db1 :: SchemasType) (io :: * -> *) x.
(MonadIO io, MonadMask io) =>
ByteString -> PQ db0 db1 io x -> io x
withConnection ByteString
connectTo (PQ db0 db1 IO () -> IO ()) -> PQ db0 db1 IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
        PQ db0 db0 IO ()
forall (schema :: SchemasType). PQ schema schema IO ()
suppressNotices
        PQ db0 db0 IO ()
-> (PQ db0 db0 IO () -> PQ db0 db1 IO ()) -> PQ db0 db1 IO ()
forall a b. a -> (a -> b) -> b
& PQ db0 db1 IO () -> PQ db0 db0 IO () -> PQ db0 db1 IO ()
forall k (t :: k -> k -> (* -> *) -> * -> *) (m :: * -> *) (j :: k)
       (k :: k) y (i :: k) x.
(IndexedMonadTrans t, Monad m) =>
t j k m y -> t i j m x -> t i k m y
pqThen (Indexed PQ IO () db0 db1 -> PQ db0 db1 IO ()
forall k k k k (t :: k -> k -> k -> k -> *) (m :: k) (r :: k)
       (i :: k) (j :: k).
Indexed t m r i j -> t i j m r
runIndexed (Path (Migration p) db0 db1 -> Indexed PQ IO () db0 db1
forall k (def :: k -> k -> *) (run :: k -> k -> *) (db0 :: k)
       (db1 :: k).
Migratory def run =>
Path (Migration def) db0 db1 -> run db0 db1
runMigrations Path (Migration p) db0 db1
migrations))
        PQ db0 db1 IO ()
-> (PQ db0 db1 IO () -> PQ db0 db1 IO ()) -> PQ db0 db1 IO ()
forall a b. a -> (a -> b) -> b
& PQ db1 db1 IO () -> PQ db0 db1 IO () -> PQ db0 db1 IO ()
forall k (t :: k -> k -> (* -> *) -> * -> *) (m :: * -> *) (j :: k)
       (k :: k) y (i :: k) x.
(IndexedMonadTrans t, Monad m) =>
t j k m y -> t i j m x -> t i k m y
pqThen PQ db1 db1 IO ()
forall (schema :: SchemasType). PQ schema schema IO ()
migrateStatus
      [String]
args -> [String] -> IO ()
displayUsage [String]
args

    migrateStatus :: PQ schema schema IO ()
    migrateStatus :: PQ schema schema IO ()
migrateStatus = PQ Any Any IO () -> PQ schema schema IO ()
forall (m :: * -> *) (db0 :: SchemasType) (db1 :: SchemasType) x
       (db0' :: SchemasType) (db1' :: SchemasType).
Functor m =>
PQ db0 db1 m x -> PQ db0' db1' m x
unsafePQ (PQ Any Any IO () -> PQ schema schema IO ())
-> PQ Any Any IO () -> PQ schema schema IO ()
forall a b. (a -> b) -> a -> b
$ do
      [Text]
runNames <- PQ Any Any IO [Text]
forall (db0 :: SchemasType). PQ db0 db0 IO [Text]
getRunMigrationNames
      let names :: [Text]
names = (forall (x1 :: SchemasType) (y1 :: SchemasType).
 Migration p x1 y1 -> Text)
-> Path (Migration p) db0 db1 -> [Text]
forall k (c :: (k -> k -> *) -> k -> k -> *) (p :: k -> k -> *) a
       (x :: k) (y :: k).
QFoldable c =>
(forall (x1 :: k) (y1 :: k). p x1 y1 -> a) -> c p x y -> [a]
qtoList forall (x1 :: SchemasType) (y1 :: SchemasType).
Migration p x1 y1 -> Text
forall k k (def :: k -> k -> *) (db0 :: k) (db1 :: k).
Migration def db0 db1 -> Text
migrationName Path (Migration p) db0 db1
migrations
          unrunNames :: [Text]
unrunNames = [Text]
names [Text] -> [Text] -> [Text]
forall a. Eq a => [a] -> [a] -> [a]
\\ [Text]
runNames
      IO () -> PQ Any Any IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> PQ Any Any IO ()) -> IO () -> PQ Any Any IO ()
forall a b. (a -> b) -> a -> b
$ [Text] -> IO ()
displayRunned [Text]
runNames IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Text] -> IO ()
displayUnrunned [Text]
unrunNames

    suppressNotices :: PQ schema schema IO ()
    suppressNotices :: PQ schema schema IO ()
suppressNotices = Manipulation '[] schema '[] '[] -> PQ schema schema IO ()
forall (db :: SchemasType) (pq :: * -> *).
MonadPQ db pq =>
Manipulation '[] db '[] '[] -> pq ()
manipulate_ (Manipulation '[] schema '[] '[] -> PQ schema schema IO ())
-> Manipulation '[] schema '[] '[] -> PQ schema schema IO ()
forall a b. (a -> b) -> a -> b
$
      ByteString -> Manipulation '[] schema '[] '[]
forall (with :: FromType) (db :: SchemasType)
       (params :: [NullType]) (columns :: RowType).
ByteString -> Manipulation with db params columns
UnsafeManipulation ByteString
"SET client_min_messages TO WARNING;"

    displayUsage :: [String] -> IO ()
    displayUsage :: [String] -> IO ()
displayUsage [String]
args = do
      String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ String
"Invalid command: \"" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> [String] -> String
unwords [String]
args String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
"\". Use:"
      String -> IO ()
putStrLn String
"migrate    to run all available migrations"
      String -> IO ()
putStrLn String
"rollback   to rollback all available migrations"

{- | `mainMigrateIso` creates a simple executable
from a connection string and a `Path` of `Migration` `IsoQ`s. -}
mainMigrateIso
  :: Migratory (IsoQ def) (IsoQ (Indexed PQ IO ()))
  => ByteString
  -- ^ connection string
  -> Path (Migration (IsoQ def)) db0 db1
  -- ^ migrations
  -> IO ()
mainMigrateIso :: ByteString -> Path (Migration (IsoQ def)) db0 db1 -> IO ()
mainMigrateIso ByteString
connectTo Path (Migration (IsoQ def)) db0 db1
migrations = [String] -> IO ()
performCommand ([String] -> IO ()) -> IO [String] -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< IO [String]
getArgs

  where

    performCommand :: [String] -> IO ()
    performCommand :: [String] -> IO ()
performCommand = \case
      [String
"status"] -> ByteString -> PQ Any Any IO () -> IO ()
forall (db0 :: SchemasType) (db1 :: SchemasType) (io :: * -> *) x.
(MonadIO io, MonadMask io) =>
ByteString -> PQ db0 db1 io x -> io x
withConnection ByteString
connectTo (PQ Any Any IO () -> IO ()) -> PQ Any Any IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
        PQ Any Any IO ()
forall (schema :: SchemasType). PQ schema schema IO ()
suppressNotices PQ Any Any IO () -> PQ Any Any IO () -> PQ Any Any IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> PQ Any Any IO ()
forall (schema :: SchemasType). PQ schema schema IO ()
migrateStatus
      [String
"migrate"] -> ByteString -> PQ db0 db1 IO () -> IO ()
forall (db0 :: SchemasType) (db1 :: SchemasType) (io :: * -> *) x.
(MonadIO io, MonadMask io) =>
ByteString -> PQ db0 db1 io x -> io x
withConnection ByteString
connectTo (PQ db0 db1 IO () -> IO ()) -> PQ db0 db1 IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
        PQ db0 db0 IO ()
forall (schema :: SchemasType). PQ schema schema IO ()
suppressNotices
        PQ db0 db0 IO ()
-> (PQ db0 db0 IO () -> PQ db0 db1 IO ()) -> PQ db0 db1 IO ()
forall a b. a -> (a -> b) -> b
& PQ db0 db1 IO () -> PQ db0 db0 IO () -> PQ db0 db1 IO ()
forall k (t :: k -> k -> (* -> *) -> * -> *) (m :: * -> *) (j :: k)
       (k :: k) y (i :: k) x.
(IndexedMonadTrans t, Monad m) =>
t j k m y -> t i j m x -> t i k m y
pqThen (Path (Migration (IsoQ def)) db0 db1 -> PQ db0 db1 IO ()
forall (def :: SchemasType -> SchemasType -> *)
       (db0 :: SchemasType) (db1 :: SchemasType).
Migratory def (IsoQ (Indexed PQ IO ())) =>
Path (Migration def) db0 db1 -> PQ db0 db1 IO ()
migrateUp Path (Migration (IsoQ def)) db0 db1
migrations)
        PQ db0 db1 IO ()
-> (PQ db0 db1 IO () -> PQ db0 db1 IO ()) -> PQ db0 db1 IO ()
forall a b. a -> (a -> b) -> b
& PQ db1 db1 IO () -> PQ db0 db1 IO () -> PQ db0 db1 IO ()
forall k (t :: k -> k -> (* -> *) -> * -> *) (m :: * -> *) (j :: k)
       (k :: k) y (i :: k) x.
(IndexedMonadTrans t, Monad m) =>
t j k m y -> t i j m x -> t i k m y
pqThen PQ db1 db1 IO ()
forall (schema :: SchemasType). PQ schema schema IO ()
migrateStatus
      [String
"rollback"] -> ByteString -> PQ db1 db0 IO () -> IO ()
forall (db0 :: SchemasType) (db1 :: SchemasType) (io :: * -> *) x.
(MonadIO io, MonadMask io) =>
ByteString -> PQ db0 db1 io x -> io x
withConnection ByteString
connectTo (PQ db1 db0 IO () -> IO ()) -> PQ db1 db0 IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
        PQ db1 db1 IO ()
forall (schema :: SchemasType). PQ schema schema IO ()
suppressNotices
        PQ db1 db1 IO ()
-> (PQ db1 db1 IO () -> PQ db1 db0 IO ()) -> PQ db1 db0 IO ()
forall a b. a -> (a -> b) -> b
& PQ db1 db0 IO () -> PQ db1 db1 IO () -> PQ db1 db0 IO ()
forall k (t :: k -> k -> (* -> *) -> * -> *) (m :: * -> *) (j :: k)
       (k :: k) y (i :: k) x.
(IndexedMonadTrans t, Monad m) =>
t j k m y -> t i j m x -> t i k m y
pqThen (Path (Migration (IsoQ def)) db0 db1 -> PQ db1 db0 IO ()
forall (def :: SchemasType -> SchemasType -> *)
       (db0 :: SchemasType) (db1 :: SchemasType).
Migratory def (IsoQ (Indexed PQ IO ())) =>
Path (Migration def) db0 db1 -> PQ db1 db0 IO ()
migrateDown Path (Migration (IsoQ def)) db0 db1
migrations)
        PQ db1 db0 IO ()
-> (PQ db1 db0 IO () -> PQ db1 db0 IO ()) -> PQ db1 db0 IO ()
forall a b. a -> (a -> b) -> b
& PQ db0 db0 IO () -> PQ db1 db0 IO () -> PQ db1 db0 IO ()
forall k (t :: k -> k -> (* -> *) -> * -> *) (m :: * -> *) (j :: k)
       (k :: k) y (i :: k) x.
(IndexedMonadTrans t, Monad m) =>
t j k m y -> t i j m x -> t i k m y
pqThen PQ db0 db0 IO ()
forall (schema :: SchemasType). PQ schema schema IO ()
migrateStatus
      [String]
args -> [String] -> IO ()
displayUsage [String]
args

    migrateStatus :: PQ schema schema IO ()
    migrateStatus :: PQ schema schema IO ()
migrateStatus = PQ Any Any IO () -> PQ schema schema IO ()
forall (m :: * -> *) (db0 :: SchemasType) (db1 :: SchemasType) x
       (db0' :: SchemasType) (db1' :: SchemasType).
Functor m =>
PQ db0 db1 m x -> PQ db0' db1' m x
unsafePQ (PQ Any Any IO () -> PQ schema schema IO ())
-> PQ Any Any IO () -> PQ schema schema IO ()
forall a b. (a -> b) -> a -> b
$ do
      [Text]
runNames <- PQ Any Any IO [Text]
forall (db0 :: SchemasType). PQ db0 db0 IO [Text]
getRunMigrationNames
      let names :: [Text]
names = (forall (x1 :: SchemasType) (y1 :: SchemasType).
 Migration (IsoQ def) x1 y1 -> Text)
-> Path (Migration (IsoQ def)) db0 db1 -> [Text]
forall k (c :: (k -> k -> *) -> k -> k -> *) (p :: k -> k -> *) a
       (x :: k) (y :: k).
QFoldable c =>
(forall (x1 :: k) (y1 :: k). p x1 y1 -> a) -> c p x y -> [a]
qtoList forall (x1 :: SchemasType) (y1 :: SchemasType).
Migration (IsoQ def) x1 y1 -> Text
forall k k (def :: k -> k -> *) (db0 :: k) (db1 :: k).
Migration def db0 db1 -> Text
migrationName Path (Migration (IsoQ def)) db0 db1
migrations
          unrunNames :: [Text]
unrunNames = [Text]
names [Text] -> [Text] -> [Text]
forall a. Eq a => [a] -> [a] -> [a]
\\ [Text]
runNames
      IO () -> PQ Any Any IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> PQ Any Any IO ()) -> IO () -> PQ Any Any IO ()
forall a b. (a -> b) -> a -> b
$ [Text] -> IO ()
displayRunned [Text]
runNames IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Text] -> IO ()
displayUnrunned [Text]
unrunNames

    suppressNotices :: PQ schema schema IO ()
    suppressNotices :: PQ schema schema IO ()
suppressNotices = Manipulation '[] schema '[] '[] -> PQ schema schema IO ()
forall (db :: SchemasType) (pq :: * -> *).
MonadPQ db pq =>
Manipulation '[] db '[] '[] -> pq ()
manipulate_ (Manipulation '[] schema '[] '[] -> PQ schema schema IO ())
-> Manipulation '[] schema '[] '[] -> PQ schema schema IO ()
forall a b. (a -> b) -> a -> b
$
      ByteString -> Manipulation '[] schema '[] '[]
forall (with :: FromType) (db :: SchemasType)
       (params :: [NullType]) (columns :: RowType).
ByteString -> Manipulation with db params columns
UnsafeManipulation ByteString
"SET client_min_messages TO WARNING;"

    displayUsage :: [String] -> IO ()
    displayUsage :: [String] -> IO ()
displayUsage [String]
args = do
      String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ String
"Invalid command: \"" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> [String] -> String
unwords [String]
args String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
"\". Use:"
      String -> IO ()
putStrLn String
"migrate    to run all available migrations"
      String -> IO ()
putStrLn String
"rollback   to rollback all available migrations"
      String -> IO ()
putStrLn String
"status     to display migrations run and migrations left to run"

getRunMigrationNames :: PQ db0 db0 IO [Text]
getRunMigrationNames :: PQ db0 db0 IO [Text]
getRunMigrationNames =
  (MigrationRow -> Text) -> [MigrationRow] -> [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap MigrationRow -> Text
name ([MigrationRow] -> [Text])
-> PQ db0 db0 IO [MigrationRow] -> PQ db0 db0 IO [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    (PQ
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  IO
  (Result MigrationRow)
-> PQ db0 db0 IO (Result MigrationRow)
forall (m :: * -> *) (db0 :: SchemasType) (db1 :: SchemasType) x
       (db0' :: SchemasType) (db1' :: SchemasType).
Functor m =>
PQ db0 db1 m x -> PQ db0' db1' m x
unsafePQ (Definition
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     IO
     ()
forall (pq :: SchemasType -> SchemasType -> (* -> *) -> * -> *)
       (io :: * -> *) (db0 :: SchemasType) (db1 :: SchemasType).
(IndexedMonadTransPQ pq, MonadIO io) =>
Definition db0 db1 -> pq db0 db1 io ()
define Definition
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
Definition MigrationsSchemas MigrationsSchemas
createMigrations
    PQ
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  IO
  ()
-> (PQ
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
      IO
      ()
    -> PQ
         '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
         '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
         IO
         (Result MigrationRow))
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     IO
     (Result MigrationRow)
forall a b. a -> (a -> b) -> b
& PQ
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  IO
  (Result MigrationRow)
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     IO
     ()
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     IO
     (Result MigrationRow)
forall k (t :: k -> k -> (* -> *) -> * -> *) (m :: * -> *) (j :: k)
       (k :: k) y (i :: k) x.
(IndexedMonadTrans t, Monad m) =>
t j k m y -> t i j m x -> t i k m y
pqThen (Statement
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  ()
  MigrationRow
-> PQ
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
     IO
     (Result MigrationRow)
forall (db :: SchemasType) (pq :: * -> *) y.
MonadPQ db pq =>
Statement db () y -> pq (Result y)
execute Statement
  '["public" ::: '["schema_migrations" ::: 'Table MigrationsTable]]
  ()
  MigrationRow
Statement MigrationsSchemas () MigrationRow
selectMigrations)) PQ db0 db0 IO (Result MigrationRow)
-> (Result MigrationRow -> PQ db0 db0 IO [MigrationRow])
-> PQ db0 db0 IO [MigrationRow]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Result MigrationRow -> PQ db0 db0 IO [MigrationRow]
forall (m :: * -> *) y. MonadResult m => Result y -> m [y]
getRows)

displayListOfNames :: [Text] -> IO ()
displayListOfNames :: [Text] -> IO ()
displayListOfNames [] = Text -> IO ()
Text.putStrLn Text
"  None"
displayListOfNames [Text]
xs =
  let singleName :: Text -> IO ()
singleName Text
n = Text -> IO ()
Text.putStrLn (Text -> IO ()) -> Text -> IO ()
forall a b. (a -> b) -> a -> b
$ Text
"  - " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
n
  in (Text -> IO ()) -> [Text] -> IO ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ Text -> IO ()
singleName [Text]
xs

displayUnrunned :: [Text] -> IO ()
displayUnrunned :: [Text] -> IO ()
displayUnrunned [Text]
unrunned =
  Text -> IO ()
Text.putStrLn Text
"Migrations left to run:"
  IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Text] -> IO ()
displayListOfNames [Text]
unrunned

displayRunned :: [Text] -> IO ()
displayRunned :: [Text] -> IO ()
displayRunned [Text]
runned =
  Text -> IO ()
Text.putStrLn Text
"Migrations already run:"
  IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Text] -> IO ()
displayListOfNames [Text]
runned