Fix schema

This commit is contained in:
Mats Rauhala 2018-08-03 00:09:43 +03:00
parent 9dc1a7dca2
commit cf8360fd95
3 changed files with 19 additions and 17 deletions

View File

@ -1,5 +1,9 @@
create table users (
email varchar(64) primary key,
username varchar(64),
password varchar(64)
CREATE TABLE public.users (
email text NOT NULL,
username text NOT NULL,
"password" bytea NOT NULL,
CONSTRAINT users_pkey PRIMARY KEY (email)
)
WITH (
OIDS=FALSE
) ;

View File

@ -47,7 +47,7 @@ type API = Get '[HTML] Index
handler :: ServerT API AppM
handler = do
u <- runDB $
u <- runDB $ do
query $ select $ gen users
$logInfo $ "users: " <> (pack . show $ u)
return Index

View File

@ -11,7 +11,6 @@ import Network.Wai.Handler.Warp (run)
import Types
import Configuration
import Dhall (input, auto)
import System.Process (callProcess)
import ClassyPrelude
import Control.Lens (view)
import Data.Generics.Product
@ -29,18 +28,17 @@ defaultMain config = do
let app = App{..}
run 8080 (server app)
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]
-- 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 = do
c <- input auto "./config/config.dhall"
migrate (view (field @"database") c)
defaultMain c