@@ -72,15 +72,27 @@ def structure_dump(filename, extra_flags)
72
72
73
73
dump = File . read ( filename )
74
74
dump . gsub! ( /^USE .*$\n GO\n / , "" ) # Strip db USE statements
75
- dump . gsub! ( /^GO\n / , "" ) # Strip db GO statements
75
+ # dump.gsub!(/^GO\n/, "") # Strip db GO statements
76
76
dump . gsub! ( /nvarchar\( 8000\) / , "nvarchar(4000)" ) # Fix nvarchar(8000) column defs
77
77
dump . gsub! ( /nvarchar\( -1\) / , "nvarchar(max)" ) # Fix nvarchar(-1) column defs
78
78
dump . gsub! ( /text\( \d +\) / , "text" ) # Fix text(16) column defs
79
79
File . open ( filename , "w" ) { |file | file . puts dump }
80
80
end
81
81
82
82
def structure_load ( filename , extra_flags )
83
- connection . execute File . read ( filename )
83
+ # connection.execute File.read(filename)
84
+ server_arg = "-S #{ Shellwords . escape ( configuration_hash [ :host ] ) } "
85
+ server_arg += ":#{ Shellwords . escape ( configuration_hash [ :port ] ) } " if configuration_hash [ :port ]
86
+ command = [
87
+ "tsql-ttds" ,
88
+ server_arg ,
89
+ "-D #{ Shellwords . escape ( configuration_hash [ :database ] ) } " ,
90
+ "-U #{ Shellwords . escape ( configuration_hash [ :username ] ) } " ,
91
+ "-P #{ Shellwords . escape ( configuration_hash [ :password ] ) } " ,
92
+ ]
93
+
94
+ stdout_str , stderr_str , status = Open3 . capture3 ( command . join ( " " ) , stdin_data : File . read ( filename ) )
95
+ raise "Error loading database: #{ stderr_str } " unless status . exitstatus == 0
84
96
end
85
97
86
98
private
0 commit comments