{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_HADDOCK not-home #-}
module Arbiter.Core.Gates
( arbiterGatesTable
, arbiterGatesTableName
, createGatesTableSQL
, addGateMetadataColumnSQL
, gateEpochSQL
) where
import Data.Text (Text)
import Data.Text qualified as T
import Arbiter.Core.Job.Schema (SchemaName)
import Arbiter.Core.SqlLiterals (sharedTable)
arbiterGatesTable :: SchemaName -> Text
arbiterGatesTable :: Text -> Text
arbiterGatesTable Text
schemaName = Text -> Text -> Text
sharedTable Text
schemaName Text
arbiterGatesTableName
arbiterGatesTableName :: Text
arbiterGatesTableName :: Text
arbiterGatesTableName = Text
"arbiter_gates"
gateEpochSQL :: Text
gateEpochSQL :: Text
gateEpochSQL = Text
"'1970-01-01'::timestamptz"
createGatesTableSQL :: SchemaName -> Text
createGatesTableSQL :: Text -> Text
createGatesTableSQL Text
schemaName =
[Text] -> Text
T.unlines
[ Text
"CREATE TABLE IF NOT EXISTS " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text
arbiterGatesTable Text
schemaName Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" ("
, Text
" task_name TEXT PRIMARY KEY,"
, Text
" last_run_at TIMESTAMPTZ NOT NULL DEFAULT " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
gateEpochSQL
, Text
");"
]
addGateMetadataColumnSQL :: SchemaName -> Text
addGateMetadataColumnSQL :: Text -> Text
addGateMetadataColumnSQL Text
schemaName =
Text
"ALTER TABLE " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> Text
arbiterGatesTable Text
schemaName Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" ADD COLUMN IF NOT EXISTS metadata JSONB;"