From 9cb045f46f5113db2e05c5d7fdbf2132c8d437b2 Mon Sep 17 00:00:00 2001 From: gabrieljablonski Date: Fri, 17 Apr 2026 23:33:50 -0300 Subject: [PATCH] fix(installation_config): normalize legacy native-hash rows to YAML strings Some rows in installation_configs.serialized_value were written as native jsonb objects by older code paths, while the YAML coder expects JSON-encoded YAML strings. Reading the object-shaped rows raised "TypeError: no implicit conversion of Hash into String" in production after the upstream 4.13.0 merge. Convert every object-shaped row to the YAML-string shape the coder produces, so the stock serialize :serialized_value, coder: YAML, ... works for all rows without needing a custom coder. --- ...e_installation_config_serialized_values.rb | 25 +++++++++++++++++++ db/schema.rb | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20260418020000_normalize_installation_config_serialized_values.rb diff --git a/db/migrate/20260418020000_normalize_installation_config_serialized_values.rb b/db/migrate/20260418020000_normalize_installation_config_serialized_values.rb new file mode 100644 index 000000000..98b05779f --- /dev/null +++ b/db/migrate/20260418020000_normalize_installation_config_serialized_values.rb @@ -0,0 +1,25 @@ +class NormalizeInstallationConfigSerializedValues < ActiveRecord::Migration[7.1] + # Rails' YAML coder expects the jsonb column to hold a JSON-encoded YAML + # string. Some rows were written as native jsonb objects by older code paths, + # which raises "no implicit conversion of Hash into String" on read. Convert + # every `object`-shaped row to the YAML-string shape the coder produces. + def up + rows = execute( + "SELECT id, serialized_value FROM installation_configs WHERE jsonb_typeof(serialized_value) = 'object'" + ).to_a + + rows.each do |row| + hash = JSON.parse(row['serialized_value']).with_indifferent_access + yaml = YAML.dump(hash) + execute( + ActiveRecord::Base.sanitize_sql_array( + ['UPDATE installation_configs SET serialized_value = to_jsonb(?::text) WHERE id = ?', yaml, row['id']] + ) + ) + end + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/db/schema.rb b/db/schema.rb index 0fc367337..d3ab66a24 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2026_04_10_170003) do +ActiveRecord::Schema[7.1].define(version: 2026_04_18_020000) do # These extensions should be enabled to support this database enable_extension "pg_stat_statements" enable_extension "pg_trgm"