1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actiontext/db/migrate/20180528164100_create_action_text_tables.rb

26 lines
912 B
Ruby
Raw Normal View History

2019-01-04 19:43:11 -05:00
class CreateActionTextTables < ActiveRecord::Migration[6.0]
2018-05-29 10:13:19 -04:00
def change
# Use Active Record's configured type for primary and foreign keys
primary_key_type, foreign_key_type = primary_and_foreign_key_types
create_table :action_text_rich_texts, id: primary_key_type do |t|
2018-05-29 10:13:19 -04:00
t.string :name, null: false
t.text :body, size: :long
t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type
2018-05-29 10:13:19 -04:00
t.timestamps
2018-05-29 10:13:19 -04:00
t.index [ :record_type, :record_id, :name ], name: "index_action_text_rich_texts_uniqueness", unique: true
end
end
private
def primary_and_foreign_key_types
config = Rails.configuration.generators
setting = config.options[config.orm][:primary_key_type]
primary_key_type = setting || :primary_key
foreign_key_type = setting || :bigint
[primary_key_type, foreign_key_type]
end
2018-05-29 10:13:19 -04:00
end