Skip to content

Commit 30033e6

Browse files
authored
Merge pull request rails#42657 from abhaynikam/ensure-foreign-key-type-respect-generator-config
Ensure Action Text migration use config set primary_key_type
2 parents 91593af + fa6067d commit 30033e6

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
class CreateActionTextTables < ActiveRecord::Migration[6.0]
22
def change
3-
create_table :action_text_rich_texts do |t|
3+
# Use Active Record's configured type for primary and foreign keys
4+
primary_key_type, foreign_key_type = primary_and_foreign_key_types
5+
6+
create_table :action_text_rich_texts, id: primary_key_type do |t|
47
t.string :name, null: false
58
t.text :body, size: :long
6-
t.references :record, null: false, polymorphic: true, index: false
9+
t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type
710

811
t.timestamps
912

1013
t.index [ :record_type, :record_id, :name ], name: "index_action_text_rich_texts_uniqueness", unique: true
1114
end
1215
end
16+
17+
private
18+
def primary_and_foreign_key_types
19+
config = Rails.configuration.generators
20+
setting = config.options[config.orm][:primary_key_type]
21+
primary_key_type = setting || :primary_key
22+
foreign_key_type = setting || :bigint
23+
[primary_key_type, foreign_key_type]
24+
end
1325
end

0 commit comments

Comments
 (0)