multiverse 0.2.1 → 0.2.2

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: 365e44dc02e354cb81a8d5e8962c51ec0873e208e35be402d24ce5826aee5a54
4
- data.tar.gz: 262ca4346fcb9a9800cc5d8016860f64d9e88f0318cdde986626a09310a9a783
3
+ metadata.gz: 795bc91f0bfa9e597a580449331ac77509fdba477a0313b1c83e06b7f45d6ab0
4
+ data.tar.gz: 9d21f5ab4e0e6bcf1095e2d23d0f24cfd8e12ec8b7c4a2a2f0af04e5172f75b5
5
5
  SHA512:
6
- metadata.gz: aa190b450724f9aa7d2c0fbe21618eb2fe8acb4169886129a018a1d20bf2e888884f33d604cff01c9d60c0599f6c33453a900eb2e81067a3d7788ea904183819
7
- data.tar.gz: dde00c42005d41c515d0519719c7287d7bdd74fdbe66244167d772096928193a2d3cef51b057ba2af8695e00de8f98e6754784a1397ebb9448e0044c1e958738
6
+ metadata.gz: 90d731497ca6a7514321ee25ec50690b61132e514f1b7e26c38b7df6c4fc082a74ab9af662717e5c6e729ce11d19c74349856b92ffed0ab947f382ffea1a91e8
7
+ data.tar.gz: bc0bc7446fe753dcb4c64fabf3c557bab8aac44899283c713d33d17020e709c6eb87b2ef7606096821b73811d30eb0c85ca649eb36e1b51aaf4ea236048d751e
@@ -1,3 +1,7 @@
1
+ ## 0.2.2
2
+
3
+ - Raise error when DB specified not in `database.yml`
4
+
1
5
  ## 0.2.1
2
6
 
3
7
  - Added support for `config.paths["db"]`
@@ -1,4 +1,4 @@
1
- Copyright (c) 2017 Andrew Kane
1
+ Copyright (c) 2017-2019 Andrew Kane
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  :fire: Multiple databases for Rails
4
4
 
