mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
FIX: Handle enum types during database restore (#16624)
c1db9687
introduced an postgres enum type. Our database restore logic did not handle custom types correctly, and would therefore raise a 'type already exists' error when restoring any backup.
This commit adds restore handling for enums, mirroring the similar logic for tables and views.
This commit is contained in:
parent
ad293e510d
commit
b01b1570ab
|
@ -103,6 +103,15 @@ module BackupRestore
|
||||||
EXECUTE 'DROP VIEW IF EXISTS #{destination}.' || quote_ident(row.viewname) || ' CASCADE;';
|
EXECUTE 'DROP VIEW IF EXISTS #{destination}.' || quote_ident(row.viewname) || ' CASCADE;';
|
||||||
EXECUTE 'ALTER VIEW #{source}.' || quote_ident(row.viewname) || ' SET SCHEMA #{destination};';
|
EXECUTE 'ALTER VIEW #{source}.' || quote_ident(row.viewname) || ' SET SCHEMA #{destination};';
|
||||||
END LOOP;
|
END LOOP;
|
||||||
|
-- move all <source> enums to <destination> enums
|
||||||
|
FOR row IN (
|
||||||
|
SELECT typname FROM pg_type t
|
||||||
|
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
|
||||||
|
WHERE typcategory = 'E' AND n.nspname = '#{source}' AND pg_catalog.pg_get_userbyid(typowner) = '#{owner}'
|
||||||
|
) LOOP
|
||||||
|
EXECUTE 'DROP TYPE IF EXISTS #{destination}.' || quote_ident(row.typname) || ' CASCADE;';
|
||||||
|
EXECUTE 'ALTER TYPE #{source}.' || quote_ident(row.typname) || ' SET SCHEMA #{destination};';
|
||||||
|
END LOOP;
|
||||||
END$$;
|
END$$;
|
||||||
SQL
|
SQL
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user