public
Fork of rails/rails
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/nicksieger/rails.git
Search Repo:
Change all databases.rake adapter 'when' statements to use regexes.

This is more friendly to JRuby/JDBC adapters (with names like 'jdbcmysql')

and leaves the door open to alternate implementations of adapters in the
future.
nicksieger (author)
Tue Apr 15 06:39:30 -0700 2008
commit  d61c1ebb28d4292b87e85ccdba229a7a3c9a157c
tree    749a7623d543a41542a65698d34aac652ffc0f02
parent  2c96f509a8e630bcd0a79916ae7aadfe919b49a5
...
32
33
34
35
 
36
37
38
39
40
...
42
43
44
45
 
46
47
 
48
49
 
50
51
52
...
109
110
111
112
 
113
114
115
...
121
122
123
124
 
125
126
127
128
...
203
204
205
206
 
207
208
209
 
210
211
212
213
214
...
214
215
216
217
 
218
219
220
 
221
222
223
 
224
225
226
227
228
229
230
231
...
247
248
249
250
 
251
252
253
254
255
256
 
257
258
259
260
261
 
262
263
264
 
265
266
 
267
268
269
270
271
 
272
273
274
275
...
281
282
283
284
 
285
286
287
 
288
289
290
291
292
293
...
293
294
295
296
 
297
298
299
 
300
301
302
303
 
304
305
306
307
308
 
309
310
311
312
313
...
339
340
341
342
 
343
344
 
345
346
 
347
348
349
...
32
33
34
 
35
36
37
38
39
40
...
42
43
44
 
45
46
 
47
48
 
49
50
51
52
...
109
110
111
 
112
113
114
115
...
121
122
123
 
124
125
126
127
128
...
203
204
205
 
206
207
208
 
209
210
211
212
213
214
...
214
215
216
 
217
218
219
 
220
221
222
 
223
224
225
226
227
228
229
230
231
...
247
248
249
 
250
251
252
253
254
255
 
256
257
258
259
260
 
261
262
263
 
264
265
 
266
267
268
269
270
 
271
272
273
274
275
...
281
282
283
 
284
285
286
 
287
288
289
290
291
292
293
...
293
294
295
 
296
297
298
 
299
300
301
302
 
303
304
305
306
307
 
308
309
310
311
312
313
...
339
340
341
 
342
343
 
344
345
 
346
347
348
349
0
@@ -32,7 +32,7 @@
0
       ActiveRecord::Base.connection
0
     rescue
0
       case config['adapter']
0
- when 'mysql'
0
+ when /mysql/
0
         @charset = ENV['CHARSET'] || 'utf8'
0
         @collation = ENV['COLLATION'] || 'utf8_general_ci'
0
         begin
0
0
0
@@ -42,11 +42,11 @@
0
         rescue
0
           $stderr.puts "Couldn't create database for #{config.inspect}"
0
         end
0
- when 'postgresql'
0
+ when /postgresql/
0
         `createdb "#{config['database']}" -E utf8`
0
- when 'sqlite'
0
+ when /sqlite$/
0
         `sqlite "#{config['database']}"`
0
- when 'sqlite3'
0
+ when /sqlite3$/
0
         `sqlite3 "#{config['database']}"`
0
       end
0
     else
0
@@ -109,7 +109,7 @@
0
   task :charset => :environment do
0
     config = ActiveRecord::Base.configurations[RAILS_ENV || 'development']
0
     case config['adapter']
0
- when 'mysql'
0
+ when /mysql/
0
       ActiveRecord::Base.establish_connection(config)
0
       puts ActiveRecord::Base.connection.charset
0
     else
0
@@ -121,7 +121,7 @@
0
   task :collation => :environment do
0
     config = ActiveRecord::Base.configurations[RAILS_ENV || 'development']
0
     case config['adapter']
0
- when 'mysql'
0
+ when /mysql/
0
       ActiveRecord::Base.establish_connection(config)
0
       puts ActiveRecord::Base.connection.collation
0
     else
0
0
@@ -203,10 +203,10 @@
0
     task :dump => :environment do
0
       abcs = ActiveRecord::Base.configurations
0
       case abcs[RAILS_ENV]["adapter"]
0
- when "mysql", "oci", "oracle"
0
+ when /mysql/, /oci/, /oracle/
0
         ActiveRecord::Base.establish_connection(abcs[RAILS_ENV])