5
- One of the easiest ways to scale your database is to move large, infrequently-joined tables to a separate database. **ActiveRecord supports multiple databases, but Rails doesn’t provide a way to manage them.** Multiverse changes this.
5
+ **ActiveRecord supports multiple databases, but Rails < 6 doesn’t provide a way to manage them.** Multiverse changes this.
6
+
7
+ Plus, it’s easy to [upgrade to Rails 6](#upgrading-to-rails-6) when you get there.
6
8
 
7
9
  Works with Rails 4.2+
8
10
 
@@ -71,6 +73,8 @@ end
71
73
 
72
74
  ## Web Servers
73
75
 
76
+ *Only necessary in Rails < 5.2*
77
+
74
78
  For web servers that fork, be sure to reconnect after forking (just like you do with `ActiveRecord::Base`)
75
79
 
76
80
  ### Puma
@@ -99,7 +103,17 @@ CatalogRecord.establish_connection :"catalog_#{Rails.env}"
99
103
 
100
104
  ### Fixtures
101
105
 
102
- [Rails fixtures](http://guides.rubyonrails.org/testing.html#the-low-down-on-fixtures) work automatically.
106
+ [Rails fixtures](https://guides.rubyonrails.org/testing.html#the-low-down-on-fixtures) work automatically.
107
+
108
+ **Note:** Referential integrity is not disabled on additional databases when fixtures are loaded, so you may run into issues if you use foreign keys. Also, you may run into errors with fixtures if the additional databases aren’t the same type as the primary.
109
+
110
+ ### RSpec
111
+
112
+ After running migrations for additional databases, run:
113
+
114
+ ```sh
115
+ DB=catalog rails db:test:prepare
116
+ ```
103
117
 
104
118
  ### Database Cleaner
105
119
 
@@ -115,6 +129,89 @@ end
115
129
 
116
130
  [Read more here](https://github.com/DatabaseCleaner/database_cleaner#how-to-use-with-multiple-orms)
117
131
 
132
+ ## Limitations
133
+
134
+ There are a few features that aren’t supported on additional databases.
135
+
136
+ - Pending migration check
137
+ - `schema_cache.yml`
138
+
139
+ Also note that `ActiveRecord::Migration.maintain_test_schema!` doesn’t affect additional databases.
140
+
141
+ ## Upgrading to Rails 6
142
+
143
+ Rails 6 provides a way to manage multiple databases :tada:
144
+
145
+ To upgrade from Multiverse, nest your database configuration in `config/database.yml`:
146
+
147
+ ```yml
148
+ # this should be similar to default, but with migrations_paths
149
+ catalog_default: &catalog_default
150
+ adapter: ...
151
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
152
+ migrations_paths: db/catalog_migrate
153
+
154
+ development:
155
+ primary:
156
+ <<: *default
157
+ database: ...
158
+ catalog:
159
+ <<: *catalog_default
160
+ database: ...
161
+
162
+ test:
163
+ primary:
164
+ <<: *default
165
+ database: ...
166
+ catalog:
167
+ <<: *catalog_default
168
+ database: ...
169
+
170
+ production:
171
+ primary:
172
+ <<: *default
173
+ database: ...
174
+ catalog:
175
+ <<: *catalog_default
176
+ database: ...
177
+ ```
178
+
179
+ Then change `establish_connection` in `app/models/catalog_record.rb` to:
180
+
181
+ ```rb
182
+ class CatalogRecord < ActiveRecord::Base
183
+ establish_connection :catalog
184
+ end
185
+ ```
186
+
187
+ And move:
188
+
189
+ - `db/catalog/migrate` to `db/catalog_migrate`
190
+ - `db/catalog/schema.rb` to `db/catalog_schema.rb` (or `db/catalog/structure.sql` to `db/catalog_structure.sql`).
191
+
192
+ Then remove `multiverse` from your Gemfile. :tada:
193
+
194
+ Now you can use the updated commands:
195
+
196
+ ```sh
197
+ rails db:migrate # run all
198
+ rails db:migrate:catalog # runs catalog only
199
+ ```
200
+
201
+ Generate migrations with:
202
+
203
+ ```sh
204
+ rails generate migration add_name_to_products --database=catalog
205
+ ```
206
+
207
+ And models with:
208
+
209
+ ```sh
210
+ rails generate model Product --database=catalog --parent=CatalogRecord
211
+ ```
212
+
213
+ Happy scaling!
214
+
118
215
  ## History
119
216
 
120
217
  View the [changelog](https://github.com/ankane/multiverse/blob/master/CHANGELOG.md)
@@ -36,7 +36,8 @@ module Multiverse
36
36
  new_config[env.sub("#{Multiverse.db}_", "")] = config
37
37
  end
38
38
  end
39
- ActiveRecord::Tasks::DatabaseTasks.database_configuration.merge!(new_config)
39
+ abort "Unknown DB: #{Multiverse.db}" if new_config.empty?
40
+ ActiveRecord::Tasks::DatabaseTasks.database_configuration = new_config
40
41
  end
41
42
 
42
43
  # load config
@@ -1,3 +1,3 @@
1
1
  module Multiverse
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multiverse
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-23 00:00:00.000000000 Z
11
+ date: 2019-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -109,28 +109,23 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description:
112
- email:
113
- - andrew@chartkick.com
112
+ email: andrew@chartkick.com
114
113
  executables: []
115
114
  extensions: []
116
115
  extra_rdoc_files: []
117
116
  files:
118
- - ".gitignore"
119
- - ".travis.yml"
120
117
  - CHANGELOG.md
121
- - Gemfile
122
118
  - LICENSE.txt
123
119
  - README.md
124
- - Rakefile
125
120
  - lib/generators/multiverse/db_generator.rb
126
121
  - lib/generators/multiverse/templates/record.rb.tt
127
122
  - lib/multiverse.rb
128
123
  - lib/multiverse/generators.rb
129
124
  - lib/multiverse/railtie.rb
130
125
  - lib/multiverse/version.rb
131
- - multiverse.gemspec
132
126
  homepage: https://github.com/ankane/multiverse
133
- licenses: []
127
+ licenses:
128
+ - MIT
134
129
  metadata: {}
135
130
  post_install_message:
136
131
  rdoc_options: []
@@ -140,15 +135,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
135
  requirements:
141
136
  - - ">="
142
137
  - !ruby/object:Gem::Version
143
- version: '0'
138
+ version: '2.2'
144
139
  required_rubygems_version: !ruby/object:Gem::Requirement
145
140
  requirements:
146
141
  - - ">="
147
142
  - !ruby/object:Gem::Version
148
143
  version: '0'
149
144
  requirements: []
150
- rubyforge_project:
151
- rubygems_version: 2.7.7
145
+ rubygems_version: 3.0.3
152
146
  signing_key:
153
147
  specification_version: 4
154
148
  summary: Multiple databases for Rails
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
- *.lock
@@ -1,20 +0,0 @@
1
- language: ruby
2
- rvm: 2.5.1
3
- gemfile:
4
- - Gemfile
5
- sudo: false
6
- before_install:
7
- - gem install bundler
8
- - unset RAILS_ENV
9
- - unset RACK_ENV
10
- script: bundle exec rake test
11
- notifications:
12
- email:
13
- on_success: never
14
- on_failure: change
15
- env:
16
- - RAILS_VERSION=5.2.1
17
- - RAILS_VERSION=5.2.1 API=t
18
- - RAILS_VERSION=5.1.6
19
- - RAILS_VERSION=5.0.7
20
- - RAILS_VERSION=4.2.10
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in multiverse.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1,10 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/*_test.rb"]
8
- end
9
-
10
- task :default => :test
@@ -1,30 +0,0 @@
1
-
2
- lib = File.expand_path("../lib", __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "multiverse/version"
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "multiverse"
8
- spec.version = Multiverse::VERSION
9
- spec.authors = ["Andrew Kane"]
10
- spec.email = ["andrew@chartkick.com"]
11
-
12
- spec.summary = "Multiple databases for Rails"
13
- spec.homepage = "https://github.com/ankane/multiverse"
14
-
15
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
- f.match(%r{^(test|spec|features)/})
17
- end
18
- spec.bindir = "exe"
19
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
- spec.require_paths = ["lib"]
21
-
22
- spec.add_dependency "activesupport", ">= 4.2"
23
- spec.add_dependency "activerecord", ">= 4.2"
24
- spec.add_dependency "railties", ">= 4.2"
25
-
26
- spec.add_development_dependency "bundler"
27
- spec.add_development_dependency "rake"
28
- spec.add_development_dependency "minitest"
29
- spec.add_development_dependency "sqlite3"
30
- end