@@ -35,7 +35,9 @@ module Squeal.PostgreSQL.Definition.Table
35 , dropTable
35 , dropTable
36 , dropTableIfExists
36 , dropTableIfExists
37 , alterTable
37 , alterTable
38 , alterTableRename
39 , alterTableRename
40+ , alterTableIfExistsRename
39 , AlterTable (..)
41 , AlterTable (..)
40 , addConstraint
42 , addConstraint
41 , dropConstraint
43 , dropConstraint
@@ -202,16 +204,28 @@ dropTableIfExists tab = UnsafeDefinition $ "DROP TABLE IF EXISTS" <+> renderSQL
203-- | `alterTable` changes the definition of a table from the schema.
205-- | `alterTable` changes the definition of a table from the schema.
204alterTable
206alterTable
205− :: (Has sch schemas schema, Has tab schema ('Table table0))
207+ :: (Has sch schemas schema, KnownSymbol tab)
206 => QualifiedAlias sch tab -- ^ table to alter
208 => QualifiedAlias sch tab -- ^ table to alter
207− -> AlterTable sch tab schemas table1 -- ^ alteration to perform
209+ -> AlterTable sch tab schemas table -- ^ alteration to perform
208− -> Definition schemas (Alter sch (Alter tab ('Table table1) schema) schemas)
210+ -> Definition schemas (Alter sch (Alter tab ('Table table) schema) schemas)
209alterTable tab alteration = UnsafeDefinition $
211alterTable tab alteration = UnsafeDefinition $
210 "ALTER TABLE"
212 "ALTER TABLE"
211 <+> renderSQL tab
213 <+> renderSQL tab
212 <+> renderAlterTable alteration
214 <+> renderAlterTable alteration
217+-- | `alterTable` changes the definition of a table from the schema.
219+ :: (Has sch schemas schema, KnownSymbol tab)
220+ => QualifiedAlias sch tab -- ^ table to alter
221+ -> AlterTable sch tab schemas table -- ^ alteration to perform
222+ -> Definition schemas (Alter sch (AlterIfExists tab ('Table table) schema) schemas)
223+alterTableIfExists tab alteration = UnsafeDefinition $
224+ "ALTER TABLE IF EXISTS"
226+ <+> renderAlterTable alteration
215-- | `alterTableRename` changes the name of a table from the schema.
229-- | `alterTableRename` changes the name of a table from the schema.
217-- >>> printSQL $ alterTableRename #foo #bar
231-- >>> printSQL $ alterTableRename #foo #bar
@@ -225,6 +239,15 @@ alterTableRename tab0 tab1 = UnsafeDefinition $
225 "ALTER TABLE" <+> renderSQL tab0
239 "ALTER TABLE" <+> renderSQL tab0
226 <+> "RENAME TO" <+> renderSQL tab1 <> ";"
240 <+> "RENAME TO" <+> renderSQL tab1 <> ";"
242+alterTableIfExistsRename
243+ :: (KnownSymbol tab0, KnownSymbol tab1)
244+ => Alias tab0 -- ^ table to rename
245+ -> Alias tab1 -- ^ what to rename it
246+ -> Definition schema (RenameIfExists tab0 tab1 schema)
247+alterTableIfExistsRename tab0 tab1 = UnsafeDefinition $
248+ "ALTER TABLE IF EXISTS" <+> renderSQL tab0
249+ <+> "RENAME TO" <+> renderSQL tab1 <> ";"
228-- | An `AlterTable` describes the alteration to perform on the columns
251-- | An `AlterTable` describes the alteration to perform on the columns
229-- of a table.
252-- of a table.
230newtype AlterTable
253newtype AlterTable