Commit bc7594d0 authored by Sophie Herold's avatar Sophie Herold 🌼

Default to `Nothing` instead of `Just []`

parent becfa51f
Pipeline #811 passed with stage
in 3 minutes and 47 seconds
......@@ -14,10 +14,6 @@ import Database.HamSql.Internal.Utils
import Database.HamSql.Setup
import Database.YamSql
presetEmpty :: [a] -> Maybe [a]
presetEmpty [] = Nothing
presetEmpty xs = Just xs
recoverIndexName :: Text -> [Text] -> Text -> Text -> Maybe IndexName
recoverIndexName tbl keys n s =
case stripPrefix (tbl <> "_") n >>= stripSuffix ("_" <> s) of
......@@ -38,12 +34,12 @@ deployedSchemas = do
{ schemaName = schema
, schemaDescription = description
, schemaDependencies = Nothing
, schemaFunctions = Just []
, schemaFunctions = Nothing
, schemaFunctionTemplates = Nothing
, schemaTables = Just tables
, schemaTableTemplates = Nothing
, schemaRoles = Nothing
, schemaSequences = Just []
, schemaSequences = Nothing
, schemaPrivUsage = Nothing
, schemaPrivSelectAll = Nothing
, schemaPrivInsertAll = Nothing
......@@ -52,8 +48,8 @@ deployedSchemas = do
, schemaPrivSequenceAll = Nothing
, schemaPrivExecuteAll = Nothing
, schemaPrivAllAll = Nothing
, schemaDomains = Just []
, schemaTypes = Just []
, schemaDomains = Nothing
, schemaTypes = Nothing
, schemaExecPostInstall = Nothing
, schemaExecPostInstallAndUpgrade = Nothing
}
......
......@@ -127,11 +127,11 @@ readSchema md = do
in confDirFiles "functions.d" >>= mapM (readFunctionFromFile ins)
let schemaData' =
schemaData
{ schemaDomains = schemaDomains schemaData <> Just domains
, schemaTypes = schemaTypes schemaData <> Just types
, schemaSequences = schemaSequences schemaData <> Just sequences
, schemaTables = schemaTables schemaData <> Just tables
, schemaFunctions = schemaFunctions schemaData <> Just functions
{ schemaDomains = schemaDomains schemaData <> presetEmpty domains
, schemaTypes = schemaTypes schemaData <> presetEmpty types
, schemaSequences = schemaSequences schemaData <> presetEmpty sequences
, schemaTables = schemaTables schemaData <> presetEmpty tables
, schemaFunctions = schemaFunctions schemaData <> presetEmpty functions
}
return schemaData'
where
......
......@@ -28,6 +28,10 @@ preset d x
| d == x = Nothing
| otherwise = Just x
presetEmpty :: [a] -> Maybe [a]
presetEmpty [] = Nothing
presetEmpty xs = Just xs
err :: Text -> a
err xs =
unsafePerformIO $ do
......@@ -70,11 +74,6 @@ maybePrefix :: Text -> Maybe Text -> Text
maybePrefix _ Nothing = ""
maybePrefix p (Just x) = p <> x
-- | Joins two Maybe lists
maybeJoin :: Maybe [a] -> Maybe [a] -> Maybe [a]
maybeJoin Nothing Nothing = Nothing
maybeJoin xs ys = Just (fromMaybe [] xs ++ fromMaybe [] ys)
fromJustReason :: Text -> Maybe a -> a
fromJustReason _ (Just x) = x
fromJustReason reason Nothing = err $ "fromJust failed: " <> reason
......
......@@ -111,13 +111,12 @@ applyTpl :: Setup -> Setup
applyTpl s =
s
-- TODO: possible overwrite here!
{setupSchemaData = Just $ maybeMap applySchema (setupSchemaData s)}
{setupSchemaData = map applySchema <$> setupSchemaData s}
where
applySchema m =
m
{ schemaTables = Just $ maybeMap applyTableTemplates (schemaTables m)
, schemaFunctions =
Just $ maybeMap applyFunctionTemplates (schemaFunctions m)
{ schemaTables = map applyTableTemplates <$> schemaTables m
, schemaFunctions = map applyFunctionTemplates <$> schemaFunctions m
}
applyTableTemplates :: Table -> Table
applyTableTemplates t = foldr applyTableTpl t (tableTpls t)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment