Skip to content

Commit

Permalink
FIX: Correctly handle materialized views during db restore (discourse…
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaylorhq authored Nov 1, 2023
1 parent 8887438 commit 85c2cc2
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/backup_restore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ def self.move_tables_between_schemas_sql(source, destination, owner)
EXECUTE 'DROP VIEW IF EXISTS #{destination}.' || quote_ident(row.viewname) || ' CASCADE;';
EXECUTE 'ALTER VIEW #{source}.' || quote_ident(row.viewname) || ' SET SCHEMA #{destination};';
END LOOP;
-- move all <source> materialized views to <destination> schema
FOR row IN SELECT matviewname FROM pg_matviews WHERE schemaname = '#{source}' AND matviewowner = '#{owner}'
LOOP
EXECUTE 'DROP MATERIALIZED VIEW IF EXISTS #{destination}.' || quote_ident(row.matviewname) || ' CASCADE;';
EXECUTE 'ALTER MATERIALIZED VIEW #{source}.' || quote_ident(row.matviewname) || ' SET SCHEMA #{destination};';
END LOOP;
-- move all <source> enums to <destination> enums
FOR row IN (
SELECT typname FROM pg_type t
Expand Down

0 comments on commit 85c2cc2

Please sign in to comment.