class Create<%= migration_class_name %> < ActiveRecord::Migration
  def change
    create_table :<%= table_name %> do |t|
      t.string :to_state, null: false
      t.text :metadata<%= ", default: \"{}\"" unless mysql? %>
      t.integer :sort_key, null: false
      t.integer :<%= parent_id %>, null: false
      t.timestamps
    end

    add_index :<%= table_name %>, :<%= parent_id %>
    add_index :<%= table_name %>, [:sort_key, :<%= parent_id %>], unique: true
  end
end

class Create<%= migration_class_name %> < ActiveRecord::Migration
  def change
    create_table :<%= table_name %> do |t|
      t.string :to_state, null: false
      t.text :metadata<%= ", default: \"{}\"" unless mysql? %>
      t.integer :sort_key, null: false
      t.integer :<%= parent_id %>, null: false
      t.timestamps
    end

    add_index :<%= table_name %>, [:<%= parent_id %>, :sort_key], unique: true
  end
end

Optimize MySQL indexes for transition model
Optimize MySQL indexes for transition model

See https://github.com/gocardless/statesman/issues/59 for more details.