Skip to content

Commit 5433b5d

Browse files
Support custom primary key types in migration template
1 parent 09b062f commit 5433b5d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/generators/templates/create_rails_api_logger_table.rb.tt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
class CreateRailsApiLoggerTable < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
2+
<% pk_type = Rails.application.config.generators.options[:active_record].dig(:primary_key_type) %>
23
def change
3-
create_table :inbound_request_logs do |t|
4+
create_table :inbound_request_logs<%= ", id: :#{pk_type}" if pk_type %> do |t|
45
t.string :method
56
t.string :path
67
t.text :request_body
78
t.text :response_body
89
t.integer :response_code
910
t.timestamp :started_at
1011
t.timestamp :ended_at
11-
t.references :loggable, index: true, polymorphic: true
12+
t.references :loggable, index: true, polymorphic: true<%= ", type: :#{pk_type}" if pk_type %>
1213
t.timestamps null: false
1314
end
1415

15-
create_table :outbound_request_logs do |t|
16+
create_table :outbound_request_logs<%= ", id: :#{pk_type}" if pk_type %> do |t|
1617
t.string :method
1718
t.string :path
1819
t.text :request_body
1920
t.text :response_body
2021
t.integer :response_code
2122
t.timestamp :started_at
2223
t.timestamp :ended_at
23-
t.references :loggable, index: true, polymorphic: true
24+
t.references :loggable, index: true, polymorphic: true<%= ", type: :#{pk_type}" if pk_type %>
2425
t.timestamps null: false
2526
end
2627
end

0 commit comments

Comments
 (0)