Skip to content

Commit

Permalink
Ignore large_pg_notifications table in migrations. Fixes #1605
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed Feb 13, 2023
1 parent ad55c54 commit c9acf9c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
10 changes: 6 additions & 4 deletions IHP/IDE/CodeGen/MigrationGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions Test/IDE/CodeGeneration/MigrationGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c9acf9c

Please sign in to comment.