Created
July 27, 2015 22:05
-
-
Save psibi/5ac89accf2e9c76f6d71 to your computer and use it in GitHub Desktop.
Mock Migration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE EmptyDataDecls #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE QuasiQuotes #-} | |
{-# LANGUAGE TemplateHaskell #-} | |
{-# LANGUAGE TypeFamilies #-} | |
import Control.Monad.IO.Class (liftIO) | |
import Control.Monad.Logger (runStderrLoggingT) | |
import Database.Persist | |
import Database.Persist.Postgresql | |
import Database.Persist.TH | |
import Control.Monad.Trans.Reader (runReaderT) | |
import Data.IORef | |
import qualified Data.Map as Map | |
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase| | |
Person | |
name String | |
age Int Maybe | |
deriving Show | |
BlogPost | |
title String | |
authorId PersonId | |
deriving Show | |
|] | |
main :: IO () | |
main = mockMigration migrateAll | |
--- Output: | |
-- CREATe TABLE "person"("id" SERIAL PRIMARY KEY UNIQUE,"name" VARCHAR NOT NULL,"age" INT8 NULL) | |
-- CREATe TABLE "blog_post"("id" SERIAL PRIMARY KEY UNIQUE,"title" VARCHAR NOT NULL,"author_id" INT8 NOT NULL) | |
-- ALTER TABLE "blog_post" ADD CONSTRAINT "blog_post_author_id_fkey" FOREIGN KEY("author_id") REFERENCES "person"("id") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment