@@ -590,8 +590,8 @@ newtype AlterTable
590590-- >>> :{
591591-- let
592592-- definition :: Definition
593−-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
594−-- '["tab" ::: 'Table ('["positive" ::: Check '["col"]] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
593+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]]
594+-- '["public" ::: '["tab" ::: 'Table ('["positive" ::: Check '["col"]] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]]
595595-- definition = alterTable #tab (addConstraint #positive (check #col (#col .> 0)))
596596-- in printSQL definition
597597-- :}
@@ -615,8 +615,8 @@ addConstraint alias constraint = UnsafeAlterTable $
615615-- >>> :{
616616-- let
617617-- definition :: Definition
618−-- '["tab" ::: 'Table ('["positive" ::: Check '["col"]] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
619−-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
618+-- '["public" ::: '["tab" ::: 'Table ('["positive" ::: Check '["col"]] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]]
619+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]]
620620-- definition = alterTable #tab (dropConstraint #positive)
621621-- in printSQL definition
622622-- :}
@@ -641,10 +641,10 @@ class AddColumn ty where
641641 -- >>> :{
642642 -- let
643643 -- definition :: Definition
644− -- '["tab" ::: 'Table ('[] :=> '["col1" ::: 'NoDef :=> 'Null 'PGint4])]
645− -- '["tab" ::: 'Table ('[] :=>
644+ -- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col1" ::: 'NoDef :=> 'Null 'PGint4])]]
645+ -- '["public" ::: '["tab" ::: 'Table ('[] :=>
646646 -- '[ "col1" ::: 'NoDef :=> 'Null 'PGint4
647− -- , "col2" ::: 'Def :=> 'Null 'PGtext ])]
647+ -- , "col2" ::: 'Def :=> 'Null 'PGtext ])]]
648648 -- definition = alterTable #tab (addColumn #col2 (text & nullable & default_ "foo"))
649649 -- in printSQL definition
650650 -- :}
@@ -653,10 +653,10 @@ class AddColumn ty where
653653 -- >>> :{
654654 -- let
655655 -- definition :: Definition
656− -- '["tab" ::: 'Table ('[] :=> '["col1" ::: 'NoDef :=> 'Null 'PGint4])]
657− -- '["tab" ::: 'Table ('[] :=>
656+ -- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col1" ::: 'NoDef :=> 'Null 'PGint4])]]
657+ -- '["public" ::: '["tab" ::: 'Table ('[] :=>
658658 -- '[ "col1" ::: 'NoDef :=> 'Null 'PGint4
659− -- , "col2" ::: 'NoDef :=> 'Null 'PGtext ])]
659+ -- , "col2" ::: 'NoDef :=> 'Null 'PGtext ])]]
660660 -- definition = alterTable #tab (addColumn #col2 (text & nullable))
661661 -- in printSQL definition
662662 -- :}
@@ -682,10 +682,10 @@ instance {-# OVERLAPPABLE #-} AddColumn ('NoDef :=> 'Null ty)
682682-- >>> :{
683683-- let
684684-- definition :: Definition
685−-- '["tab" ::: 'Table ('[] :=>
685+-- '["public" ::: '["tab" ::: 'Table ('[] :=>
686686-- '[ "col1" ::: 'NoDef :=> 'Null 'PGint4
687−-- , "col2" ::: 'NoDef :=> 'Null 'PGtext ])]
688−-- '["tab" ::: 'Table ('[] :=> '["col1" ::: 'NoDef :=> 'Null 'PGint4])]
687+-- , "col2" ::: 'NoDef :=> 'Null 'PGtext ])]]
688+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col1" ::: 'NoDef :=> 'Null 'PGint4])]]
689689-- definition = alterTable #tab (dropColumn #col2)
690690-- in printSQL definition
691691-- :}
@@ -706,8 +706,8 @@ dropColumn column = UnsafeAlterTable $
706706-- >>> :{
707707-- let
708708-- definition :: Definition
709−-- '["tab" ::: 'Table ('[] :=> '["foo" ::: 'NoDef :=> 'Null 'PGint4])]
710−-- '["tab" ::: 'Table ('[] :=> '["bar" ::: 'NoDef :=> 'Null 'PGint4])]
709+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["foo" ::: 'NoDef :=> 'Null 'PGint4])]]
710+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["bar" ::: 'NoDef :=> 'Null 'PGint4])]]
711711-- definition = alterTable #tab (renameColumn #foo #bar)
712712-- in printSQL definition
713713-- :}
@@ -751,8 +751,8 @@ newtype AlterColumn (db :: DBType) (ty0 :: ColumnType) (ty1 :: ColumnType) =
751751-- >>> :{
752752-- let
753753-- definition :: Definition
754−-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
755−-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'Def :=> 'Null 'PGint4])]
754+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]]
755+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col" ::: 'Def :=> 'Null 'PGint4])]]
756756-- definition = alterTable #tab (alterColumn #col (setDefault 5))
757757-- in printSQL definition
758758-- :}
@@ -768,8 +768,8 @@ setDefault expression = UnsafeAlterColumn $
768768-- >>> :{
769769-- let
770770-- definition :: Definition
771−-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'Def :=> 'Null 'PGint4])]
772−-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
771+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col" ::: 'Def :=> 'Null 'PGint4])]]
772+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]]
773773-- definition = alterTable #tab (alterColumn #col dropDefault)
774774-- in printSQL definition
775775-- :}
@@ -784,8 +784,8 @@ dropDefault = UnsafeAlterColumn $ "DROP DEFAULT"
784784-- >>> :{
785785-- let
786786-- definition :: Definition
787−-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
788−-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
787+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]]
788+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]]
789789-- definition = alterTable #tab (alterColumn #col setNotNull)
790790-- in printSQL definition
791791-- :}
@@ -799,8 +799,8 @@ setNotNull = UnsafeAlterColumn $ "SET NOT NULL"
799799-- >>> :{
800800-- let
801801-- definition :: Definition
802−-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
803−-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]
802+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]]
803+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'Null 'PGint4])]]
804804-- definition = alterTable #tab (alterColumn #col dropNotNull)
805805-- in printSQL definition
806806-- :}
@@ -816,8 +816,8 @@ dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
816816-- >>> :{
817817-- let
818818-- definition :: Definition
819−-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]
820−-- '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGnumeric])]
819+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGint4])]]
820+-- '["public" ::: '["tab" ::: 'Table ('[] :=> '["col" ::: 'NoDef :=> 'NotNull 'PGnumeric])]]
821821-- definition =
822822-- alterTable #tab (alterColumn #col (alterType (numeric & notNullable)))
823823-- in printSQL definition
@@ -831,9 +831,9 @@ alterType ty = UnsafeAlterColumn $ "TYPE" <+> renderColumnTypeExpression ty
831831-- >>> :{
832832-- let
833833-- definition :: Definition
834−-- '[ "abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])]
835−-- '[ "abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])
836−-- , "bc" ::: 'View ('["b" ::: 'Null 'PGint4, "c" ::: 'Null 'PGint4])]
834+-- '[ "public" ::: '["abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])]]
835+-- '[ "public" ::: '["abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])
836+-- , "bc" ::: 'View ('["b" ::: 'Null 'PGint4, "c" ::: 'Null 'PGint4])]]
837837-- definition =
838838-- createView #bc (select (#b :* #c) (from (table #abc)))
839839-- in printSQL definition
@@ -854,9 +854,9 @@ createView alias query = UnsafeDefinition $
854854-- >>> :{
855855-- let
856856-- definition :: Definition
857−-- '[ "abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])
858−-- , "bc" ::: 'View ('["b" ::: 'Null 'PGint4, "c" ::: 'Null 'PGint4])]
859−-- '[ "abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])]
857+-- '[ "public" ::: '["abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])
858+-- , "bc" ::: 'View ('["b" ::: 'Null 'PGint4, "c" ::: 'Null 'PGint4])]]
859+-- '[ "public" ::: '["abc" ::: 'Table ('[] :=> '["a" ::: 'NoDef :=> 'Null 'PGint4, "b" ::: 'NoDef :=> 'Null 'PGint4, "c" ::: 'NoDef :=> 'Null 'PGint4])]]
860860-- definition = dropView #bc
861861-- in printSQL definition
862862-- :}
@@ -869,7 +869,7 @@ dropView vw = UnsafeDefinition $ "DROP VIEW" <+> renderQualifiedAlias vw <> ";"
869869
870870-- | Enumerated types are created using the `createTypeEnum` command, for example
871871--
872−-- >>> printSQL $ createTypeEnum #mood (label @"sad" :* label @"ok" :* label @"happy")
872+-- >>> printSQL $ (createTypeEnum #mood (label @"sad" :* label @"ok" :* label @"happy") :: Definition '["public" ::: '[]] '["public" ::: '["mood" ::: 'Typedef ('PGenum '["sad","ok","happy"])]])
873873-- CREATE TYPE "mood" AS ENUM ('sad', 'ok', 'happy');
874874createTypeEnum
875875 :: (KnownSymbol enum, Has sch db schema, SOP.All KnownSymbol labels)
@@ -887,7 +887,13 @@ createTypeEnum enum labels = UnsafeDefinition $
887887-- >>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
888888-- >>> instance SOP.Generic Schwarma
889889-- >>> instance SOP.HasDatatypeInfo Schwarma
890−-- >>> printSQL $ createTypeEnumFrom @Schwarma #schwarma
890+-- >>> :{
891+-- let
892+-- createSchwarma :: Definition '["public" ::: '[]] '["public" ::: '["schwarma" ::: 'Typedef (PG (Enumerated Schwarma))]]
893+-- createSchwarma = createTypeEnumFrom @Schwarma #schwarma
894+-- in
895+-- printSQL createSchwarma
896+-- :}
891897-- CREATE TYPE "schwarma" AS ENUM ('Beef', 'Lamb', 'Chicken');
892898createTypeEnumFrom
893899 :: forall hask sch enum db schema.
@@ -912,7 +918,7 @@ type PGcomplex = 'PGcomposite
912918
913919>>> :{
914920let
915− setup :: Definition '[] '["complex" ::: 'Typedef PGcomplex]
921+ setup :: Definition '["public" ::: '[]] '["public" ::: '["complex" ::: 'Typedef PGcomplex]]
916922 setup = createTypeComposite #complex
917923 (float8 `as` #real :* float8 `as` #imaginary)
918924in printSQL setup
@@ -939,7 +945,14 @@ createTypeComposite ty fields = UnsafeDefinition $
939945-- >>> data Complex = Complex {real :: Double, imaginary :: Double} deriving GHC.Generic
940946-- >>> instance SOP.Generic Complex
941947-- >>> instance SOP.HasDatatypeInfo Complex
942−-- >>> printSQL $ createTypeCompositeFrom @Complex #complex
948+-- >>> type DB = '["public" ::: '["complex" ::: 'Typedef (PG (Composite Complex))]]
949+-- >>> :{
950+-- let
951+-- createComplex :: Definition '["public" ::: '[]] DB
952+-- createComplex = createTypeCompositeFrom @Complex #complex
953+-- in
954+-- printSQL createComplex
955+-- :}
943956-- CREATE TYPE "complex" AS ("real" float8, "imaginary" float8);
944957createTypeCompositeFrom
945958 :: forall hask sch ty db schema.
@@ -964,7 +977,7 @@ instance (KnownSymbol alias, PGTyped db ty)
964977-- >>> data Schwarma = Beef | Lamb | Chicken deriving GHC.Generic
965978-- >>> instance SOP.Generic Schwarma
966979-- >>> instance SOP.HasDatatypeInfo Schwarma
967−-- >>> printSQL (dropType #schwarma :: Definition '["schwarma" ::: 'Typedef (PG (Enumerated Schwarma))] '[])
980+-- >>> printSQL (dropType #schwarma :: Definition '["public" ::: '["schwarma" ::: 'Typedef (PG (Enumerated Schwarma))]] '["public" ::: '[]])
968981-- DROP TYPE "schwarma";
969982dropType
970983 :: (Has sch db schema, Has td schema ('Typedef ty))