Merge pull request #47791 from fatkodima/fix-dumping-enums-other-schemas

Fix dumping enum definitions from other schemas
This commit is contained in:
Eileen M. Uchitelle 2023-03-28 10:39:59 -04:00 committed by GitHub
commit 559c9ebcd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -494,6 +494,7 @@ module ActiveRecord
FROM pg_enum AS enum FROM pg_enum AS enum
JOIN pg_type AS type ON (type.oid = enum.enumtypid) JOIN pg_type AS type ON (type.oid = enum.enumtypid)
JOIN pg_namespace n ON type.typnamespace = n.oid JOIN pg_namespace n ON type.typnamespace = n.oid
WHERE n.nspname = ANY (current_schemas(false))
GROUP BY type.OID, n.nspname, type.typname; GROUP BY type.OID, n.nspname, type.typname;
SQL SQL

View File

@ -190,6 +190,9 @@ class PostgresqlEnumTest < ActiveRecord::PostgreSQLTestCase
end end
def test_schema_dump_scoped_to_schemas def test_schema_dump_scoped_to_schemas
@connection.create_schema("other_schema")
@connection.create_enum("other_schema.mood_in_other_schema", ["sad", "ok", "happy"])
with_test_schema("test_schema") do with_test_schema("test_schema") do
@connection.create_enum("mood_in_test_schema", ["sad", "ok", "happy"]) @connection.create_enum("mood_in_test_schema", ["sad", "ok", "happy"])
@connection.create_table("postgresql_enums_in_test_schema") do |t| @connection.create_table("postgresql_enums_in_test_schema") do |t|
@ -201,7 +204,10 @@ class PostgresqlEnumTest < ActiveRecord::PostgreSQLTestCase
assert_includes output, 'create_enum "public.mood", ["sad", "ok", "happy"]' assert_includes output, 'create_enum "public.mood", ["sad", "ok", "happy"]'
assert_includes output, 'create_enum "mood_in_test_schema", ["sad", "ok", "happy"]' assert_includes output, 'create_enum "mood_in_test_schema", ["sad", "ok", "happy"]'
assert_includes output, 't.enum "current_mood", enum_type: "mood_in_test_schema"' assert_includes output, 't.enum "current_mood", enum_type: "mood_in_test_schema"'
assert_not_includes output, 'create_enum "other_schema.mood_in_other_schema"'
end end
ensure
@connection.drop_schema("other_schema")
end end
def test_schema_load_scoped_to_schemas def test_schema_load_scoped_to_schemas
@ -230,7 +236,7 @@ class PostgresqlEnumTest < ActiveRecord::PostgreSQLTestCase
def with_test_schema(name, drop: true) def with_test_schema(name, drop: true)
old_search_path = @connection.schema_search_path old_search_path = @connection.schema_search_path
@connection.create_schema(name) @connection.create_schema(name)
@connection.schema_search_path = name @connection.schema_search_path = "#{name}, public"
yield yield
ensure ensure
@connection.drop_schema(name) if drop @connection.drop_schema(name) if drop