Migrations
This commit is contained in:
parent
7c08c46c16
commit
2e5e64feae
@ -40,6 +40,7 @@ executable ebook-manager
|
|||||||
, bytestring
|
, bytestring
|
||||||
, text
|
, text
|
||||||
, pandoc
|
, pandoc
|
||||||
|
, pandoc-types
|
||||||
, foreign-store
|
, foreign-store
|
||||||
, warp
|
, warp
|
||||||
, wai
|
, wai
|
||||||
@ -48,5 +49,9 @@ executable ebook-manager
|
|||||||
, servant-lucid
|
, servant-lucid
|
||||||
, lens
|
, lens
|
||||||
, generic-lens
|
, generic-lens
|
||||||
|
, resource-pool
|
||||||
|
, selda
|
||||||
|
, selda-postgresql
|
||||||
|
, process
|
||||||
hs-source-dirs: src
|
hs-source-dirs: src
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
5
migrations/V1__Initial_databas.sql
Normal file
5
migrations/V1__Initial_databas.sql
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
create table users (
|
||||||
|
email varchar(64) primary key,
|
||||||
|
username varchar(64),
|
||||||
|
password varchar(64)
|
||||||
|
);
|
21
src/Main.hs
21
src/Main.hs
@ -1,16 +1,35 @@
|
|||||||
{-# Language OverloadedStrings #-}
|
{-# Language OverloadedStrings #-}
|
||||||
|
{-# Language RecordWildCards #-}
|
||||||
|
{-# Language DuplicateRecordFields #-}
|
||||||
|
{-# Language TypeApplications #-}
|
||||||
|
{-# Language DataKinds #-}
|
||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
import Server (server)
|
import Server (server)
|
||||||
import Network.Wai.Handler.Warp (run)
|
import Network.Wai.Handler.Warp (run)
|
||||||
import Types
|
import Types
|
||||||
import Configuration (Config)
|
import Configuration
|
||||||
import Dhall (input, auto)
|
import Dhall (input, auto)
|
||||||
|
import System.Process (callProcess)
|
||||||
|
import ClassyPrelude
|
||||||
|
import Control.Lens (view)
|
||||||
|
import Data.Generics.Product
|
||||||
|
|
||||||
defaultMain :: Config -> IO ()
|
defaultMain :: Config -> IO ()
|
||||||
defaultMain c = run 8080 (server (App c))
|
defaultMain c = run 8080 (server (App c))
|
||||||
|
|
||||||
|
migrate :: Pg -> IO ()
|
||||||
|
migrate Pg{..} = do
|
||||||
|
-- Credentials visible on ps
|
||||||
|
-- XXX: Modify this to write the credentials to a temporary file or something
|
||||||
|
callProcess "flyway" $ fmap unpack [ "migrate"
|
||||||
|
, "-locations=filesystem:migrations/"
|
||||||
|
, "-url=jdbc:postgresql://" <> host <> "/" <> database
|
||||||
|
, "-user=" <> username
|
||||||
|
, "-password=" <> password]
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
c <- input auto "./config/config.dhall"
|
c <- input auto "./config/config.dhall"
|
||||||
|
migrate (view (field @"database") c)
|
||||||
defaultMain c
|
defaultMain c
|
||||||
|
Loading…
Reference in New Issue
Block a user