Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use tsql-ttds for structure_load (fixes #956) #957

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/active_record/tasks/sqlserver_database_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,25 @@ def structure_dump(filename, extra_flags)

dump = File.read(filename)
dump.gsub!(/^USE .*$\nGO\n/, "") # Strip db USE statements
dump.gsub!(/^GO\n/, "") # Strip db GO statements
dump.gsub!(/nvarchar\(8000\)/, "nvarchar(4000)") # Fix nvarchar(8000) column defs
dump.gsub!(/nvarchar\(-1\)/, "nvarchar(max)") # Fix nvarchar(-1) column defs
dump.gsub!(/text\(\d+\)/, "text") # Fix text(16) column defs
File.open(filename, "w") { |file| file.puts dump }
end

def structure_load(filename, extra_flags)
connection.execute File.read(filename)
server_arg = "-S #{Shellwords.escape(configuration_hash[:host])}"
server_arg += ":#{Shellwords.escape(configuration_hash[:port])}" if configuration_hash[:port]
command = [
"tsql-ttds",
server_arg,
"-D #{Shellwords.escape(configuration_hash[:database])}",
"-U #{Shellwords.escape(configuration_hash[:username])}",
"-P #{Shellwords.escape(configuration_hash[:password])}",
]

stdout_str, stderr_str, status = Open3.capture3(command.join(" "), stdin_data: File.read(filename))
raise "Error loading database: #{stderr_str}" unless status.exitstatus == 0
end

private
Expand Down