feat: use config pk type in Action Mailbox migration
This commit is contained in:
parent
8049d7983f
commit
1df5ece43b
@ -1,3 +1,7 @@
|
||||
* Support configured primary key types in generated migrations.
|
||||
|
||||
*Nishiki Liu*
|
||||
|
||||
* Fixed ingress controllers' ability to accept emails that contain no UTF-8 encoded parts.
|
||||
|
||||
Fixes #46297.
|
||||
|
@ -1,6 +1,6 @@
|
||||
class CreateActionMailboxTables < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
create_table :action_mailbox_inbound_emails do |t|
|
||||
create_table :action_mailbox_inbound_emails, id: primary_key_type do |t|
|
||||
t.integer :status, default: 0, null: false
|
||||
t.string :message_id, null: false
|
||||
t.string :message_checksum, null: false
|
||||
@ -10,4 +10,10 @@ def change
|
||||
t.index [ :message_id, :message_checksum ], name: "index_action_mailbox_inbound_emails_uniqueness", unique: true
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def primary_key_type
|
||||
config = Rails.configuration.generators
|
||||
config.options[config.orm][:primary_key_type] || :primary_key
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
class CreateActionMailboxTables < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
create_table :action_mailbox_inbound_emails do |t|
|
||||
create_table :action_mailbox_inbound_emails, id: primary_key_type do |t|
|
||||
t.integer :status, default: 0, null: false
|
||||
t.string :message_id, null: false
|
||||
t.string :message_checksum, null: false
|
||||
@ -10,4 +10,10 @@ def change
|
||||
t.index [ :message_id, :message_checksum ], name: "index_action_mailbox_inbound_emails_uniqueness", unique: true
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def primary_key_type
|
||||
config = Rails.configuration.generators
|
||||
config.options[config.orm][:primary_key_type] || :primary_key
|
||||
end
|
||||
end
|
||||
|
52
actionmailbox/test/migrations_test.rb
Normal file
52
actionmailbox/test/migrations_test.rb
Normal file
@ -0,0 +1,52 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "test_helper"
|
||||
require ActionMailbox::Engine.root.join("db/migrate/20180917164000_create_action_mailbox_tables.rb").to_s
|
||||
|
||||
class ActionMailbox::MigrationsTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@original_verbose = ActiveRecord::Migration.verbose
|
||||
ActiveRecord::Migration.verbose = false
|
||||
|
||||
@connection = ActiveRecord::Base.connection
|
||||
@original_options = Rails.configuration.generators.options.deep_dup
|
||||
end
|
||||
|
||||
teardown do
|
||||
Rails.configuration.generators.options = @original_options
|
||||
rerun_migration
|
||||
ActiveRecord::Migration.verbose = @original_verbose
|
||||
end
|
||||
|
||||
test "migration creates tables with default primary key type" do
|
||||
action_mailbox_tables.each do |table|
|
||||
assert_equal :integer, primary_key(table).type
|
||||
end
|
||||
end
|
||||
|
||||
test "migration creates tables with configured primary key type" do
|
||||
Rails.configuration.generators do |g|
|
||||
g.orm :active_record, primary_key_type: :string
|
||||
end
|
||||
|
||||
rerun_migration
|
||||
|
||||
action_mailbox_tables.each do |table|
|
||||
assert_equal :string, primary_key(table).type
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def rerun_migration
|
||||
CreateActionMailboxTables.migrate(:down)
|
||||
CreateActionMailboxTables.migrate(:up)
|
||||
end
|
||||
|
||||
def action_mailbox_tables
|
||||
[:action_mailbox_inbound_emails]
|
||||
end
|
||||
|
||||
def primary_key(table)
|
||||
@connection.columns(table).find { |c| c.name == "id" }
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user