mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 12:31:52 +03:00
ec8b2c80b5
* 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
37 lines
1018 B
Haskell
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 $$; "
|