Repository: hasura/graphql-engine
File: server/src-lib/Hasura/Server/Init.hs (Haskell)

Code before:
  <*> parseConnParams
  <*> parseTxIsolation
  <*> (parseAdminSecret <|> parseAccessKey)
  <*> parseWebHook
  <*> parseJwtSecret
  <*> parseUnAuthRole
  <*> parseCorsConfig
  <*> parseEnableConsole
  <*> parseConsoleAssetsDir
  <*> parseEnableTelemetry
  <*> parseWsReadCookie
  <*> parseStringifyNum
  <*> parseEnabledAPIs
  <*> parseMxRefetchInt
  <*> parseMxBatchSize
  <*> parseEnableAllowlist
  <*> parseEnabledLogs
  <*> parseLogLevel
  <*> parsePlanCacheSize

-- | This implements the mapping between application versions
-- and catalog schema versions.
downgradeShortcuts :: [(String, String)]
downgradeShortcuts = 
  $(do addDependentFile "catalog_versions"
       s <- runIO (readFile "catalog_versions")
       let parseVersions = mapMaybe (parseVersion . words) . lines
    
           parseVersion [tag, version] = Just (tag, version)
           parseVersion _ = Nothing
       TH.lift (parseVersions s))     

downgradeOptionsParser :: Parser DowngradeOptions
downgradeOptionsParser = 
    DowngradeOptions
    <$> choice
        (strOption
          ( long "to-catalog-version" <>
            metavar "<VERSION>" <>
            help "The target catalog schema version (e.g. 31)"
          )
        : map (uncurry shortcut) downgradeShortcuts
        )
    <*> switch
        ( long "dryRun" <>
          help "Don't run any migrations, just print out the SQL."
        )
  where
    shortcut v catalogVersion = 
      flag' (DataString.fromString catalogVersion)
        ( long ("to-" <> v) <>

Review comment (suggestion):
This is a minor point, but I think you can nest splices, so you could use `Data.FileEmbed.embedStringFile` here to avoid having to call `addDependentFile` manually (since we already depend on `file-embed` anyway).

Code after:
  <*> parseServerHost
  <*> parseConnParams
  <*> parseTxIsolation
  <*> (parseAdminSecret <|> parseAccessKey)
  <*> parseWebHook
  <*> parseJwtSecret
  <*> parseUnAuthRole
  <*> parseCorsConfig
  <*> parseEnableConsole
  <*> parseConsoleAssetsDir
  <*> parseEnableTelemetry
  <*> parseWsReadCookie
  <*> parseStringifyNum
  <*> parseEnabledAPIs
  <*> parseMxRefetchInt
  <*> parseMxBatchSize
  <*> parseEnableAllowlist
  <*> parseEnabledLogs
  <*> parseLogLevel
  <*> parsePlanCacheSize

-- | This implements the mapping between application versions
-- and catalog schema versions.
downgradeShortcuts :: [(String, String)]
downgradeShortcuts = 
  $(do let s = $(embedStringFile "src-rsr/catalog_versions.txt")
          
           parseVersions = map (parseVersion . words) . lines
     
           parseVersion [tag, version] = (tag, version)
           parseVersion other = error ("unrecognized tag/catalog mapping " ++ show other)
       TH.lift (parseVersions s))     

downgradeOptionsParser :: Parser DowngradeOptions
downgradeOptionsParser = 
    DowngradeOptions
    <$> choice
        (strOption
          ( long "to-catalog-version" <>
            metavar "<VERSION>" <>
            help "The target catalog schema version (e.g. 31)"
          )
        : map (uncurry shortcut) downgradeShortcuts
        )
    <*> switch
        ( long "dryRun" <>
          help "Don't run any migrations, just print out the SQL."
        )
  where
    shortcut v catalogVersion = 
      flag' (DataString.fromString catalogVersion)