multiverse 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +14 -0
- data/CHANGELOG.md +5 -0
- data/README.md +12 -16
- data/lib/generators/multiverse/db_generator.rb +14 -3
- data/lib/multiverse.rb +5 -1
- data/lib/multiverse/patches.rb +21 -13
- data/lib/multiverse/railtie.rb +6 -0
- data/lib/multiverse/version.rb +1 -1
- data/multiverse.gemspec +1 -0
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce5783babc9113d0316026b66a1422a96197a3a6
|
4
|
+
data.tar.gz: 61c98174e4f294ec7b06153f5317d698c150b574
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fb064da5869d11381bed4badda210c0ea09eedde16a70ce1bae61a44f5f68fd34ecae1144cd6a9a6e5a10e5196b90fa3b5f541da5cbe21f75958579b1e9ad6a
|
7
|
+
data.tar.gz: b5756f721abc0b70b68c2aef1251ec7bdb6449c0dacee2cf005c891eb2602aa8e975a0e9b892a7b953544d47d4846a1cd2e38f86b5853eb655a7379319cf8836
|
data/.travis.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm: 2.4.2
|
3
|
+
gemfile:
|
4
|
+
- Gemfile
|
5
|
+
sudo: false
|
6
|
+
before_install: gem install bundler
|
7
|
+
script: bundle exec rake test
|
8
|
+
notifications:
|
9
|
+
email:
|
10
|
+
on_success: never
|
11
|
+
on_failure: change
|
12
|
+
env:
|
13
|
+
- RAILS_VERSION=5.1.4 RAILS_ENV=development
|
14
|
+
- RAILS_VERSION=5.0.6 RAILS_ENV=development
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -24,7 +24,7 @@ rails generate multiverse:db catalog
|
|
24
24
|
|
25
25
|
This generates `CatalogRecord` class for models to inherit from and adds configuration to `config/database.yml`. It also creates a `db/catalog` directory for migrations and `schema.rb` to live.
|
26
26
|
|
27
|
-
`rails` and `rake` commands
|
27
|
+
`rails` and `rake` commands run for the original database by default. To run commands for the new database, use the `DB` environment variable. For instance:
|
28
28
|
|
29
29
|
Create the database
|
30
30
|
|
@@ -65,34 +65,30 @@ class Product < CatalogRecord
|
|
65
65
|
end
|
66
66
|
```
|
67
67
|
|
68
|
-
## Seeds
|
69
|
-
|
70
|
-
Use `db/seeds.rb` for all databases
|
71
|
-
|
72
68
|
## Web Servers
|
73
69
|
|
70
|
+
For web servers that fork, be sure to reconnect after forking (just like you do with `ActiveRecord::Base`)
|
71
|
+
|
74
72
|
### Puma
|
75
73
|
|
76
|
-
|
74
|
+
In `config/puma.rb`, add inside the `on_worker_boot` block
|
77
75
|
|
78
76
|
```ruby
|
79
|
-
|
80
|
-
CatalogRecord.establish_connection :"catalog_#{Rails.env}"
|
81
|
-
end
|
77
|
+
CatalogRecord.establish_connection :"catalog_#{Rails.env}"
|
82
78
|
```
|
83
79
|
|
84
80
|
### Unicorn
|
85
81
|
|
86
|
-
|
82
|
+
In `config/unicorn.rb`, add inside the `before_fork` block
|
87
83
|
|
88
84
|
```ruby
|
89
|
-
|
90
|
-
|
91
|
-
end
|
85
|
+
CatalogRecord.connection.disconnect!
|
86
|
+
```
|
92
87
|
|
93
|
-
|
94
|
-
|
95
|
-
|
88
|
+
And inside the `after_fork` block
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
CatalogRecord.establish_connection :"catalog_#{Rails.env}"
|
96
92
|
```
|
97
93
|
|
98
94
|
## History
|
@@ -12,19 +12,30 @@ module Multiverse
|
|
12
12
|
|
13
13
|
template "record.rb", "app/models/#{lower_name}_record.rb"
|
14
14
|
|
15
|
+
case ActiveRecord::Base.connection_config[:adapter]
|
16
|
+
when "sqlite3"
|
17
|
+
development_conf = "database: db/#{lower_name}_development.sqlite3"
|
18
|
+
test_conf = "database: db/#{lower_name}_test.sqlite3"
|
19
|
+
production_conf = "database: db/#{lower_name}_production.sqlite3"
|
20
|
+
else
|
21
|
+
development_conf = "database: #{lower_name}_development"
|
22
|
+
test_conf = "database: #{lower_name}_development"
|
23
|
+
production_conf = "url: <%= ENV['#{lower_name.upcase}_DATABASE_URL'] %>"
|
24
|
+
end
|
25
|
+
|
15
26
|
append_to_file "config/database.yml" do
|
16
27
|
"
|
17
28
|
#{name}_development:
|
18
29
|
<<: *default
|
19
|
-
|
30
|
+
#{development_conf}
|
20
31
|
|
21
32
|
#{name}_test:
|
22
33
|
<<: *default
|
23
|
-
|
34
|
+
#{test_conf}
|
24
35
|
|
25
36
|
#{name}_production:
|
26
37
|
<<: *default
|
27
|
-
|
38
|
+
#{production_conf}
|
28
39
|
"
|
29
40
|
end
|
30
41
|
|
data/lib/multiverse.rb
CHANGED
@@ -30,12 +30,16 @@ module Multiverse
|
|
30
30
|
def migrate_path
|
31
31
|
"#{db_dir}/migrate"
|
32
32
|
end
|
33
|
+
|
34
|
+
def env(environment)
|
35
|
+
db ? "#{db}_#{environment}" : environment
|
36
|
+
end
|
33
37
|
end
|
34
38
|
end
|
35
39
|
|
36
40
|
ActiveSupport.on_load(:active_record) do
|
37
41
|
ActiveRecord::Tasks::DatabaseTasks.singleton_class.prepend Multiverse::DatabaseTasks
|
38
42
|
ActiveRecord::Migration.prepend Multiverse::Migration
|
39
|
-
ActiveRecord::
|
43
|
+
ActiveRecord::Migrator.prepend Multiverse::Migrator
|
40
44
|
ActiveRecord::SchemaDumper.singleton_class.prepend Multiverse::SchemaDumper
|
41
45
|
end
|
data/lib/multiverse/patches.rb
CHANGED
@@ -1,15 +1,11 @@
|
|
1
1
|
module Multiverse
|
2
2
|
module DatabaseTasks
|
3
3
|
def each_current_configuration(environment)
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
else
|
10
|
-
environments = [environment]
|
11
|
-
environments << "test" if environment == "development"
|
12
|
-
end
|
4
|
+
environments = [Multiverse.env(environment)]
|
5
|
+
environments << Multiverse.env("test") if environment == "development"
|
6
|
+
|
7
|
+
self.migrations_paths = Multiverse.migrate_path
|
8
|
+
self.db_dir = Multiverse.db_dir
|
13
9
|
|
14
10
|
configurations = ActiveRecord::Base.configurations.values_at(*environments)
|
15
11
|
configurations.compact.each do |configuration|
|
@@ -18,11 +14,23 @@ module Multiverse
|
|
18
14
|
end
|
19
15
|
end
|
20
16
|
|
21
|
-
module
|
22
|
-
def
|
23
|
-
|
17
|
+
module Migrator
|
18
|
+
def initialize(*_)
|
19
|
+
puts "Migrator#initialize"
|
20
|
+
# ActiveRecord::Migration#initialize calls
|
21
|
+
# ActiveRecord::SchemaMigration.create_table
|
22
|
+
# ActiveRecord::InternalMetadata.create_table
|
23
|
+
# which both inherit from ActiveRecord::Base
|
24
|
+
#
|
25
|
+
# We need to change this for migrations
|
26
|
+
# but not for db:schema:load (messes up multiverse test env otherwise)
|
27
|
+
ActiveRecord::SchemaMigration.singleton_class.prepend(Multiverse::Connection)
|
28
|
+
ActiveRecord::InternalMetadata.singleton_class.prepend(Multiverse::Connection)
|
29
|
+
super
|
24
30
|
end
|
31
|
+
end
|
25
32
|
|
33
|
+
module Migration
|
26
34
|
# TODO don't checkout main connection at all
|
27
35
|
def exec_migration(_, direction)
|
28
36
|
Multiverse.record_class.connection_pool.with_connection do |conn|
|
@@ -31,7 +39,7 @@ module Multiverse
|
|
31
39
|
end
|
32
40
|
end
|
33
41
|
|
34
|
-
module
|
42
|
+
module Connection
|
35
43
|
def connection
|
36
44
|
Multiverse.record_class.connection
|
37
45
|
end
|
data/lib/multiverse/railtie.rb
CHANGED
@@ -16,6 +16,12 @@ module Multiverse
|
|
16
16
|
ActiveRecord::Tasks::DatabaseTasks.migrations_paths = [Multiverse.migrate_path]
|
17
17
|
ActiveRecord::Tasks::DatabaseTasks.db_dir = [Multiverse.db_dir]
|
18
18
|
end
|
19
|
+
|
20
|
+
namespace :test do
|
21
|
+
task purge: %w(environment load_config check_protected_environments) do
|
22
|
+
ActiveRecord::Tasks::DatabaseTasks.purge ActiveRecord::Base.configurations[Multiverse.env("test")]
|
23
|
+
end
|
24
|
+
end
|
19
25
|
end
|
20
26
|
end
|
21
27
|
end
|
data/lib/multiverse/version.rb
CHANGED
data/multiverse.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multiverse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description:
|
70
84
|
email:
|
71
85
|
- andrew@chartkick.com
|
@@ -74,6 +88,7 @@ extensions: []
|
|
74
88
|
extra_rdoc_files: []
|
75
89
|
files:
|
76
90
|
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
77
92
|
- CHANGELOG.md
|
78
93
|
- Gemfile
|
79
94
|
- LICENSE.txt
|