Skip to content

Commit 2b5a37a

Browse files
authored
Rails 6.1: fix rake task (#904)
* configuration_hash use symbols as keys * db_tasks.load_schema requires db_config object
1 parent c0f5f7b commit 2b5a37a

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

lib/active_record/tasks/sqlserver_database_tasks.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def initialize(configuration)
2424

2525
def create(master_established = false)
2626
establish_master_connection unless master_established
27-
connection.create_database configuration.database, configuration_hash.merge("collation" => default_collation)
27+
connection.create_database configuration.database, configuration_hash.merge(collation: default_collation)
2828
establish_connection configuration
2929
rescue ActiveRecord::StatementInvalid => e
3030
if /database .* already exists/i === e.message
@@ -54,14 +54,14 @@ def purge
5454
end
5555

5656
def structure_dump(filename, extra_flags)
57-
server_arg = "-S #{Shellwords.escape(configuration_hash['host'])}"
58-
server_arg += ":#{Shellwords.escape(configuration_hash['port'])}" if configuration_hash["port"]
57+
server_arg = "-S #{Shellwords.escape(configuration_hash[:host])}"
58+
server_arg += ":#{Shellwords.escape(configuration_hash[:port])}" if configuration_hash[:port]
5959
command = [
6060
"defncopy-ttds",
6161
server_arg,
62-
"-D #{Shellwords.escape(configuration_hash['database'])}",
63-
"-U #{Shellwords.escape(configuration_hash['username'])}",
64-
"-P #{Shellwords.escape(configuration_hash['password'])}",
62+
"-D #{Shellwords.escape(configuration_hash[:database])}",
63+
"-U #{Shellwords.escape(configuration_hash[:username])}",
64+
"-P #{Shellwords.escape(configuration_hash[:password])}",
6565
"-o #{Shellwords.escape(filename)}",
6666
]
6767
table_args = connection.tables.map { |t| Shellwords.escape(t) }
@@ -88,11 +88,11 @@ def structure_load(filename, extra_flags)
8888
attr_reader :configuration, :configuration_hash
8989

9090
def default_collation
91-
configuration_hash["collation"] || DEFAULT_COLLATION
91+
configuration_hash[:collation] || DEFAULT_COLLATION
9292
end
9393

9494
def establish_master_connection
95-
establish_connection configuration_hash.merge("database" => "master")
95+
establish_connection configuration_hash.merge(database: "master")
9696
end
9797
end
9898

test/cases/rake_test_sqlserver.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class SQLServerRakeTest < ActiveRecord::TestCase
1212
let(:new_database) { "activerecord_unittest_tasks" }
1313
let(:default_configuration) { ARTest.test_configuration_hashes["arunit"] }
1414
let(:configuration) { default_configuration.merge("database" => new_database) }
15+
let(:db_config) { ActiveRecord::Base.configurations.resolve(configuration) }
1516

1617
before { skip "on azure" if azure_skip }
1718
before { disconnect! unless azure_skip }
@@ -151,7 +152,7 @@ class SQLServerRakeStructureDumpLoadTest < SQLServerRakeTest
151152
_(filedata).must_match %r{CREATE TABLE dbo\.users}
152153
db_tasks.purge(configuration)
153154
_(connection.tables).wont_include "users"
154-
db_tasks.load_schema configuration, :sql, filename
155+
db_tasks.load_schema db_config, :sql, filename
155156
_(connection.tables).must_include "users"
156157
end
157158
end

0 commit comments

Comments
 (0)