glebpom-db-charmer 1.4.0 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/db-charmer.gemspec +2 -2
- data/lib/db_charmer.rb +1 -1
- data/lib/db_charmer/active_record_extensions.rb +5 -5
- data/lib/db_charmer/multi_db_migrations.rb +20 -33
- data/lib/db_charmer/multi_db_proxy.rb +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.4.
|
1
|
+
1.4.2
|
data/db-charmer.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glebpom-db-charmer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Kovyrin
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-
|
13
|
+
date: 2009-10-01 00:00:00 +04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
data/lib/db_charmer.rb
CHANGED
@@ -59,7 +59,7 @@ require 'db_charmer/multi_db_migrations'
|
|
59
59
|
require 'db_charmer/multi_db_proxy'
|
60
60
|
|
61
61
|
# Enable multi-db migrations
|
62
|
-
ActiveRecord::Migration.extend(DbCharmer::MultiDbMigrations
|
62
|
+
ActiveRecord::Migration.extend(DbCharmer::MultiDbMigrations)
|
63
63
|
|
64
64
|
# Enable the magic
|
65
65
|
ActiveRecord::Base.extend(DbCharmer::DbMagic::ClassMethods)
|
@@ -61,12 +61,12 @@ module DbCharmer
|
|
61
61
|
|
62
62
|
#-----------------------------------------------------------------------------
|
63
63
|
def hijack_connection!
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
db_charmer_connection_proxy || super
|
64
|
+
return if self.respond_to?(:connection_with_magic)
|
65
|
+
class << self
|
66
|
+
def connection_with_magic
|
67
|
+
db_charmer_connection_proxy || connection_without_magic
|
69
68
|
end
|
69
|
+
alias_method_chain :connection, :magic
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -1,41 +1,28 @@
|
|
1
1
|
module DbCharmer
|
2
2
|
module MultiDbMigrations
|
3
|
-
|
4
|
-
abstract_class = true
|
5
|
-
hijack_connection!
|
6
|
-
end
|
7
|
-
|
8
|
-
module ClassMethods
|
9
|
-
def hijack_connection!
|
10
|
-
class << self
|
11
|
-
def connection
|
12
|
-
# puts "DEBUG: Retrieving migration connection"
|
13
|
-
MigrationAbstractClass.connection
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
3
|
+
@@multi_db_name = nil
|
17
4
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
old_proxy = MigrationAbstractClass.db_charmer_connection_proxy
|
22
|
-
MigrationAbstractClass.switch_connection_to(db_name, DbCharmer.migration_connections_should_exist?)
|
23
|
-
yield
|
24
|
-
ensure
|
25
|
-
announce "Checking all database connections"
|
26
|
-
ActiveRecord::Base.verify_active_connections!
|
27
|
-
announce "Switching connection back to default"
|
28
|
-
MigrationAbstractClass.switch_connection_to(old_proxy)
|
29
|
-
end
|
5
|
+
def migrate_with_db_wrapper(direction)
|
6
|
+
on_db(@@multi_db_name) { migrate_without_db_wrapper(direction) }
|
7
|
+
end
|
30
8
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
9
|
+
def on_db(db_name)
|
10
|
+
announce "Switching connection to #{db_name}"
|
11
|
+
old_proxy = ActiveRecord::Base.db_charmer_connection_proxy
|
12
|
+
ActiveRecord::Base.switch_connection_to(db_name, DbCharmer.migration_connections_should_exist?)
|
13
|
+
yield
|
14
|
+
ensure
|
15
|
+
announce "Checking all database connections"
|
16
|
+
ActiveRecord::Base.verify_active_connections!
|
17
|
+
announce "Switching connection back to default"
|
18
|
+
ActiveRecord::Base.switch_connection_to(old_proxy)
|
19
|
+
end
|
35
20
|
|
36
|
-
|
37
|
-
|
38
|
-
|
21
|
+
def db_magic(opts = {})
|
22
|
+
raise ArgumentError, "No connection name - no magic!" unless opts[:connection]
|
23
|
+
@@multi_db_name = opts[:connection]
|
24
|
+
class << self
|
25
|
+
alias_method_chain :migrate, :db_wrapper
|
39
26
|
end
|
40
27
|
end
|
41
28
|
end
|
@@ -38,7 +38,7 @@ module DbCharmer
|
|
38
38
|
module MasterSlaveClassMethods
|
39
39
|
def on_slave(con = nil, proxy_target = nil, &block)
|
40
40
|
con ||= db_charmer_random_slave
|
41
|
-
raise ArgumentError, "No slaves found in the class and no slave connection given"
|
41
|
+
raise ArgumentError, "No slaves found in the class and no slave connection given" if con.nil? && DbCharmer.switch_connection?
|
42
42
|
on_db(con, proxy_target, &block)
|
43
43
|
end
|
44
44
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glebpom-db-charmer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Kovyrin
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-
|
13
|
+
date: 2009-10-01 00:00:00 +04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|