From c9acf9c4024d948604779f0a63534e442fd7bc85 Mon Sep 17 00:00:00 2001 From: Marc Scholten Date: Mon, 13 Feb 2023 21:57:28 +0100 Subject: [PATCH] Ignore large_pg_notifications table in migrations. Fixes #1605 --- IHP/IDE/CodeGen/MigrationGenerator.hs | 10 ++++++---- Test/IDE/CodeGeneration/MigrationGenerator.hs | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/IHP/IDE/CodeGen/MigrationGenerator.hs b/IHP/IDE/CodeGen/MigrationGenerator.hs index c001a8435..3c83ad941 100644 --- a/IHP/IDE/CodeGen/MigrationGenerator.hs +++ b/IHP/IDE/CodeGen/MigrationGenerator.hs @@ -188,10 +188,12 @@ diffSchemas targetSchema' actualSchema' = (drop <> create) removeNoise = filter \case Comment {} -> False - StatementCreateTable { unsafeGetCreateTable = CreateTable { name = "schema_migrations" } } -> False - AddConstraint { tableName = "schema_migrations" } -> False - CreateFunction { functionName } | "notify_" `Text.isPrefixOf` functionName -> False - _ -> True + StatementCreateTable { unsafeGetCreateTable = CreateTable { name = "schema_migrations" } } -> False + AddConstraint { tableName = "schema_migrations" } -> False + CreateFunction { functionName } | "notify_" `Text.isPrefixOf` functionName -> False + StatementCreateTable { unsafeGetCreateTable = CreateTable { name = "large_pg_notifications" } } -> False + CreateIndex { tableName = "large_pg_notifications" } -> False + _ -> True migrateTable :: Statement -> Statement -> [Statement] migrateTable StatementCreateTable { unsafeGetCreateTable = targetTable } StatementCreateTable { unsafeGetCreateTable = actualTable } = migrateTable' targetTable actualTable diff --git a/Test/IDE/CodeGeneration/MigrationGenerator.hs b/Test/IDE/CodeGeneration/MigrationGenerator.hs index f92887ff1..5863cbffe 100644 --- a/Test/IDE/CodeGeneration/MigrationGenerator.hs +++ b/Test/IDE/CodeGeneration/MigrationGenerator.hs @@ -1258,6 +1258,20 @@ CREATE POLICY "Users can read and edit their own record" ON public.users USING ( let targetSchema = [] let migration = [] + diffSchemas targetSchema actualSchema `shouldBe` migration + + it "should ignore the large_pg_notifications table" do + let actualSchema = sql $ cs [plain| + CREATE UNLOGGED TABLE large_pg_notifications ( + id UUID DEFAULT uuid_generate_v4() PRIMARY KEY NOT NULL, + payload TEXT DEFAULT null, + created_at TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL + ); + CREATE INDEX large_pg_notifications_created_at_index ON large_pg_notifications (created_at); + |] + let targetSchema = [] + let migration = [] + diffSchemas targetSchema actualSchema `shouldBe` migration sql :: Text -> [Statement] sql code = case Megaparsec.runParser Parser.parseDDL "" code of