From 6c849b430bbcd302a6c2dc5995b4940b47fa959b Mon Sep 17 00:00:00 2001 From: Ryan Wold <64987852+ryanwoldatwork@users.noreply.github.com> Date: Thu, 27 Feb 2025 09:42:55 -0800 Subject: [PATCH] migrate papertrail text columns to jsonb * ensure version changeset renders --- Gemfile.lock | 28 ++++++++--------- db/migrate/20250226221548_versions_json.rb | 36 ++++++++++++++++++++++ db/schema.rb | 10 +++--- spec/features/admin/websites_spec.rb | 8 +++++ 4 files changed, 64 insertions(+), 18 deletions(-) create mode 100644 db/migrate/20250226221548_versions_json.rb diff --git a/Gemfile.lock b/Gemfile.lock index 2641ea275..9a4dfcbd1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -103,7 +103,7 @@ GEM aes_key_wrap (1.1.0) ast (2.4.2) aws-eventstream (1.3.1) - aws-partitions (1.1052.0) + aws-partitions (1.1056.0) aws-record (2.13.2) aws-sdk-dynamodb (~> 1, >= 1.85.0) aws-sdk-core (3.219.0) @@ -115,7 +115,7 @@ GEM aws-sdk-dynamodb (1.129.0) aws-sdk-core (~> 3, >= 3.210.0) aws-sigv4 (~> 1.5) - aws-sdk-kms (1.98.0) + aws-sdk-kms (1.99.0) aws-sdk-core (~> 3, >= 3.216.0) aws-sigv4 (~> 1.5) aws-sdk-rails (4.1.0) @@ -129,7 +129,7 @@ GEM aws-sessionstore-dynamodb (~> 2) concurrent-ruby (~> 1.3, >= 1.3.1) railties (>= 7.0.0) - aws-sdk-s3 (1.181.0) + aws-sdk-s3 (1.182.0) aws-sdk-core (~> 3, >= 3.216.0) aws-sdk-kms (~> 1) aws-sigv4 (~> 1.5) @@ -228,7 +228,7 @@ GEM drb (2.2.1) dumb_delegator (1.1.0) erubi (1.13.1) - excon (1.2.3) + excon (1.2.4) factory_bot (6.5.1) activesupport (>= 6.1.0) factory_bot_rails (6.4.4) @@ -344,8 +344,8 @@ GEM mime-types (3.6.0) logger mime-types-data (~> 3.2015) - mime-types-data (3.2025.0204) - mini_magick (5.1.2) + mime-types-data (3.2025.0220) + mini_magick (5.2.0) benchmark logger mini_mime (1.1.5) @@ -491,7 +491,7 @@ GEM ffi (~> 1.0) rdoc (6.12.0) psych (>= 4.0.0) - redis (5.3.0) + redis (5.4.0) redis-client (>= 0.22.0) redis-client (0.23.2) connection_pool @@ -526,7 +526,7 @@ GEM rspec-support (3.13.2) rspec_junit_formatter (0.6.0) rspec-core (>= 2, < 4, != 2.12.0) - rubocop (1.72.2) + rubocop (1.73.0) json (~> 2.3) language_server-protocol (~> 3.17.0.2) lint_roller (~> 1.1.0) @@ -537,9 +537,9 @@ GEM rubocop-ast (>= 1.38.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 4.0) - rubocop-ast (1.38.0) + rubocop-ast (1.38.1) parser (>= 3.3.1.0) - rubocop-rails (2.30.1) + rubocop-rails (2.30.2) activesupport (>= 4.2.0) lint_roller (~> 1.1) rack (>= 1.1) @@ -564,7 +564,7 @@ GEM sprockets-rails tilt securerandom (0.4.1) - selenium-webdriver (4.28.0) + selenium-webdriver (4.29.1) base64 (~> 0.2) logger (~> 1.4) rexml (~> 3.2, >= 3.2.5) @@ -595,7 +595,7 @@ GEM ssrf_filter (1.2.0) stimulus-rails (1.3.4) railties (>= 6.0.0) - stringio (3.1.3) + stringio (3.1.5) thor (1.3.2) thread_safe (0.3.6) tilt (2.6.0) @@ -609,9 +609,9 @@ GEM unicode-emoji (~> 4.0, >= 4.0.4) unicode-emoji (4.0.4) uniform_notifier (1.16.0) - uri (1.0.2) + uri (1.0.3) useragent (0.16.11) - version_gem (1.1.4) + version_gem (1.1.6) virtus (2.0.0) axiom-types (~> 0.1) coercible (~> 1.0) diff --git a/db/migrate/20250226221548_versions_json.rb b/db/migrate/20250226221548_versions_json.rb new file mode 100644 index 000000000..2f94d9dd4 --- /dev/null +++ b/db/migrate/20250226221548_versions_json.rb @@ -0,0 +1,36 @@ + class SafeYAML + def self.load(string) + return {} if string.nil? + + YAML.safe_load( + string, + permitted_classes: [ + Time, + Date, + ActiveSupport::TimeWithZone, + ActiveSupport::TimeZone + ], + aliases: true + ) + end +end + +class VersionsJson < ActiveRecord::Migration[8.0] + def change + rename_column :versions, :object, :old_object + rename_column :versions, :object_changes, :old_object_changes + add_column :versions, :object, :jsonb + add_column :versions, :object_changes, :jsonb + + PaperTrail::Version.where.not(old_object: nil).in_batches(of: 500, start: 1) do |batch| + batch.each do |version| + version.update_columns( + object: SafeYAML.load(version.old_object), + old_object: nil, + object_changes: SafeYAML.load(version.old_object_changes), + old_object_changes: nil, + ) + end + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 23ff5f477..7c941841d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,9 +10,9 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.2].define(version: 2025_02_21_194420) do +ActiveRecord::Schema[8.0].define(version: 2025_02_26_221548) do # These are extensions that must be enabled in order to support this database - enable_extension "plpgsql" + enable_extension "pg_catalog.plpgsql" create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false @@ -720,9 +720,11 @@ t.bigint "item_id", null: false t.string "event", null: false t.string "whodunnit" - t.text "object" + t.text "old_object" t.datetime "created_at", precision: nil - t.text "object_changes" + t.text "old_object_changes" + t.jsonb "object" + t.jsonb "object_changes" t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id" end diff --git a/spec/features/admin/websites_spec.rb b/spec/features/admin/websites_spec.rb index bef5745fc..0927a1746 100644 --- a/spec/features/admin/websites_spec.rb +++ b/spec/features/admin/websites_spec.rb @@ -47,6 +47,14 @@ website.reload expect(website.versions.size).to eq(1) expect(website.versions.last.event).to eq('create') + + visit versions_admin_website_path(website) + expect(page).to have_content("Website #{website.domain} versions") + expect(page).to have_content("production_status") + expect(page).to have_content("in_development") + expect(page).to have_content("production_status") + expect(page).to have_content("site_owner_email") + expect(page).to have_content(website.site_owner_email) end end