Skip to content

Commit fa6067d

Browse files
committed
Ensure Action Text migration use config set primary_key_type
Similar to: rails#42378 Tried adding test cases for the changes but migration file would always use id as primary_key_type and reference type as foreign_key_type. Did not find any good way to assert the changes. Tested locally and following is the schema generated for Action Text migration if `primary_key_type: :uuid` ``` create_table "action_text_rich_texts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name", null: false t.text "body" t.string "record_type", null: false t.uuid "record_id", null: false t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true end ```
1 parent 8be6e7a commit fa6067d

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)