Skip to content

Commit 7e80321

Browse files
migrate papertrail text columns to jsonb
2 parents a328d3e + 6c849b4 commit 7e80321

4 files changed

Lines changed: 64 additions & 18 deletions

File tree

Gemfile.lock

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ GEM
103103
aes_key_wrap (1.1.0)
104104
ast (2.4.2)
105105
aws-eventstream (1.3.1)
106-
aws-partitions (1.1052.0)
106+
aws-partitions (1.1056.0)
107107
aws-record (2.13.2)
108108
aws-sdk-dynamodb (~> 1, >= 1.85.0)
109109
aws-sdk-core (3.219.0)
@@ -115,7 +115,7 @@ GEM
115115
aws-sdk-dynamodb (1.129.0)
116116
aws-sdk-core (~> 3, >= 3.210.0)
117117
aws-sigv4 (~> 1.5)
118-
aws-sdk-kms (1.98.0)
118+
aws-sdk-kms (1.99.0)
119119
aws-sdk-core (~> 3, >= 3.216.0)
120120
aws-sigv4 (~> 1.5)
121121
aws-sdk-rails (4.1.0)
@@ -129,7 +129,7 @@ GEM
129129
aws-sessionstore-dynamodb (~> 2)
130130
concurrent-ruby (~> 1.3, >= 1.3.1)
131131
railties (>= 7.0.0)
132-
aws-sdk-s3 (1.181.0)
132+
aws-sdk-s3 (1.182.0)
133133
aws-sdk-core (~> 3, >= 3.216.0)
134134
aws-sdk-kms (~> 1)
135135
aws-sigv4 (~> 1.5)
@@ -228,7 +228,7 @@ GEM
228228
drb (2.2.1)
229229
dumb_delegator (1.1.0)
230230
erubi (1.13.1)
231-
excon (1.2.3)
231+
excon (1.2.4)
232232
factory_bot (6.5.1)
233233
activesupport (>= 6.1.0)
234234
factory_bot_rails (6.4.4)
@@ -344,8 +344,8 @@ GEM
344344
mime-types (3.6.0)
345345
logger
346346
mime-types-data (~> 3.2015)
347-
mime-types-data (3.2025.0204)
348-
mini_magick (5.1.2)
347+
mime-types-data (3.2025.0220)
348+
mini_magick (5.2.0)
349349
benchmark
350350
logger
351351
mini_mime (1.1.5)
@@ -491,7 +491,7 @@ GEM
491491
ffi (~> 1.0)
492492
rdoc (6.12.0)
493493
psych (>= 4.0.0)
494-
redis (5.3.0)
494+
redis (5.4.0)
495495
redis-client (>= 0.22.0)
496496
redis-client (0.23.2)
497497
connection_pool
@@ -526,7 +526,7 @@ GEM
526526
rspec-support (3.13.2)
527527
rspec_junit_formatter (0.6.0)
528528
rspec-core (>= 2, < 4, != 2.12.0)
529-
rubocop (1.72.2)
529+
rubocop (1.73.0)
530530
json (~> 2.3)
531531
language_server-protocol (~> 3.17.0.2)
532532
lint_roller (~> 1.1.0)
@@ -537,9 +537,9 @@ GEM
537537
rubocop-ast (>= 1.38.0, < 2.0)
538538
ruby-progressbar (~> 1.7)
539539
unicode-display_width (>= 2.4.0, < 4.0)
540-
rubocop-ast (1.38.0)
540+
rubocop-ast (1.38.1)
541541
parser (>= 3.3.1.0)
542-
rubocop-rails (2.30.1)
542+
rubocop-rails (2.30.2)
543543
activesupport (>= 4.2.0)
544544
lint_roller (~> 1.1)
545545
rack (>= 1.1)
@@ -564,7 +564,7 @@ GEM
564564
sprockets-rails
565565
tilt
566566
securerandom (0.4.1)
567-
selenium-webdriver (4.28.0)
567+
selenium-webdriver (4.29.1)
568568
base64 (~> 0.2)
569569
logger (~> 1.4)
570570
rexml (~> 3.2, >= 3.2.5)
@@ -595,7 +595,7 @@ GEM
595595
ssrf_filter (1.2.0)
596596
stimulus-rails (1.3.4)
597597
railties (>= 6.0.0)
598-
stringio (3.1.3)
598+
stringio (3.1.5)
599599
thor (1.3.2)
600600
thread_safe (0.3.6)
601601
tilt (2.6.0)
@@ -609,9 +609,9 @@ GEM
609609
unicode-emoji (~> 4.0, >= 4.0.4)
610610
unicode-emoji (4.0.4)
611611
uniform_notifier (1.16.0)
612-
uri (1.0.2)
612+
uri (1.0.3)
613613
useragent (0.16.11)
614-
version_gem (1.1.4)
614+
version_gem (1.1.6)
615615
virtus (2.0.0)
616616
axiom-types (~> 0.1)
617617
coercible (~> 1.0)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
class SafeYAML
2+
def self.load(string)
3+
return {} if string.nil?
4+
5+
YAML.safe_load(
6+
string,
7+
permitted_classes: [
8+
Time,
9+
Date,
10+
ActiveSupport::TimeWithZone,
11+
ActiveSupport::TimeZone
12+
],
13+
aliases: true
14+
)
15+
end
16+
end
17+
18+
class VersionsJson < ActiveRecord::Migration[8.0]
19+
def change
20+
rename_column :versions, :object, :old_object
21+
rename_column :versions, :object_changes, :old_object_changes
22+
add_column :versions, :object, :jsonb
23+
add_column :versions, :object_changes, :jsonb
24+
25+
PaperTrail::Version.where.not(old_object: nil).in_batches(of: 500, start: 1) do |batch|
26+
batch.each do |version|
27+
version.update_columns(
28+
object: SafeYAML.load(version.old_object),
29+
old_object: nil,
30+
object_changes: SafeYAML.load(version.old_object_changes),
31+
old_object_changes: nil,
32+
)
33+
end
34+
end
35+
end
36+
end

db/schema.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.2].define(version: 2025_02_21_194420) do
13+
ActiveRecord::Schema[8.0].define(version: 2025_02_26_221548) do
1414
# These are extensions that must be enabled in order to support this database
15-
enable_extension "plpgsql"
15+
enable_extension "pg_catalog.plpgsql"
1616

1717
create_table "active_storage_attachments", force: :cascade do |t|
1818
t.string "name", null: false
@@ -720,9 +720,11 @@
720720
t.bigint "item_id", null: false
721721
t.string "event", null: false
722722
t.string "whodunnit"
723-
t.text "object"
723+
t.text "old_object"
724724
t.datetime "created_at", precision: nil
725-
t.text "object_changes"
725+
t.text "old_object_changes"
726+
t.jsonb "object"
727+
t.jsonb "object_changes"
726728
t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id"
727729
end
728730

spec/features/admin/websites_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@
4747
website.reload
4848
expect(website.versions.size).to eq(1)
4949
expect(website.versions.last.event).to eq('create')
50+
51+
visit versions_admin_website_path(website)
52+
expect(page).to have_content("Website #{website.domain} versions")
53+
expect(page).to have_content("production_status")
54+
expect(page).to have_content("in_development")
55+
expect(page).to have_content("production_status")
56+
expect(page).to have_content("site_owner_email")
57+
expect(page).to have_content(website.site_owner_email)
5058
end
5159
end
5260

0 commit comments

Comments
 (0)