0
         File.open("db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
0
- when "postgresql"
0
+ when /postgresql/
0
         ENV['PGHOST'] = abcs[RAILS_ENV]["host"] if abcs[RAILS_ENV]["host"]
0
         ENV['PGPORT'] = abcs[RAILS_ENV]["port"].to_s if abcs[RAILS_ENV]["port"]
0
         ENV['PGPASSWORD'] = abcs[RAILS_ENV]["password"].to_s if abcs[RAILS_ENV]["password"]
0
0
0
@@ -214,13 +214,13 @@
0
         search_path = "--schema=#{search_path}" if search_path
0
         `pg_dump -i -U "#{abcs[RAILS_ENV]["username"]}" -s -x -O -f db/#{RAILS_ENV}_structure.sql #{search_path} #{abcs[RAILS_ENV]["database"]}`
0
         raise "Error dumping database" if $?.exitstatus == 1
0
- when "sqlite", "sqlite3"
0
+ when /sqlite/
0
         dbfile = abcs[RAILS_ENV]["database"] || abcs[RAILS_ENV]["dbfile"]
0
         `#{abcs[RAILS_ENV]["adapter"]} #{dbfile} .schema > db/#{RAILS_ENV}_structure.sql`
0
- when "sqlserver"
0
+ when /sqlserver/
0
         `scptxfr /s #{abcs[RAILS_ENV]["host"]} /d #{abcs[RAILS_ENV]["database"]} /I /f db\\#{RAILS_ENV}_structure.sql /q /A /r`
0
         `scptxfr /s #{abcs[RAILS_ENV]["host"]} /d #{abcs[RAILS_ENV]["database"]} /I /F db\ /q /A /r`
0
- when "firebird"
0
+ when /firebird/
0
         set_firebird_env(abcs[RAILS_ENV])
0
         db_string = firebird_db_string(abcs[RAILS_ENV])
0
         sh "isql -a #{db_string} > db/#{RAILS_ENV}_structure.sql"
0
0
0
0
0
0
@@ -247,28 +247,28 @@
0
     task :clone_structure => [ "db:structure:dump", "db:test:purge" ] do
0
       abcs = ActiveRecord::Base.configurations
0
       case abcs["test"]["adapter"]
0
- when "mysql"
0
+ when /mysql/
0
         ActiveRecord::Base.establish_connection(:test)
0
         ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0')
0
         IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table|
0
           ActiveRecord::Base.connection.execute(table)
0
         end
0
- when "postgresql"
0
+ when /postgresql/
0
         ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"]
0
         ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"]
0
         ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"]
0
         `psql -U "#{abcs["test"]["username"]}" -f db/#{RAILS_ENV}_structure.sql #{abcs["test"]["database"]}`
0
- when "sqlite", "sqlite3"
0
+ when /sqlite/
0
         dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"]
0
         `#{abcs["test"]["adapter"]} #{dbfile} < db/#{RAILS_ENV}_structure.sql`
0
- when "sqlserver"
0
+ when /sqlserver/
0
         `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql`
0
- when "oci", "oracle"
0
+ when /oci/, /oracle/
0
         ActiveRecord::Base.establish_connection(:test)
0
         IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split(";\n\n").each do |ddl|
0
           ActiveRecord::Base.connection.execute(ddl)
0
         end
0
- when "firebird"
0
+ when /firebird/
0
         set_firebird_env(abcs["test"])
0
         db_string = firebird_db_string(abcs["test"])
0
         sh "isql -i db/#{RAILS_ENV}_structure.sql #{db_string}"
0
0
@@ -281,10 +281,10 @@
0
     task :purge => :environment do
0
       abcs = ActiveRecord::Base.configurations
0
       case abcs["test"]["adapter"]
0
- when "mysql"
0
+ when /mysql/
0
         ActiveRecord::Base.establish_connection(:test)
0
         ActiveRecord::Base.connection.recreate_database(abcs["test"]["database"])
0
- when "postgresql"
0
+ when /postgresql/
0
         ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"]
0
         ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"]
0
         ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"]
0
0
0
0
@@ -293,19 +293,19 @@
0
         ActiveRecord::Base.clear_active_connections!
0
         `dropdb -U "#{abcs["test"]["username"]}" #{abcs["test"]["database"]}`
0
         `createdb #{enc_option} -U "#{abcs["test"]["username"]}" #{abcs["test"]["database"]}`
0
- when "sqlite","sqlite3"
0
+ when /sqlite/
0
         dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"]
0
         File.delete(dbfile) if File.exist?(dbfile)
0
- when "sqlserver"
0
+ when /sqlserver/
0
         dropfkscript = "#{abcs["test"]["host"]}.#{abcs["test"]["database"]}.DP1".gsub(/\\/,'-')
0
         `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{dropfkscript}`
0
         `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql`
0
- when "oci", "oracle"
0
+ when /oci/, /oracle/
0
         ActiveRecord::Base.establish_connection(:test)
0
         ActiveRecord::Base.connection.structure_drop.split(";\n\n").each do |ddl|
0
           ActiveRecord::Base.connection.execute(ddl)
0
         end
0
- when "firebird"
0
+ when /firebird/
0
         ActiveRecord::Base.establish_connection(:test)
0
         ActiveRecord::Base.connection.recreate_database!
0
       else
0
0
0
@@ -339,11 +339,11 @@
0
 
0
 def drop_database(config)
0
   case config['adapter']
0
- when 'mysql'
0
+ when /mysql/
0
     ActiveRecord::Base.connection.drop_database config['database']
0
- when /^sqlite/
0
+ when /sqlite/
0
     FileUtils.rm(File.join(RAILS_ROOT, config['database']))
0
- when 'postgresql'
0
+ when /postgresql/
0
     `dropdb "#{config['database']}"`
0
   end
0
 end

Comments

    No one has commented yet.