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.boolean :most_recent<%= ", null: false" if database_supports_partial_indexes? %>
      t.timestamps null: false
    end

    add_foreign_key :<%= table_name %>, :<%= parent_table_name %>

    add_index(:<%= table_name %>,
              [:<%= parent_id %>, :sort_key],
              unique: true,
              name: "<%= index_name :parent_sort %>")
    add_index(:<%= table_name %>,
              [:<%= parent_id %>, :most_recent],
              unique: true,
              <%= "where: 'most_recent'," if database_supports_partial_indexes? %>
              name: "<%= index_name :parent_most_recent %>")
  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.boolean :most_recent<%= ", null: false" if database_supports_partial_indexes? %>
      t.timestamps null: false
    end

    # Foreign keys are optional, but highly recommended
    add_foreign_key :<%= table_name %>, :<%= parent_table_name %>

    add_index(:<%= table_name %>,
              [:<%= parent_id %>, :sort_key],
              unique: true,
              name: "<%= index_name :parent_sort %>")
    add_index(:<%= table_name %>,
              [:<%= parent_id %>, :most_recent],
              unique: true,
              <%= "where: 'most_recent'," if database_supports_partial_indexes? %>
              name: "<%= index_name :parent_most_recent %>")
  end
end

Add comment on foreign keys
Add comment on foreign keys
