db-charmer 1.6.9 → 1.6.10
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.
- data/CHANGES +7 -0
- data/README.rdoc +9 -0
- data/VERSION +1 -1
- data/db-charmer.gemspec +2 -2
- data/lib/db_charmer.rb +3 -0
- data/lib/db_charmer/active_record_extensions.rb +2 -2
- data/lib/db_charmer/multi_db_migrations.rb +25 -10
- metadata +3 -3
data/CHANGES
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
1.6.10 (2010-04-09):
|
2
|
+
|
3
|
+
Multi-Db migrations changed. Now it is possible to call ActiveRecord::Migration.db_magic
|
4
|
+
and specify default migration connection that would be used by all migrations without
|
5
|
+
excplicitly switched connections.
|
6
|
+
|
7
|
+
----------------------------------------------------------------------------------------
|
1
8
|
1.6.9 (2010-04-08):
|
2
9
|
|
3
10
|
Bugfix release: now DbCharmer works without Rails.
|
data/README.rdoc
CHANGED
@@ -127,6 +127,15 @@ Migration class example (global connection rewrite, multiple connections with th
|
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
130
|
+
=== Default Migrations Connection
|
131
|
+
|
132
|
+
Starting with DbCharmer version 1.6.10 it is possible to call <tt>ActiveRecord::Migration.db_magic</tt>
|
133
|
+
and specify default migration connection that would be used by all migrations without
|
134
|
+
excplicitly switched connections. If you want to switch your migration to the default ActiveRecord
|
135
|
+
connection, just use <tt>db_magic :connection => :default</tt>.
|
136
|
+
|
137
|
+
=== Invalid Connection Names Handling
|
138
|
+
|
130
139
|
By default in all environments <tt>on_db</tt> and <tt>db_magic</tt> statments would fail if
|
131
140
|
specified connection does not exist in database.yml. It is possible to make +DbCharmer+
|
132
141
|
ignore such situations in non-production environments so that rails would create the tables
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.6.
|
1
|
+
1.6.10
|
data/db-charmer.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{db-charmer}
|
8
|
-
s.version = "1.6.
|
8
|
+
s.version = "1.6.10"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Alexey Kovyrin"]
|
12
|
-
s.date = %q{2010-04-
|
12
|
+
s.date = %q{2010-04-09}
|
13
13
|
s.description = %q{ActiveRecord Connections Magic (slaves, multiple connections, etc)}
|
14
14
|
s.email = %q{alexey@kovyrin.net}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/db_charmer.rb
CHANGED
@@ -4,10 +4,10 @@ module DbCharmer
|
|
4
4
|
|
5
5
|
def establish_real_connection_if_exists(name, should_exist = false)
|
6
6
|
name = name.to_s
|
7
|
-
config = configurations[
|
7
|
+
config = configurations[DbCharmer.env][name]
|
8
8
|
unless config
|
9
9
|
if should_exist
|
10
|
-
raise ArgumentError, "Invalid connection name (does not exist in database.yml): #{
|
10
|
+
raise ArgumentError, "Invalid connection name (does not exist in database.yml): #{DbCharmer.env}/#{name}"
|
11
11
|
end
|
12
12
|
return # No need to establish connection - they do not want us to
|
13
13
|
end
|
@@ -1,12 +1,31 @@
|
|
1
1
|
module DbCharmer
|
2
2
|
module MultiDbMigrations
|
3
|
-
|
3
|
+
def self.extended(base)
|
4
|
+
class << base
|
5
|
+
alias_method_chain :migrate, :db_wrapper
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
@@multi_db_names = {}
|
10
|
+
def multi_db_names
|
11
|
+
puts "Retrieving connections for #{self.name}"
|
12
|
+
@@multi_db_names[self.name] || @@multi_db_names['ActiveRecord::Migration']
|
13
|
+
end
|
14
|
+
|
15
|
+
def multi_db_names=(names)
|
16
|
+
puts "Setting connections for #{self.name}"
|
17
|
+
@@multi_db_names[self.name] = names
|
18
|
+
end
|
4
19
|
|
5
20
|
def migrate_with_db_wrapper(direction)
|
6
|
-
|
7
|
-
|
8
|
-
|
21
|
+
if names = multi_db_names
|
22
|
+
names.each do |multi_db_name|
|
23
|
+
on_db(multi_db_name) do
|
24
|
+
migrate_without_db_wrapper(direction)
|
25
|
+
end
|
9
26
|
end
|
27
|
+
else
|
28
|
+
migrate_without_db_wrapper(direction)
|
10
29
|
end
|
11
30
|
end
|
12
31
|
|
@@ -21,9 +40,8 @@ module DbCharmer
|
|
21
40
|
yield
|
22
41
|
ensure
|
23
42
|
# Switch it back
|
24
|
-
announce "Checking all database connections"
|
25
43
|
ActiveRecord::Base.verify_active_connections!
|
26
|
-
announce "Switching connection back
|
44
|
+
announce "Switching connection back"
|
27
45
|
ActiveRecord::Base.switch_connection_to(old_proxy)
|
28
46
|
end
|
29
47
|
|
@@ -37,10 +55,7 @@ module DbCharmer
|
|
37
55
|
raise ArgumentError, "No connection name - no magic!" unless conns.any?
|
38
56
|
|
39
57
|
# Save connections
|
40
|
-
|
41
|
-
class << self
|
42
|
-
alias_method_chain :migrate, :db_wrapper
|
43
|
-
end
|
58
|
+
self.multi_db_names = conns
|
44
59
|
end
|
45
60
|
|
46
61
|
# Return a list of connections to shards in a sharded connection
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 6
|
8
|
-
-
|
9
|
-
version: 1.6.
|
8
|
+
- 10
|
9
|
+
version: 1.6.10
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Alexey Kovyrin
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-09 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|