Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload type map when creating or dropping PostgreSQL enums #49772

Merged
merged 1 commit into from Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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