Commit 9569816
Migrate versions.object and versions.object_changes to JSON
Why these changes are being introduced:
The versions table, used by paper_trail, has two columns that use
YAML. PaperTrail prefers that these tables use JSON or JSONB.
In order to update paper_trail to the latest version, we need
either to update our config to use YAML.safe_load or migrate
the data to JSON.
Relevant ticket(s):
* https://mitlibraries.atlassian.net/browse/ETD-626
* https://mitlibraries.atlassian.net/browse/ETD-615
How this addresses that need:
This converts the columns to JSON as described here:
https://github.com/paper-trail-gem/paper_trail/blob/v14.0.0/README.md#6b-custom-serializer
Our migration uses `PaperTrail::Serializers::YAML.load`. This is
effectively the same as `YAML.safe_load`. `YAML.load`,
awhich is uggested in the readme, will no longer work due to a
long-running bug in Psych:
collectiveidea/audited#631
We are using JSON instead of JSONB for two reasons:
1. SQLite does not support JSONB, so our local environments will
differ from Heroku; and
2. We are not actively leveraging JSONB's performance advantages in
the codebase, so there is likely no functional difference.
Long-term, it's worth considering whether we should use postgres
locally, as this would support better dev/prod parity and allow us
to use psql features like JSONB with more confidence. We discussed
this briefly in a team meeting on 3/7/23 and decided that such a
change could bring value, but is not necessary at this time.
Side effects of this change:
* One test has been updated to accommodate a value that change from
a date to a string.
* We are adding some `yaml_column_permitted_classes` to our ActiveRecord
config. This is required to run the db migration because of the
aforementioned bug in Psych. I've added a comment to remove it once
this commit is deployed.
* The migration is relatively inefficient. However, we tested it
against a clone of our prod db and found that it completed in 83.12s,
which we find acceptable.
* Running db migrations sometimes incorrectly parses the
`null: false` param into its own column. This bug occurs despite
PaperTrail's claiming to have fixed it, and it's inconsistent
(it occurs when Adam runs the migrations, but not when Jeremy does).
There's not much we can do about this except to keep an eye on it
in the future.
co-authored-by: Jeremy Prevost <jprevost@mit.edu>1 parent d0a1017 commit 9569816
File tree
7 files changed
+44
-10
lines changed- config
- initializers
- db
- migrate
- test/integration/admin
7 files changed
+44
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
260 | | - | |
261 | | - | |
262 | | - | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
263 | 263 | | |
264 | 264 | | |
265 | 265 | | |
| |||
436 | 436 | | |
437 | 437 | | |
438 | 438 | | |
439 | | - | |
| 439 | + | |
440 | 440 | | |
441 | 441 | | |
442 | 442 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
22 | 32 | | |
23 | 33 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
Lines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
260 | 260 | | |
261 | 261 | | |
262 | 262 | | |
263 | | - | |
| 263 | + | |
264 | 264 | | |
265 | 265 | | |
266 | | - | |
267 | | - | |
268 | 266 | | |
| 267 | + | |
| 268 | + | |
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | | - | |
| 140 | + | |
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| |||
0 commit comments