yam-db-charmer 1.7.01 → 1.7.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,115 @@
1
+
2
+ namespace :db_charmer do
3
+ namespace :test do
4
+
5
+ desc 'Reinitialize all test databases'
6
+ task :prepare => ['db:abort_if_pending_migrations', 'db:load_config'] do |t|
7
+ old_rails_env = Rails.env
8
+ Rails.env = 'test'
9
+ unless ActiveRecord::Base.schema_format==:sql
10
+ abort "db_charmer can only reset databases using sql, check config.active_record.schema_format"
11
+ end
12
+ Rake::Task['db_charmer:test:clone_structure'].invoke
13
+ Rails.env = old_rails_env
14
+ end
15
+
16
+ task :purge do
17
+ Rake::Task['db_charmer:drop'].invoke
18
+ Rake::Task['db_charmer:create'].invoke
19
+ end
20
+
21
+ task :dump_structure do
22
+ ::ActiveRecord::Base.configurations['development'].each_key do |name|
23
+ config = ::ActiveRecord::Base.configurations['development'][name]
24
+ next unless config.is_a?(Hash) && config['database']
25
+ # Only connect to local databases
26
+ local_database?(config) { dump_database_structure(name, config) }
27
+ end
28
+
29
+ config = ::ActiveRecord::Base.configurations['development']
30
+ local_database?(config) { dump_database_structure('main', config) }
31
+ end
32
+
33
+ # desc "Recreate the test databases from the development structure"
34
+ task :clone_structure => [ 'db_charmer:test:dump_structure', 'db_charmer:test:purge' ] do
35
+ ::ActiveRecord::Base.configurations['test'].each_key do |name|
36
+ config = ::ActiveRecord::Base.configurations['test'][name]
37
+ next unless config.is_a?(Hash) && config['database']
38
+ # Only connect to local databases
39
+ local_database?(config) { clone_database_structure(name, config) }
40
+ end
41
+ config = ::ActiveRecord::Base.configurations['test']
42
+ local_database?(config) { clone_database_structure('main', config) }
43
+ end
44
+
45
+ def dump_database_structure(name, config, origin_env='development')
46
+ return unless config.is_a?(Hash) && config['database']
47
+ structure_filename = "#{Rails.root}/db/#{origin_env}_#{name}_structure.sql"
48
+ case config["adapter"]
49
+ when /^(jdbc)?mysql/, "oci", "oracle"
50
+ ActiveRecord::Base.establish_connection(config)
51
+ File.open(structure_filename, "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
52
+ when /^(jdbc)?postgresql$/
53
+ ENV['PGHOST'] = config["host"] if config["host"]
54
+ ENV['PGPORT'] = config["port"].to_s if config["port"]
55
+ search_path = config["schema_search_path"]
56
+ unless search_path.blank?
57
+ search_path = search_path.split(",").map{|search_path| "--schema=#{search_path.strip}" }.join(" ")
58
+ end
59
+ cmd ="pg_dump -U #{config["username"]} -s -x -O -f db/#{origin_env}_#{name}_structure.sql #{search_path} #{config['database']}"
60
+ puts cmd
61
+ `#{cmd}`
62
+ raise "Error dumping database" if $?.exitstatus == 1
63
+ when /^(jdbc)?sqlite/
64
+ dbfile = config["database"] || config["dbfile"]
65
+ `sqlite3 #{dbfile} .schema > #{structure_filename}`
66
+ when "sqlserver"
67
+ `scptxfr /s #{config["host"]} /d #{config["database"]} /I /f db\\#{origin_env}_#{name}_structure.sql /q /A /r`
68
+ `scptxfr /s #{config["host"]} /d #{config["database"]} /I /F db\ /q /A /r`
69
+ when "firebird"
70
+ set_firebird_env(config)
71
+ db_string = firebird_db_string(config)
72
+ sh "isql -a #{db_string} > #{structure_filename}"
73
+ else
74
+ raise "Task not supported by '#{config["adapter"]}'"
75
+ end
76
+ end
77
+
78
+ def clone_database_structure(name, config, origin_env='development')
79
+ structure_filename = "#{Rails.root}/db/#{origin_env}_#{name}_structure.sql"
80
+ case config["adapter"]
81
+ when /^(jdbc)?mysql/
82
+ ActiveRecord::Base.establish_connection(:test)
83
+ ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0')
84
+ IO.readlines(structure_filename).join.split("\n\n").each do |table|
85
+ ActiveRecord::Base.connection.execute(table)
86
+ end
87
+ when /^(jdbc)?postgresql$/
88
+ ENV['PGHOST'] = config["host"] if config["host"]
89
+ ENV['PGPORT'] = config["port"].to_s if config["port"]
90
+ #ENV['PGPASSWORD'] = config["password"].to_s if config["password"]
91
+ cmd = "psql -U #{config["username"]} -f #{structure_filename} #{config["database"]}"
92
+ puts cmd
93
+ `#{cmd}`
94
+ when /^(jdbc)?sqlite/
95
+ dbfile = config["database"] || config["dbfile"]
96
+ `sqlite3 #{dbfile} < #{structure_filename}`
97
+ when "sqlserver"
98
+ `osql -E -S #{config["host"]} -d #{config["database"]} -i #{structure_filename}`
99
+ when "oci", "oracle"
100
+ ActiveRecord::Base.establish_connection(:test)
101
+ IO.readlines(structure_filename).join.split(";\n\n").each do |ddl|
102
+ ActiveRecord::Base.connection.execute(ddl)
103
+ end
104
+ when "firebird"
105
+ set_firebird_env(abcs["test"])
106
+ db_string = firebird_db_string(abcs["test"])
107
+ sh "isql -i #{structure_filename} #{db_string}"
108
+ else
109
+ raise "Task not supported by '#{config["adapter"]}'"
110
+ end
111
+
112
+ File.delete(structure_filename) if File.exist?(structure_filename)
113
+ end
114
+ end
115
+ end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yam-db-charmer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 119
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 7
9
- - 1
10
- version: 1.7.01
9
+ - 4
10
+ - 0
11
+ version: 1.7.4.0
11
12
  platform: ruby
12
13
  authors:
13
14
  - Oleksiy Kovyrin
@@ -16,7 +17,7 @@ autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2012-06-04 00:00:00 -07:00
20
+ date: 2012-09-18 00:00:00 -07:00
20
21
  default_executable:
21
22
  dependencies:
22
23
  - !ruby/object:Gem::Dependency
@@ -25,13 +26,13 @@ dependencies:
25
26
  requirement: &id001 !ruby/object:Gem::Requirement
26
27
  none: false
27
28
  requirements:
28
- - - <
29
+ - - ~>
29
30
  - !ruby/object:Gem::Version
30
- hash: 5
31
+ hash: 7
31
32
  segments:
32
33
  - 3
33
- - 1
34
- version: "3.1"
34
+ - 0
35
+ version: "3.0"
35
36
  type: :runtime
36
37
  version_requirements: *id001
37
38
  - !ruby/object:Gem::Dependency
@@ -40,13 +41,13 @@ dependencies:
40
41
  requirement: &id002 !ruby/object:Gem::Requirement
41
42
  none: false
42
43
  requirements:
43
- - - <
44
+ - - ~>
44
45
  - !ruby/object:Gem::Version
45
- hash: 5
46
+ hash: 7
46
47
  segments:
47
48
  - 3
48
- - 1
49
- version: "3.1"
49
+ - 0
50
+ version: "3.0"
50
51
  type: :runtime
51
52
  version_requirements: *id002
52
53
  - !ruby/object:Gem::Dependency
@@ -130,16 +131,22 @@ files:
130
131
  - lib/db_charmer/rails3/active_record/master_slave_routing.rb
131
132
  - lib/db_charmer/rails3/active_record/relation/connection_routing.rb
132
133
  - lib/db_charmer/rails3/active_record/relation_method.rb
134
+ - lib/db_charmer/rails31/active_record/migration/command_recorder.rb
135
+ - lib/db_charmer/rails31/active_record/preloader/association.rb
136
+ - lib/db_charmer/rails31/active_record/preloader/has_and_belongs_to_many.rb
133
137
  - lib/db_charmer/sharding.rb
134
138
  - lib/db_charmer/sharding/connection.rb
135
139
  - lib/db_charmer/sharding/method.rb
136
140
  - lib/db_charmer/sharding/method/db_block_group_map.rb
141
+ - lib/db_charmer/sharding/method/db_block_group_map_base.rb
137
142
  - lib/db_charmer/sharding/method/db_block_map.rb
143
+ - lib/db_charmer/sharding/method/db_block_schema_map.rb
138
144
  - lib/db_charmer/sharding/method/hash_map.rb
139
145
  - lib/db_charmer/sharding/method/range.rb
140
146
  - lib/db_charmer/sharding/stub_connection.rb
141
147
  - lib/db_charmer/version.rb
142
148
  - lib/tasks/databases.rake
149
+ - lib/tasks/test.rake
143
150
  has_rdoc: true
144
151
  homepage: http://kovyrin.github.com/db-charmer
145
152
  licenses: []