graphql-engine/server/src-lib/Hasura/RQL/DDL/Utils.hs
Vamshi Surabhi ec8b2c80b5
refactor to remove warnings especially with orphan instances (#1163)
* remove phase one/two distinction and hdbquery typeclass

* move extensions to default-extensions

* switch to LazyTx which only acquires a connection if needed

* move defns from TH module into Ops module

* remove tojson orphan instance for http exception

* remove orphan instance for dmlp1

* getTopLevelNodes will not throw any exceptions
2018-12-13 12:56:15 +05:30

37 lines
1018 B
Haskell

module Hasura.RQL.DDL.Utils
( clearHdbViews
) where
import qualified Data.Text as T
import qualified Database.PG.Query as Q
import Hasura.Prelude ((<>))
clearHdbViews :: Q.Tx ()
clearHdbViews = Q.multiQ (Q.fromText (clearHdbOnlyViews <> clearHdbViewsFunc))
clearHdbOnlyViews :: T.Text
clearHdbOnlyViews =
"DO $$ DECLARE \
\ r RECORD; \
\ BEGIN \
\ FOR r IN (SELECT viewname FROM pg_views WHERE schemaname = 'hdb_views') LOOP \
\ EXECUTE 'DROP VIEW IF EXISTS hdb_views.' || quote_ident(r.viewname) || ' CASCADE'; \
\ END LOOP; \
\ END $$; "
clearHdbViewsFunc :: T.Text
clearHdbViewsFunc =
"DO $$ DECLARE \
\ _sql text; \
\ BEGIN \
\ SELECT INTO _sql \
\ string_agg('DROP FUNCTION hdb_views.' || quote_ident(r.routine_name) || '() CASCADE;' \
\ , E'\n') \
\ FROM information_schema.routines r \
\ WHERE r.specific_schema = 'hdb_views'; \
\ IF _sql IS NOT NULL THEN \
\ EXECUTE _sql; \
\ END IF; \
\ END $$; "