Class: AddSnapshotV2Columns
- Inherits:
-
Object
- Object
- AddSnapshotV2Columns
- Defined in:
- lib/generators/templates/snapshot_v2/add_snapshot_v2_columns.rb
Instance Method Summary collapse
Instance Method Details
#change ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/generators/templates/snapshot_v2/add_snapshot_v2_columns.rb', line 2 def change # PostgreSQL has jsonb (binary, indexable); SQLite (used by glib-web's dummy-app) and MySQL # only have json. Pick the richest type the adapter supports so consumers on PG get indexable # diffs while greenfield adopters on SQLite/MySQL still work without edits. diff_type = connection.adapter_name.match?(/PostgreSQL/i) ? :jsonb : :json change_table :snapshots, bulk: true do |t| t.string :action t.integer :version t.column :diff, diff_type t.string :source end add_index :snapshots, [:action, :item_type, :item_id] add_index :snapshots, [:item_type, :item_id, :version] end |