Skip to content

Commit

Permalink
Merge pull request #49772 from fatkodima/reload-type_map-for-enums
Browse files Browse the repository at this point in the history
Reload type map when creating or dropping PostgreSQL enums
  • Loading branch information
yahonda committed Oct 28, 2023
2 parents 421df52 + c4a6d13 commit 680f503
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Expand Up @@ -544,7 +544,7 @@ def create_enum(name, values, **options)
END
$$;
SQL
internal_exec_query(query)
internal_exec_query(query).tap { reload_type_map }
end

# Drops an enum type.
Expand All @@ -560,7 +560,7 @@ def drop_enum(name, values = nil, **options)
query = <<~SQL
DROP TYPE#{' IF EXISTS' if options[:if_exists]} #{quote_table_name(name)};
SQL
internal_exec_query(query)
internal_exec_query(query).tap { reload_type_map }
end

# Rename an existing enum type to something else.
Expand Down
Expand Up @@ -460,11 +460,18 @@ def test_raise_error_when_cannot_translate_exception

def test_reload_type_map_for_newly_defined_types
@connection.create_enum "feeling", ["good", "bad"]
result = @connection.select_all "SELECT 'good'::feeling"
assert_instance_of(PostgreSQLAdapter::OID::Enum,
result.column_types["feeling"])

# Runs only SELECT, no type map reloading.
assert_queries(1, ignore_none: true) do
result = @connection.select_all "SELECT 'good'::feeling"
assert_instance_of(PostgreSQLAdapter::OID::Enum,
result.column_types["feeling"])
end
ensure
@connection.drop_enum "feeling", if_exists: true
# Reloads type map.
assert_sql(/from pg_type/i) do
@connection.drop_enum "feeling", if_exists: true
end
reset_connection
end

Expand Down

0 comments on commit 680f503

Please sign in to comment.