{-# LANGUAGE
AllowAmbiguousTypes
, ConstraintKinds
, DeriveAnyClass
, DeriveGeneric
, DerivingStrategies
, FlexibleContexts
, FlexibleInstances
, GADTs
, LambdaCase
, MultiParamTypeClasses
, OverloadedLabels
, OverloadedStrings
, RankNTypes
, ScopedTypeVariables
, TypeApplications
, TypeInType
, TypeOperators
, UndecidableSuperClasses
#-}
module Squeal.PostgreSQL.Definition.Schema
(
createSchema
, createSchemaIfNotExists
, dropSchemaCascade
, dropSchemaCascadeIfExists
) where
import GHC.TypeLits
import Squeal.PostgreSQL.Type.Alias
import Squeal.PostgreSQL.Definition
import Squeal.PostgreSQL.Render
import Squeal.PostgreSQL.Type.Schema
createSchema
:: KnownSymbol sch
=> Alias sch
-> Definition db (Create sch '[] db)
createSchema :: Alias sch -> Definition db (Create sch '[] db)
createSchema Alias sch
sch = ByteString -> Definition db (Create sch '[] db)
forall (db0 :: SchemasType) (db1 :: SchemasType).
ByteString -> Definition db0 db1
UnsafeDefinition (ByteString -> Definition db (Create sch '[] db))
-> ByteString -> Definition db (Create sch '[] db)
forall a b. (a -> b) -> a -> b
$
ByteString
"CREATE" ByteString -> ByteString -> ByteString
<+> ByteString
"SCHEMA" ByteString -> ByteString -> ByteString
<+> Alias sch -> ByteString
forall sql. RenderSQL sql => sql -> ByteString
renderSQL Alias sch
sch ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
";"
createSchemaIfNotExists
:: (KnownSymbol sch, Has sch db schema)
=> Alias sch
-> Definition db (CreateIfNotExists sch '[] db)
createSchemaIfNotExists :: Alias sch -> Definition db (CreateIfNotExists sch '[] db)
createSchemaIfNotExists Alias sch
sch = ByteString -> Definition db (CreateIfNotExists sch '[] db)
forall (db0 :: SchemasType) (db1 :: SchemasType).
ByteString -> Definition db0 db1
UnsafeDefinition (ByteString -> Definition db (CreateIfNotExists sch '[] db))
-> ByteString -> Definition db (CreateIfNotExists sch '[] db)
forall a b. (a -> b) -> a -> b
$
ByteString
"CREATE" ByteString -> ByteString -> ByteString
<+> ByteString
"SCHEMA" ByteString -> ByteString -> ByteString
<+> ByteString
"IF" ByteString -> ByteString -> ByteString
<+> ByteString
"NOT" ByteString -> ByteString -> ByteString
<+> ByteString
"EXISTS"
ByteString -> ByteString -> ByteString
<+> Alias sch -> ByteString
forall sql. RenderSQL sql => sql -> ByteString
renderSQL Alias sch
sch ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
";"
dropSchemaCascade
:: KnownSymbol sch
=> Alias sch
-> Definition db (Drop sch db)
dropSchemaCascade :: Alias sch -> Definition db (Drop sch db)
dropSchemaCascade Alias sch
sch = ByteString -> Definition db (Drop sch db)
forall (db0 :: SchemasType) (db1 :: SchemasType).
ByteString -> Definition db0 db1
UnsafeDefinition (ByteString -> Definition db (Drop sch db))
-> ByteString -> Definition db (Drop sch db)
forall a b. (a -> b) -> a -> b
$
ByteString
"DROP SCHEMA" ByteString -> ByteString -> ByteString
<+> Alias sch -> ByteString
forall sql. RenderSQL sql => sql -> ByteString
renderSQL Alias sch
sch ByteString -> ByteString -> ByteString
<+> ByteString
"CASCADE;"
dropSchemaCascadeIfExists
:: KnownSymbol sch
=> Alias sch
-> Definition db (DropIfExists sch db)
dropSchemaCascadeIfExists :: Alias sch -> Definition db (DropIfExists sch db)
dropSchemaCascadeIfExists Alias sch
sch = ByteString -> Definition db (DropIfExists sch db)
forall (db0 :: SchemasType) (db1 :: SchemasType).
ByteString -> Definition db0 db1
UnsafeDefinition (ByteString -> Definition db (DropIfExists sch db))
-> ByteString -> Definition db (DropIfExists sch db)
forall a b. (a -> b) -> a -> b
$
ByteString
"DROP SCHEMA IF EXISTS" ByteString -> ByteString -> ByteString
<+> Alias sch -> ByteString
forall sql. RenderSQL sql => sql -> ByteString
renderSQL Alias sch
sch ByteString -> ByteString -> ByteString
<+> ByteString
"CASCADE;"