这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 23 additions & 83 deletions console/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"less-loader": "^4.1.0",
"lint-staged": "^6.1.1",
"mini-css-extract-plugin": "^0.4.0",
"node-sass": "^4.9.2",
"node-sass": "^4.12.0",
"nyc": "^13.3.0",
"optimize-css-assets-webpack-plugin": "^4.0.2",
"react-a11y": "^0.2.6",
Expand Down
89 changes: 56 additions & 33 deletions server/src-lib/Hasura/Server/PGDump.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ module Hasura.Server.PGDump
, execPGDump
) where

import Control.Exception (IOException, try)
import Control.Exception (IOException, try)
import Data.Aeson.Casing
import Data.Aeson.TH
import qualified Data.ByteString.Lazy as BL
import qualified Data.FileEmbed as FE
import qualified Data.List as L
import qualified Data.Text as T
import qualified Database.PG.Query as Q
import qualified Data.ByteString.Lazy as BL
import Data.Char (isSpace)
import qualified Data.List as L
import qualified Data.String.Conversions as CS
import qualified Data.Text as T
import qualified Database.PG.Query as Q
import Hasura.Prelude
import qualified Hasura.RQL.Types.Error as RTE
import qualified Hasura.RQL.Types.Error as RTE
import System.Exit
import System.Process
import qualified Text.Regex.TDFA as TDFA

data PGDumpReqBody =
PGDumpReqBody
Expand All @@ -24,30 +26,13 @@ data PGDumpReqBody =

$(deriveJSON (aesonDrop 3 snakeCase) ''PGDumpReqBody)

script :: IsString a => a
script = $(FE.embedStringFile "src-rsr/run_pg_dump.sh")

runScript
:: String
-> [String]
-> String
-> IO (Either String BL.ByteString)
runScript dbUrl opts clean = do
(exitCode, filename, stdErr) <- readProcessWithExitCode "/bin/sh"
["/dev/stdin", dbUrl, unwords opts, clean] script
case exitCode of
ExitSuccess -> do
contents <- BL.readFile $ L.dropWhileEnd (== '\n') filename
return $ Right contents
ExitFailure _ -> return $ Left stdErr

execPGDump
:: (MonadError RTE.QErr m, MonadIO m)
=> PGDumpReqBody
-> Q.ConnInfo
-> m BL.ByteString
execPGDump b ci = do
eOutput <- liftIO $ try $ runScript dbUrl opts clean
eOutput <- liftIO $ try execProcess
output <- either throwException return eOutput
case output of
Left err ->
Expand All @@ -57,11 +42,49 @@ execPGDump b ci = do
throwException :: (MonadError RTE.QErr m) => IOException -> m a
throwException _ = RTE.throw500 "internal exception while executing pg_dump"

-- FIXME(shahidhk): need to add connection options (Q.connOptions) too?
dbUrl = "postgres://" <> Q.connUser ci <> ":" <> Q.connPassword ci
<> "@" <> Q.connHost ci <> ":" <> show (Q.connPort ci)
<> "/" <> Q.connDatabase ci
opts = prbOpts b
clean = case prbCleanOutput b of
Just v -> show v
Nothing -> show False
execProcess = do
(exitCode, stdOut, stdErr) <- readProcessWithExitCode "pg_dump" opts ""
return $ case exitCode of
ExitSuccess -> Right $ CS.cs (clean stdOut)
ExitFailure _ -> Left $ CS.cs stdErr

opts = Q.pgConnString ci : "--encoding=utf8" : prbOpts b

clean str
| fromMaybe False (prbCleanOutput b) =
unlines $ filter (not . shouldDropLine) (lines str)
| otherwise = str

shouldDropLine line =
-- delete empty lines
all isSpace line
-- delete comments
|| "--" `L.isPrefixOf` line
-- delete front matter
|| line `elem` preambleLines
-- delete notify triggers
|| notifyTriggerRegex `TDFA.match` line

preambleLines =
[ "SET statement_timeout = 0;"
, "SET lock_timeout = 0;"
, "SET idle_in_transaction_session_timeout = 0;"
, "SET client_encoding = 'UTF8';"
, "SET standard_conforming_strings = on;"
, "SELECT pg_catalog.set_config('search_path', '', false);"
, "SET check_function_bodies = false;"
, "SET xmloption = content;"
, "SET client_min_messages = warning;"
, "SET row_security = off;"
, "SET default_tablespace = '';"
, "SET default_with_oids = false;"
, "CREATE SCHEMA public;"
, "COMMENT ON SCHEMA public IS 'standard public schema';"
]

notifyTriggerRegex =
let regexStr :: String =
"^CREATE TRIGGER \"?notify_hasura_.+\"? AFTER [[:alnum:]]+ "
<> "ON .+ FOR EACH ROW EXECUTE PROCEDURE "
<> "\"?hdb_views\"?\\.\"?notify_hasura_.+\"?\\(\\);$"
in TDFA.makeRegex regexStr :: TDFA.Regex
47 changes: 0 additions & 47 deletions server/src-rsr/run_pg_dump.sh

This file was deleted.

2 changes: 1 addition & 1 deletion server/stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ packages:
# Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3)
extra-deps:
- git: https://github.com/hasura/pg-client-hs.git
commit: 85f9c2c15e4fa09f2e2a86dbb23149b5256bdd34
commit: 3f905a5fa57e2898dbb733a777cadb80990b3d45
- git: https://github.com/hasura/graphql-parser-hs.git
commit: 39d175c5c7bca35ec04d13c92a39f600bd6413cf
- git: https://github.com/hasura/ci-info-hs.git
Expand Down