Skip to content

Commit 2d12cce

Browse files
committed
Automatically delete all table triggers when a table is removed from the schema
1 parent 713fa49 commit 2d12cce

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

IHP/IDE/SchemaDesigner/SchemaOperations.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,4 +320,5 @@ deleteTable tableName statements =
320320
CreateIndex { tableName = indexTable } | indexTable == tableName -> False
321321
EnableRowLevelSecurity { tableName = rlsTable } | rlsTable == tableName -> False
322322
CreatePolicy { tableName = policyTable } | policyTable == tableName -> False
323+
CreateTrigger { tableName = triggerTable } | triggerTable == tableName -> False
323324
otherwise -> True

Test/IDE/SchemaDesigner/SchemaOperationsSpec.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,15 @@ tests = do
8585
(SchemaOperations.disableRowLevelSecurityIfNoPolicies "a" inputSchema) `shouldBe` inputSchema
8686

8787
describe "deleteTable" do
88-
it "delete a table with all it's indices, constraints, policies, enable RLS statements" do
88+
it "delete a table with all it's indices, constraints, policies, enable RLS statements, triggers" do
8989
let inputSchema = parseSqlStatements [trimming|
9090
CREATE TABLE users ();
9191
CREATE TABLE tasks ();
9292
CREATE INDEX tasks_user_id_index ON tasks (user_id);
9393
ALTER TABLE tasks ADD CONSTRAINT tasks_ref_user_id FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE NO ACTION;
9494
CREATE POLICY "Users can manage their tasks" ON tasks USING (user_id = ihp_user_id()) WITH CHECK (user_id = ihp_user_id());
9595
ALTER TABLE tasks ENABLE ROW LEVEL SECURITY;
96+
CREATE TRIGGER update_tasks_updated_at BEFORE UPDATE ON tasks FOR EACH ROW EXECUTE FUNCTION set_updated_at_to_now();
9697
|]
9798
let outputSchema = parseSqlStatements [trimming|
9899
CREATE TABLE users ();
@@ -176,4 +177,4 @@ parseSqlStatements :: Text -> [Statement]
176177
parseSqlStatements sql =
177178
case Megaparsec.runParser Parser.parseDDL "input" sql of
178179
Left parserError -> error (cs $ Megaparsec.errorBundlePretty parserError) -- For better error reporting in hspec
179-
Right statements -> statements
180+
Right statements -> statements

0 commit comments

Comments
 (0)