{-# LANGUAGE
AllowAmbiguousTypes
, ConstraintKinds
, DeriveAnyClass
, DeriveGeneric
, DerivingStrategies
, FlexibleContexts
, FlexibleInstances
, GADTs
, LambdaCase
, MultiParamTypeClasses
, OverloadedLabels
, OverloadedStrings
, RankNTypes
, ScopedTypeVariables
, TypeApplications
, DataKinds
, PolyKinds
, 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 :: forall (sch :: Symbol) (db :: SchemasType).
KnownSymbol sch =>
Alias sch -> Definition db (Create sch '[] db)
createSchema Alias sch
sch = forall (db0 :: SchemasType) (db1 :: SchemasType).
ByteString -> Definition db0 db1
UnsafeDefinition forall a b. (a -> b) -> a -> b
$
ByteString
"CREATE" ByteString -> ByteString -> ByteString
<+> ByteString
"SCHEMA" ByteString -> ByteString -> ByteString
<+> forall sql. RenderSQL sql => sql -> ByteString
renderSQL Alias sch
sch forall a. Semigroup a => a -> a -> a
<> ByteString
";"
createSchemaIfNotExists
:: (KnownSymbol sch, Has sch db schema)
=> Alias sch
-> Definition db (CreateIfNotExists sch '[] db)
createSchemaIfNotExists :: forall (sch :: Symbol) (db :: SchemasType)
(schema :: [(Symbol, SchemumType)]).
(KnownSymbol sch, Has sch db schema) =>
Alias sch -> Definition db (CreateIfNotExists sch '[] db)
createSchemaIfNotExists Alias sch
sch = forall (db0 :: SchemasType) (db1 :: SchemasType).
ByteString -> Definition db0 db1
UnsafeDefinition 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
<+> forall sql. RenderSQL sql => sql -> ByteString
renderSQL Alias sch
sch forall a. Semigroup a => a -> a -> a
<> ByteString
";"
dropSchemaCascade
:: KnownSymbol sch
=> Alias sch
-> Definition db (Drop sch db)
dropSchemaCascade :: forall (sch :: Symbol) (db :: SchemasType).
KnownSymbol sch =>
Alias sch -> Definition db (Drop sch db)
dropSchemaCascade Alias sch
sch = forall (db0 :: SchemasType) (db1 :: SchemasType).
ByteString -> Definition db0 db1
UnsafeDefinition forall a b. (a -> b) -> a -> b
$
ByteString
"DROP SCHEMA" ByteString -> ByteString -> 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 :: forall (sch :: Symbol) (db :: SchemasType).
KnownSymbol sch =>
Alias sch -> Definition db (DropIfExists sch db)
dropSchemaCascadeIfExists Alias sch
sch = forall (db0 :: SchemasType) (db1 :: SchemasType).
ByteString -> Definition db0 db1
UnsafeDefinition forall a b. (a -> b) -> a -> b
$
ByteString
"DROP SCHEMA IF EXISTS" ByteString -> ByteString -> ByteString
<+> forall sql. RenderSQL sql => sql -> ByteString
renderSQL Alias sch
sch ByteString -> ByteString -> ByteString
<+> ByteString
"CASCADE;"