Sha256: 9deecd8912d7311a4163435290a50f67f1690ace5816160f044328eab4d49542

Contents?: true

Size: 1.26 KB

Versions: 33

Compression:

Stored size: 1.26 KB

Contents

class Create<%= migration_class_name %> < ActiveRecord::Migration<%= "[#{ActiveRecord::Migration.current_version}]" if Statesman::Utils.rails_5_or_higher? %>
  def change
    create_table :<%= table_name %> do |t|
      t.string :to_state, null: false
      t.text :metadata<%= ", default: #{metadata_default_value}" 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? %>

      # If you decide not to include an updated timestamp column in your transition
      # table, you'll need to configure the `updated_timestamp_column` setting in your
      # migration class.
      t.timestamps null: false
    end

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

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

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
statesman-12.1.0 lib/generators/statesman/templates/create_migration.rb.erb
statesman-12.0.0 lib/generators/statesman/templates/create_migration.rb.erb
statesman-11.0.0 lib/generators/statesman/templates/create_migration.rb.erb
statesman-10.2.3 lib/generators/statesman/templates/create_migration.rb.erb
statesman-10.2.2 lib/generators/statesman/templates/create_migration.rb.erb
statesman-10.2.1 lib/generators/statesman/templates/create_migration.rb.erb
statesman-10.2.0 lib/generators/statesman/templates/create_migration.rb.erb
statesman-10.1.0 lib/generators/statesman/templates/create_migration.rb.erb
statesman-10.0.0 lib/generators/statesman/templates/create_migration.rb.erb
statesman-9.0.1 lib/generators/statesman/templates/create_migration.rb.erb
statesman-9.0.0 lib/generators/statesman/templates/create_migration.rb.erb
statesman-8.0.3 lib/generators/statesman/templates/create_migration.rb.erb
statesman-8.0.2 lib/generators/statesman/templates/create_migration.rb.erb
statesman-8.0.1 lib/generators/statesman/templates/create_migration.rb.erb
statesman-8.0.0 lib/generators/statesman/templates/create_migration.rb.erb
statesman-7.4.1 lib/generators/statesman/templates/create_migration.rb.erb
statesman-7.4.0 lib/generators/statesman/templates/create_migration.rb.erb
statesman-7.3.0 lib/generators/statesman/templates/create_migration.rb.erb
statesman-7.2.0 lib/generators/statesman/templates/create_migration.rb.erb
statesman-7.1.0 lib/generators/statesman/templates/create_migration.rb.erb