|
| 1 | +# This migration creates the `versions` table, the only schema PT requires. |
| 2 | +# All other migrations PT provides are optional. |
| 3 | +class CreateVersions < ActiveRecord::Migration[7.1] |
| 4 | + |
| 5 | + # The largest text column available in all supported RDBMS is |
| 6 | + # 1024^3 - 1 bytes, roughly one gibibyte. We specify a size |
| 7 | + # so that MySQL will use `longtext` instead of `text`. Otherwise, |
| 8 | + # when serializing very large objects, `text` might not be big enough. |
| 9 | + TEXT_BYTES = 1_073_741_823 |
| 10 | + |
| 11 | + def change |
| 12 | + create_table :versions, id: :uuid do |t| |
| 13 | + t.string :item_type, null: false |
| 14 | + t.string :item_id, null: false |
| 15 | + t.string :event, null: false |
| 16 | + t.string :whodunnit |
| 17 | + # We're not using versioning, so exclude the original state by not having an options field (see docs) |
| 18 | + # t.json :object |
| 19 | + |
| 20 | + # Known issue in MySQL: fractional second precision |
| 21 | + # ------------------------------------------------- |
| 22 | + # |
| 23 | + # MySQL timestamp columns do not support fractional seconds unless |
| 24 | + # defined with "fractional seconds precision". MySQL users should manually |
| 25 | + # add fractional seconds precision to this migration, specifically, to |
| 26 | + # the `created_at` column. |
| 27 | + # (https://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html) |
| 28 | + # |
| 29 | + # MySQL users should also upgrade to at least rails 4.2, which is the first |
| 30 | + # version of ActiveRecord with support for fractional seconds in MySQL. |
| 31 | + # (https://github.com/rails/rails/pull/14359) |
| 32 | + # |
| 33 | + # MySQL users should use the following line for `created_at` |
| 34 | + # t.datetime :created_at, limit: 6 |
| 35 | + t.datetime :created_at |
| 36 | + end |
| 37 | + add_index :versions, %i[item_type item_id] |
| 38 | + end |
| 39 | +end |
0 commit comments