Skip to content

Chore/paper trail migration to jsonb columns#592

Merged
tsubik merged 3 commits intodevelopfrom
chore/paper-trail-jsonb
May 6, 2026
Merged

Chore/paper trail migration to jsonb columns#592
tsubik merged 3 commits intodevelopfrom
chore/paper-trail-jsonb

Conversation

@tsubik
Copy link
Copy Markdown
Collaborator

@tsubik tsubik commented Apr 16, 2026

Paper trail migration to JSONB columns for better performance and less problems in the future.

@tsubik tsubik force-pushed the chore/paper-trail-jsonb branch from 09b469f to 6c94c77 Compare April 16, 2026 09:45
@tsubik tsubik requested a review from santostiago April 16, 2026 09:50
Comment thread db/schema.rb
t.string "event", null: false
t.string "whodunnit"
t.text "object"
t.text "old_object"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a text field? 🤯

puts "Wrote tmp/data_migrations_report_mission_type_report.csv"
end

desc "Move PaperTrail versions from YAML to JSON columns."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh.. it was YAML. Then text field made sense.

attrs = {}
attrs[:object] = PaperTrail::Serializers::YAML.load(version.old_object) if version.old_object.present?
attrs[:object_changes] = PaperTrail::Serializers::YAML.load(version.old_object_changes) if version.old_object_changes.present?
version.update_columns(attrs) if for_real
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmmm.. ok... but this just keeps the old data in a new field.
Shouldn't we also migrate the old data into JSON and start using that field everywhere?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YAML loading will load to hash, and that will be saved in new object and object_changes fields as JSON.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then in the next PR, I will remove old fields.

@tsubik tsubik force-pushed the chore/paper-trail-jsonb branch from 6c94c77 to 7ef14d2 Compare May 5, 2026 13:17
@tsubik tsubik force-pushed the chore/paper-trail-jsonb branch from 08b2034 to af11062 Compare May 6, 2026 08:02
@tsubik tsubik merged commit 1ff987d into develop May 6, 2026
4 checks passed
@tsubik tsubik deleted the chore/paper-trail-jsonb branch May 6, 2026 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants