@@ -5521,6 +5521,64 @@ REVOKE SYSTEM CREATEDB FROM can_createdb_global;
5521
5521
statement ok
5522
5522
DROP ROLE can_createdb_global;
5523
5523
5524
+ # Test that dependencies are preserved when altering only the USING expression
5525
+ # of a policy that has both USING and WITH CHECK expressions. This is a repro
5526
+ # for GH issue 153191.
5527
+ subtest bug_fix_lost_dependencies_alter_policy_#153191
5528
+
5529
+ statement ok
5530
+ CREATE TABLE dep_test (id INT PRIMARY KEY, value INT);
5531
+
5532
+ statement ok
5533
+ CREATE SEQUENCE seq_with_check;
5534
+
5535
+ statement ok
5536
+ CREATE FUNCTION func_using_old(n INT) RETURNS BOOL AS $$ SELECT n > 0; $$ LANGUAGE SQL;
5537
+
5538
+ statement ok
5539
+ CREATE FUNCTION func_using_new(n INT) RETURNS BOOL AS $$ SELECT n >= 0; $$ LANGUAGE SQL;
5540
+
5541
+ # Create a olicy that have different dependencies for USING and WITH CHECK
5542
+ # expressions.
5543
+ statement ok
5544
+ CREATE POLICY test_policy ON dep_test
5545
+ FOR ALL
5546
+ USING (func_using_old(value))
5547
+ WITH CHECK (nextval('seq_with_check') < 1000);
5548
+
5549
+ # Verify initial dependencies are tracked.
5550
+ statement error pq: cannot drop function "func_using_old" because other objects
5551
+ DROP FUNCTION func_using_old;
5552
+
5553
+ statement error pq: cannot drop sequence seq_with_check because other objects depend on it
5554
+ DROP SEQUENCE seq_with_check;
5555
+
5556
+ # Alter only the USING expression, which should preserve the WITH CHECK
5557
+ # dependency.
5558
+ statement ok
5559
+ ALTER POLICY test_policy ON dep_test USING (func_using_new(value));
5560
+
5561
+ # Ensure dependency on WITH CHECK still exists.
5562
+ statement error pq: cannot drop sequence seq_with_check because other objects depend on it
5563
+ DROP SEQUENCE seq_with_check;
5564
+
5565
+ # Ensure old dependency on USING doesn't exist anymore.
5566
+ statement ok
5567
+ DROP FUNCTION func_using_old;
5568
+
5569
+ # And the new USING function should be protected.
5570
+ statement error pq: cannot drop function "func_using_new" because other objects
5571
+ DROP FUNCTION func_using_new;
5572
+
5573
+ statement ok
5574
+ DROP TABLE dep_test CASCADE;
5575
+
5576
+ statement ok
5577
+ DROP SEQUENCE seq_with_check;
5578
+
5579
+ statement ok
5580
+ DROP FUNCTION func_using_new;
5581
+
5524
5582
subtest end
5525
5583
5526
5584
subtest filter_pushdown_leaks
0 commit comments