active_record_shards 3.12.0.beta2 → 3.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef4602ef8dd4f4da902671838cb3c81a9a894befc5ecf4f26679c637d934128e
4
- data.tar.gz: be495688e0eb5887a65bf0679c49b2befe0de4c1505bc6d9c7d91c02595b5c87
3
+ metadata.gz: 6473c94317dd18711d1434d23c44e283f90f572893e08e3f3a0e83737e8e6bd2
4
+ data.tar.gz: cea248a4cef9bc06c36b85f0ecf9dc25ba8fd2b5584d1b751c9d49c2977d74be
5
5
  SHA512:
6
- metadata.gz: e6a568a5e3f7894a9e64319acc93991bdcd01adae5852bbe19b4e599fe66d1648fd7e13b76530b45625d78c51ed9a95ad31c37b2f4f51f11c8221132626378bc
7
- data.tar.gz: 27a84cabdef6e4b5acaadd20a8c500e979548c103cd996d1e68198ecde2d5c021c2a66bef4f95b8acf74c1f4386295b058d15fd8d4e6bd81d55b2574ba795a47
6
+ metadata.gz: 18d9045c0a5e4f3c12339aec2815746e278a96fcd1c3f22ff406efc3a9f2d42282126861ad3e30885a90fab450603d1d69cd4d9e86f63b534057fa369460576f
7
+ data.tar.gz: aa397c8156aaf9bc71835c053ffe4dee7b1f2ceb9d5ad7e2d59b1f3354bf3d30b617c3df60815f82bdf67f728d1e88256853abe0fb57e3da3fca991bae047ab9
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Build Status](https://secure.travis-ci.org/zendesk/active_record_shards.png)](http://travis-ci.org/zendesk/active_record_shards)
1
+ [![CircleCI build status](https://circleci.com/gh/zendesk/active_record_shards/tree/master.svg?style=svg)](https://circleci.com/gh/zendesk/active_record_shards/tree/master)
2
2
 
3
3
  # ActiveRecord Shards
4
4
 
@@ -48,6 +48,11 @@ module ActiveRecordShards
48
48
  @@specification_cache ||= {}
49
49
  end
50
50
 
51
+ # Helper method to clear global state when testing.
52
+ def clear_specification_cache
53
+ @@specification_cache = {}
54
+ end
55
+
51
56
  def connection_pool_key
52
57
  specification_cache[connection_pool_name]
53
58
  end
@@ -9,6 +9,25 @@ module ActiveRecord
9
9
  end
10
10
  end
11
11
 
12
+ def initialize_with_sharding(*args)
13
+ initialize_without_sharding(*args)
14
+
15
+ # Rails creates the internal tables on the unsharded DB. We make them
16
+ # manually on the sharded DBs.
17
+ ActiveRecord::Base.on_all_shards do
18
+ if ActiveRecord::VERSION::MAJOR >= 4
19
+ ActiveRecord::SchemaMigration.create_table
20
+ else
21
+ ActiveRecord::Base.connection.initialize_schema_migrations_table
22
+ end
23
+ if ActiveRecord::VERSION::MAJOR >= 5
24
+ ActiveRecord::InternalMetadata.create_table
25
+ end
26
+ end
27
+ end
28
+ alias_method :initialize_without_sharding, :initialize
29
+ alias_method :initialize, :initialize_with_sharding
30
+
12
31
  def run_with_sharding
13
32
  ActiveRecord::Base.on_shard(nil) { run_without_sharding }
14
33
  ActiveRecord::Base.on_all_shards { run_without_sharding }
@@ -30,23 +30,19 @@ namespace :db do
30
30
  task create: :load_config do
31
31
  ActiveRecord::Base.configurations.each do |key, conf|
32
32
  next if !key.starts_with?(ActiveRecordShards.rails_env) || key.ends_with?("_slave")
33
- if ActiveRecord::VERSION::MAJOR >= 4
34
- begin
35
- # MysqlAdapter takes charset instead of encoding in Rails 4
36
- # https://github.com/rails/rails/commit/78b30fed9336336694fb2cb5d2825f95800b541c
37
- symbolized_configuration = conf.symbolize_keys
38
- symbolized_configuration[:charset] = symbolized_configuration[:encoding]
33
+ begin
34
+ # MysqlAdapter takes charset instead of encoding in Rails 3.2 or greater
35
+ # https://github.com/rails/rails/blob/3-2-stable/activerecord/lib/active_record/railties/databases.rake#L68-L82
36
+ symbolized_configuration = conf.symbolize_keys
37
+ symbolized_configuration[:charset] = symbolized_configuration[:encoding]
39
38
 
40
- ActiveRecordShards::Tasks.root_connection(conf).create_database(conf['database'], symbolized_configuration)
41
- rescue ActiveRecord::StatementInvalid => ex
42
- if ex.message.include?('database exists')
43
- puts "#{conf['database']} already exists"
44
- else
45
- raise ex
46
- end
39
+ ActiveRecordShards::Tasks.root_connection(conf).create_database(conf['database'], symbolized_configuration)
40
+ rescue ActiveRecord::StatementInvalid => ex
41
+ if ex.message.include?('database exists')
42
+ puts "#{conf['database']} already exists"
43
+ else
44
+ raise ex
47
45
  end
48
- else
49
- create_database(conf)
50
46
  end
51
47
  end
52
48
  ActiveRecord::Base.establish_connection(ActiveRecordShards.rails_env.to_sym)
@@ -56,16 +52,19 @@ namespace :db do
56
52
  task abort_if_pending_migrations: :environment do
57
53
  if defined? ActiveRecord
58
54
  pending_migrations =
59
- if Rails::VERSION::MAJOR >= 4
55
+ if ActiveRecord::VERSION::STRING >= "5.2.0"
56
+ migrations = ActiveRecord::MigrationContext.new(ActiveRecord::Migrator.migrations_paths).migrations
57
+ ActiveRecord::Migrator.new(:up, migrations).pending_migrations
58
+ elsif ActiveRecord::VERSION::MAJOR >= 4
60
59
  ActiveRecord::Base.on_shard(nil) { ActiveRecord::Migrator.open(ActiveRecord::Migrator.migrations_paths).pending_migrations }
61
60
  else
62
61
  ActiveRecord::Base.on_shard(nil) { ActiveRecord::Migrator.new(:up, 'db/migrate').pending_migrations }
63
62
  end
64
63
 
65
64
  if pending_migrations.any?
66
- puts "You have #{pending_migrations.size} pending migrations:"
65
+ $stderr.puts "You have #{pending_migrations.size} pending migrations:"
67
66
  pending_migrations.each do |pending_migration|
68
- puts ' %4d %s' % [pending_migration.version, pending_migration.name]
67
+ $stderr.puts ' %4d %s' % [pending_migration.version, pending_migration.name]
69
68
  end
70
69
  abort %(Run "rake db:migrate" to update your database then try again.)
71
70
  end
@@ -89,17 +88,24 @@ end
89
88
 
90
89
  module ActiveRecordShards
91
90
  module Tasks
92
- if ActiveRecord::VERSION::MAJOR < 5
93
- def self.root_connection(conf)
94
- ActiveRecord::Base.send("#{conf['adapter']}_connection", conf.merge('database' => nil))
95
- end
96
- else
97
- def self.root_connection(conf)
98
- # this will trigger rails to load the adapter
91
+ class << self
92
+ def root_connection(conf)
99
93
  conf = conf.merge('database' => nil)
100
- resolver = ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(ActiveRecord::Base.configurations)
101
- resolver.spec(conf)
102
- ActiveRecord::Base.send("#{conf['adapter']}_connection", conf)
94
+ spec = spec_for(conf)
95
+
96
+ ActiveRecord::Base.send("#{conf['adapter']}_connection", spec.config)
97
+ end
98
+
99
+ private
100
+
101
+ def spec_for(conf)
102
+ if ActiveRecord::VERSION::MAJOR >= 4
103
+ resolver = ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(ActiveRecord::Base.configurations)
104
+ resolver.spec(conf)
105
+ else
106
+ resolver = ActiveRecordShards::ConnectionSpecification::Resolver.new conf, ActiveRecord::Base.configurations
107
+ resolver.spec
108
+ end
103
109
  end
104
110
  end
105
111
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_shards
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.12.0.beta2
4
+ version: 3.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Quorning
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2018-06-14 00:00:00.000000000 Z
16
+ date: 2019-01-28 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: activerecord
@@ -55,20 +55,6 @@ dependencies:
55
55
  - - "<"
56
56
  - !ruby/object:Gem::Version
57
57
  version: '6.0'
58
- - !ruby/object:Gem::Dependency
59
- name: wwtd
60
- requirement: !ruby/object:Gem::Requirement
61
- requirements:
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- version: '0'
65
- type: :development
66
- prerelease: false
67
- version_requirements: !ruby/object:Gem::Requirement
68
- requirements:
69
- - - ">="
70
- - !ruby/object:Gem::Version
71
- version: '0'
72
58
  - !ruby/object:Gem::Dependency
73
59
  name: rake
74
60
  requirement: !ruby/object:Gem::Requirement
@@ -159,14 +145,14 @@ dependencies:
159
145
  requirements:
160
146
  - - ">="
161
147
  - !ruby/object:Gem::Version
162
- version: '0'
148
+ version: 1.4.0
163
149
  type: :development
164
150
  prerelease: false
165
151
  version_requirements: !ruby/object:Gem::Requirement
166
152
  requirements:
167
153
  - - ">="
168
154
  - !ruby/object:Gem::Version
169
- version: '0'
155
+ version: 1.4.0
170
156
  - !ruby/object:Gem::Dependency
171
157
  name: phenix
172
158
  requirement: !ruby/object:Gem::Requirement
@@ -228,12 +214,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
228
214
  version: '2.0'
229
215
  required_rubygems_version: !ruby/object:Gem::Requirement
230
216
  requirements:
231
- - - ">"
217
+ - - ">="
232
218
  - !ruby/object:Gem::Version
233
- version: 1.3.1
219
+ version: '0'
234
220
  requirements: []
235
- rubyforge_project:
236
- rubygems_version: 2.7.6
221
+ rubygems_version: 3.0.1
237
222
  signing_key:
238
223
  specification_version: 4
239
224
  summary: Simple database switching for ActiveRecord.