@@ -210,6 +210,7 @@ tests = do
210
210
, referenceTable = Nothing
211
211
, primaryKey = False
212
212
, withIndex = True
213
+ , autoPolicy = False
213
214
}
214
215
215
216
(SchemaOperations. addColumn options inputSchema) `shouldBe` expectedSchema
@@ -266,6 +267,68 @@ tests = do
266
267
, referenceTable = Nothing
267
268
, primaryKey = False
268
269
, withIndex = False
270
+ , autoPolicy = False
271
+ }
272
+
273
+ (SchemaOperations. addColumn options inputSchema) `shouldBe` expectedSchema
274
+
275
+ it " should add a policy if autoPolicy = true" do
276
+ let inputSchema = [tableA]
277
+
278
+ let tableAWithCreatedAt = StatementCreateTable CreateTable
279
+ { name = " a"
280
+ , columns = [
281
+ Column
282
+ { name = " user_id"
283
+ , columnType = PUUID
284
+ , defaultValue = Nothing
285
+ , notNull = True
286
+ , isUnique = False
287
+ , generator = Nothing
288
+ }
289
+ ]
290
+ , primaryKeyConstraint = PrimaryKeyConstraint []
291
+ , constraints = []
292
+ }
293
+
294
+ let index = CreateIndex
295
+ { indexName = " a_user_id_index"
296
+ , unique = False
297
+ , tableName = " a"
298
+ , columns = [IndexColumn { column = VarExpression " user_id" , columnOrder = [] }]
299
+ , whereClause = Nothing
300
+ , indexType = Nothing
301
+ }
302
+ let constraint = AddConstraint
303
+ { tableName = " a"
304
+ , constraint = ForeignKeyConstraint { name = Just " a_ref_user_id" , columnName = " user_id" , referenceTable = " users" , referenceColumn = Just " id" , onDelete = Just NoAction }
305
+ , deferrable = Nothing
306
+ , deferrableType = Nothing
307
+ }
308
+ let enableRLS = EnableRowLevelSecurity { tableName = " a" }
309
+ let policy = CreatePolicy
310
+ { name = " Users can manage their a"
311
+ , tableName = " a"
312
+ , action = Nothing
313
+ , using = Just (EqExpression (VarExpression " user_id" ) (CallExpression " ihp_user_id" [] ))
314
+ , check = Just (EqExpression (VarExpression " user_id" ) (CallExpression " ihp_user_id" [] ))
315
+ }
316
+
317
+ let expectedSchema = [tableAWithCreatedAt, index, constraint, enableRLS, policy]
318
+
319
+ let options = SchemaOperations. AddColumnOptions
320
+ { tableName = " a"
321
+ , columnName = " user_id"
322
+ , columnType = PUUID
323
+ , defaultValue = Nothing
324
+ , isArray = False
325
+ , allowNull = False
326
+ , isUnique = False
327
+ , isReference = True
328
+ , referenceTable = Just " users"
329
+ , primaryKey = False
330
+ , withIndex = False
331
+ , autoPolicy = True
269
332
}
270
333
271
334
(SchemaOperations. addColumn options inputSchema) `shouldBe` expectedSchema
@@ -301,7 +364,6 @@ tests = do
301
364
(SchemaOperations. deleteColumn options inputSchema) `shouldBe` expectedSchema
302
365
303
366
it " should delete a updated_at trigger" do
304
-
305
367
let tableAWithCreatedAt = StatementCreateTable CreateTable
306
368
{ name = " a"
307
369
, columns = [
0 commit comments