start slowly

This commit is contained in:
nek0 2020-05-10 07:28:17 +02:00
parent fafa684da4
commit 583316224c
3 changed files with 34 additions and 20 deletions

View file

@ -5,6 +5,8 @@
{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleContexts #-}
module Main where module Main where
import Prelude as P
import Servant import Servant
import Servant.Server.Experimental.Auth import Servant.Server.Experimental.Auth
@ -21,6 +23,8 @@ import qualified Data.CaseInsensitive as CI
import Data.IP import Data.IP
import Database.PostgreSQL.Simple import Database.PostgreSQL.Simple
import Database.PostgreSQL.Simple.Migration
import Database.PostgreSQL.Simple.Util
import Network.Wai import Network.Wai
import Network.Wai.Logger import Network.Wai.Logger
@ -81,17 +85,24 @@ main = do
"password='" <> fromString (T.unpack db_passwd) <> "'" "password='" <> fromString (T.unpack db_passwd) <> "'"
) )
store <- newTVarIO S.empty store <- newTVarIO S.empty
tracker <- newTVarIO M.empty -- tracker <- newTVarIO M.empty
void $ execute_ conn initAvatar migrationsExist <- existsTable conn "schema_migrations"
void $ execute_ conn initUser when (not migrationsExist) $ do
void $ execute_ conn initProduct withTransaction conn $
void $ execute_ conn initToken void $ do
void $ execute_ conn initAuthData runMigration $
void $ execute_ conn initAmount MigrationContext MigrationInitialization True conn
void $ execute_ conn initJournal execute_ conn initAvatar
void $ execute_ conn initRole execute_ conn initUser
void $ execute_ conn initUserToRole execute_ conn initProduct
execute_ conn initToken
execute_ conn initAuthData
execute_ conn initAmount
execute_ conn initJournal
execute_ conn initRole
execute_ conn initUserToRole
runInsertInitialRole runInsertInitialRole
-- TODO: check for Migrations
forkCleanProcess conn store forkCleanProcess conn store
withStdoutLogger $ \ilog -> do withStdoutLogger $ \ilog -> do
let settings = setPort (fromIntegral lport) $ let settings = setPort (fromIntegral lport) $

View file

@ -34,6 +34,7 @@ executable mateamt
, mtl , mtl
, opaleye , opaleye
, postgresql-simple , postgresql-simple
, postgresql-simple-migration
, stm , stm
, network , network
, servant , servant

View file

@ -5,12 +5,13 @@ let
inherit (nixpkgs) pkgs; inherit (nixpkgs) pkgs;
f = { mkDerivation, aeson, base, base16-bytestring f = { mkDerivation, aeson, base, base16-bytestring
, base64-bytestring, bytestring, case-insensitive, containers , base64-bytestring, bytestring, case-insensitive, clock
, HsYAML, http-api-data, http-types, iproute, mtl, network, opaleye , containers, HsYAML, http-api-data, http-types, iproute, mtl
, optparse-applicative, postgresql-simple, product-profunctors , network, opaleye, optparse-applicative, postgresql-simple
, profunctors, pureMD5, random-bytestring, servant, servant-rawm , postgresql-simple-migration, product-profunctors, profunctors
, servant-server, stdenv, stm, text, time, wai, wai-logger , pureMD5, random-bytestring, servant, servant-rawm, servant-server
, wai-middleware-throttle, warp , stdenv, stm, text, time, wai, wai-logger, wai-middleware-throttle
, warp
}: }:
mkDerivation { mkDerivation {
pname = "mateamt"; pname = "mateamt";
@ -25,10 +26,11 @@ let
servant-rawm servant-server stm text time wai wai-logger warp servant-rawm servant-server stm text time wai wai-logger warp
]; ];
executableHaskellDepends = [ executableHaskellDepends = [
base base16-bytestring bytestring case-insensitive containers base base16-bytestring bytestring case-insensitive clock containers
HsYAML iproute mtl network opaleye optparse-applicative HsYAML iproute mtl network opaleye optparse-applicative
postgresql-simple servant servant-server stm text time wai postgresql-simple postgresql-simple-migration servant
wai-logger wai-middleware-throttle warp servant-server stm text time wai wai-logger wai-middleware-throttle
warp
]; ];
description = "A whole new matemat"; description = "A whole new matemat";
license = stdenv.lib.licenses.agpl3; license = stdenv.lib.licenses.agpl3;