public
Fork of nicksieger/activerecord-jdbc-adapter
Description: ActiveRecord adapter for JDBC and JRuby
Homepage: http://jruby-extras.rubyforge.org/activerecord-jdbc-adapter
Clone URL: git://github.com/abedra/activerecord-jdbc-adapter.git
Search Repo:
temporary debugging modifications
abedra (author)
Mon May 12 07:25:39 -0700 2008
commit  49fcfff2d30f6ed6339f58484c297118484eaa9b
tree    1721914217dd9151864b075890b389b6f580effb
parent  ebd4c32571883dc13fdd26323bce4ddbdf66e03e
...
1
2
3
4
5
6
7
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
10
...
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
0
@@ -1,10 +1,84 @@
0
-if defined?(Rake.application) && Rake.application && ENV["SKIP_AR_JDBC_RAKE_REDEFINES"].nil?
0
- jdbc_rakefile = File.dirname(__FILE__) + "/jdbc.rake"
0
- if Rake.application.lookup("environment")
0
- # rails tasks already defined; load the override tasks now
0
- load jdbc_rakefile
0
- else
0
- # rails tasks not loaded yet; load as an import
0
- Rake.application.add_import(jdbc_rakefile)
0
+if defined?(namespace) && RUBY_PLATFORM =~ /java/ && ENV["SKIP_AR_JDBC_RAKE_REDEFINES"].nil?
0
+ def redefine_task(*args, &block)
0
+ task_name = Hash === args.first ? args.first.keys[0] : args.first
0
+ existing_task = Rake.application.lookup task_name
0
+ if existing_task
0
+ class << existing_task; public :instance_variable_set; end
0
+ existing_task.instance_variable_set "@prerequisites", FileList[]
0
+ existing_task.instance_variable_set "@actions", []
0
+ end
0
+ task(*args, &block)
0
+ end
0
+
0
+ namespace :db do
0
+ redefine_task :create => :environment do
0
+ create_database(ActiveRecord::Base.configurations[RAILS_ENV])
0
+ end
0
+
0
+ def create_database(config)
0
+ begin
0
+ ActiveRecord::Base.establish_connection(config)
0
+ ActiveRecord::Base.connection
0
+ rescue
0
+ begin
0
+ url = config['url']
0
+ if url
0
+ if url =~ /^(.*\/)/
0
+ url = $1
0
+ end
0
+ end
0
+
0
+ ActiveRecord::Base.establish_connection(config.merge({'database' => nil, 'url' => url}))
0
+ ActiveRecord::Base.connection.create_database(config['database'])
0
+ ActiveRecord::Base.establish_connection(config)
0
+ rescue
0
+ if (config['driver'] || config['adapter']) =~ /postgr/
0
+ `createdb "#{config['database']}" -E utf8`
0
+ else
0
+ warn "couldn't create database #{config['database']}"
0
+ end
0
+ end
0
+ end
0
+ end
0
+
0
+ redefine_task :drop => :environment do
0
+ begin
0
+ config = ActiveRecord::Base.configurations[environment_name]
0
+ ActiveRecord::Base.establish_connection(config)
0
+ db = ActiveRecord::Base.connection.database_name
0
+ ActiveRecord::Base.connection.recreate_database(db)
0
+ rescue
0
+ end
0
+ end
0
+
0
+ namespace :structure do
0
+ redefine_task :dump => :environment do
0
+ abcs = ActiveRecord::Base.configurations
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
+ if ActiveRecord::Base.connection.supports_migrations?
0
+ File.open("db/#{RAILS_ENV}_structure.sql", "a") { |f| f << ActiveRecord::Base.connection.dump_schema_information }
0
+ end
0
+ end
0
+ end
0
+
0
+ namespace :test do
0
+ redefine_task :clone_structure => [ "db:structure:dump", "db:test:purge" ] do
0
+ abcs = ActiveRecord::Base.configurations
0
+ ActiveRecord::Base.establish_connection(:test)
0
+ ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0') if abcs["test"]["adapter"] =~ /mysql/i
0
+ IO.readlines("db/#{RAILS_ENV}_structure.sql").join.split(";\n\n").each do |ddl|
0
+ puts "****** Executing #{ddl} *******"
0
+ ActiveRecord::Base.connection.execute(ddl)
0
+ end
0
+ end
0
+
0
+ redefine_task :purge => :environment do
0
+ abcs = ActiveRecord::Base.configurations
0
+ ActiveRecord::Base.establish_connection(:test)
0
+ db = ActiveRecord::Base.connection.database_name
0
+ ActiveRecord::Base.connection.recreate_database(db)
0
+ end
0
+ end
0
   end
0
 end

Comments

    No one has commented yet.