multiverse 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -3
- data/CHANGELOG.md +7 -0
- data/README.md +1 -1
- data/lib/multiverse.rb +4 -20
- data/lib/multiverse/generators.rb +6 -0
- data/lib/multiverse/railtie.rb +37 -36
- data/lib/multiverse/version.rb +1 -1
- data/multiverse.gemspec +3 -1
- metadata +33 -6
- data/lib/multiverse/patches.rb +0 -54
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4569d0c19e94ae2656d0b6bf1b83023c28a96d1
|
4
|
+
data.tar.gz: 696ab1dfa89bdffdfb4af49e2d6d7ac02f7a56ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed54801e4b6ed8992884635bcf5f638cd0c1b7140fc852e062b54290ab0af49b32d5a7c3ef6ea5fdc4706e7a20ccd7e08cea63a9906ba39c3486e0e20edc7357
|
7
|
+
data.tar.gz: a496c9ecbf793d6ee89b79df65b89d50a4ca8b818f79fad7eff152c60397347dec5df38561ae15cee7efe5c6a6751616682fb2f2410bfacce0d9c36926d609cd
|
data/.travis.yml
CHANGED
@@ -3,12 +3,17 @@ rvm: 2.4.2
|
|
3
3
|
gemfile:
|
4
4
|
- Gemfile
|
5
5
|
sudo: false
|
6
|
-
before_install:
|
6
|
+
before_install:
|
7
|
+
- gem install bundler
|
8
|
+
- unset RAILS_ENV
|
9
|
+
- unset RACK_ENV
|
7
10
|
script: bundle exec rake test
|
8
11
|
notifications:
|
9
12
|
email:
|
10
13
|
on_success: never
|
11
14
|
on_failure: change
|
12
15
|
env:
|
13
|
-
- RAILS_VERSION=5.
|
14
|
-
- RAILS_VERSION=5.
|
16
|
+
- RAILS_VERSION=5.2.0.rc1
|
17
|
+
- RAILS_VERSION=5.1.4
|
18
|
+
- RAILS_VERSION=5.0.6
|
19
|
+
- RAILS_VERSION=4.2.10
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
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.
|
6
6
|
|
7
|
-
Works with Rails
|
7
|
+
Works with Rails 4.2+
|
8
8
|
|
9
9
|
[![Build Status](https://travis-ci.org/ankane/multiverse.svg?branch=master)](https://travis-ci.org/ankane/multiverse)
|
10
10
|
|
data/lib/multiverse.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require "multiverse/generators"
|
2
|
-
require "multiverse/patches"
|
3
2
|
require "multiverse/railtie"
|
4
3
|
require "multiverse/version"
|
5
4
|
|
@@ -18,32 +17,17 @@ module Multiverse
|
|
18
17
|
end
|
19
18
|
|
20
19
|
def parent_class_name
|
21
|
-
db ? "#{db.camelize}Record" : "ApplicationRecord"
|
22
|
-
end
|
23
|
-
|
24
|
-
def record_class
|
25
20
|
if db
|
26
|
-
|
27
|
-
|
28
|
-
|
21
|
+
"#{db.camelize}Record"
|
22
|
+
elsif ActiveRecord::VERSION::MAJOR >= 5
|
23
|
+
"ApplicationRecord"
|
29
24
|
else
|
30
|
-
ActiveRecord::Base
|
25
|
+
"ActiveRecord::Base"
|
31
26
|
end
|
32
27
|
end
|
33
28
|
|
34
29
|
def migrate_path
|
35
30
|
"#{db_dir}/migrate"
|
36
31
|
end
|
37
|
-
|
38
|
-
def env(environment)
|
39
|
-
db ? "#{db}_#{environment}" : environment
|
40
|
-
end
|
41
32
|
end
|
42
33
|
end
|
43
|
-
|
44
|
-
ActiveSupport.on_load(:active_record) do
|
45
|
-
ActiveRecord::Tasks::DatabaseTasks.singleton_class.prepend Multiverse::DatabaseTasks
|
46
|
-
ActiveRecord::Migration.prepend Multiverse::Migration
|
47
|
-
ActiveRecord::Migrator.prepend Multiverse::Migrator
|
48
|
-
ActiveRecord::SchemaDumper.singleton_class.prepend Multiverse::SchemaDumper
|
49
|
-
end
|
@@ -11,5 +11,11 @@ module Multiverse
|
|
11
11
|
Multiverse.migrate_path
|
12
12
|
end
|
13
13
|
end
|
14
|
+
|
15
|
+
module MigrationTemplate
|
16
|
+
def migration_template(source, destination, config = {})
|
17
|
+
super(source, destination.sub("db/migrate", Multiverse.migrate_path), config)
|
18
|
+
end
|
19
|
+
end
|
14
20
|
end
|
15
21
|
end
|
data/lib/multiverse/railtie.rb
CHANGED
@@ -3,58 +3,59 @@ require "rails/railtie"
|
|
3
3
|
module Multiverse
|
4
4
|
class Railtie < Rails::Railtie
|
5
5
|
generators do
|
6
|
-
|
7
|
-
|
6
|
+
if ActiveRecord::VERSION::MAJOR >= 5
|
7
|
+
require "rails/generators/active_record/migration"
|
8
|
+
ActiveRecord::Generators::Migration.prepend(Multiverse::Generators::Migration)
|
9
|
+
else
|
10
|
+
require "rails/generators/migration"
|
11
|
+
Rails::Generators::Migration.prepend(Multiverse::Generators::MigrationTemplate)
|
12
|
+
end
|
8
13
|
|
9
14
|
require "rails/generators/active_record/model/model_generator"
|
10
15
|
ActiveRecord::Generators::ModelGenerator.prepend(Multiverse::Generators::ModelGenerator)
|
16
|
+
|
17
|
+
# for Rails < 5.0.3, need to patch db_migrate_path in model and migration generator
|
18
|
+
if ActiveRecord::VERSION::MAJOR == 5 && ActiveRecord.version < Gem::Version.new("5.0.3")
|
19
|
+
ActiveRecord::Generators::ModelGenerator.prepend(Multiverse::Generators::Migration)
|
20
|
+
|
21
|
+
require "rails/generators/active_record/migration/migration_generator"
|
22
|
+
ActiveRecord::Generators::MigrationGenerator.prepend(Multiverse::Generators::Migration)
|
23
|
+
end
|
11
24
|
end
|
12
25
|
|
13
26
|
rake_tasks do
|
14
|
-
namespace :
|
27
|
+
namespace :multiverse do
|
15
28
|
task :load_config do
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
ensure
|
28
|
-
if should_reconnect
|
29
|
-
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[Multiverse.env(ActiveRecord::Tasks::DatabaseTasks.env)])
|
29
|
+
if Multiverse.db
|
30
|
+
ActiveRecord::Tasks::DatabaseTasks.migrations_paths = [Multiverse.migrate_path]
|
31
|
+
ActiveRecord::Tasks::DatabaseTasks.db_dir = [Multiverse.db_dir]
|
32
|
+
Rails.application.paths["db/seeds.rb"] = ["#{Multiverse.db_dir}/seeds.rb"]
|
33
|
+
|
34
|
+
if ActiveRecord::Tasks::DatabaseTasks.database_configuration
|
35
|
+
new_config = {}
|
36
|
+
Rails.application.config.database_configuration.each do |env, config|
|
37
|
+
if env.start_with?("#{Multiverse.db}_")
|
38
|
+
new_config[env.sub("#{Multiverse.db}_", "")] = config
|
39
|
+
end
|
30
40
|
end
|
41
|
+
ActiveRecord::Tasks::DatabaseTasks.database_configuration.merge!(new_config)
|
31
42
|
end
|
32
|
-
end
|
33
43
|
|
34
|
-
|
35
|
-
ActiveRecord::
|
36
|
-
|
44
|
+
# load config
|
45
|
+
ActiveRecord::Base.configurations = ActiveRecord::Tasks::DatabaseTasks.database_configuration || {}
|
46
|
+
ActiveRecord::Migrator.migrations_paths = ActiveRecord::Tasks::DatabaseTasks.migrations_paths
|
47
|
+
|
48
|
+
ActiveRecord::Base.establish_connection
|
37
49
|
|
38
|
-
|
39
|
-
|
50
|
+
# need this to run again if environment is loaded afterwards
|
51
|
+
Rake::Task["db:load_config"].reenable
|
40
52
|
end
|
41
53
|
end
|
42
54
|
end
|
43
55
|
|
44
|
-
|
45
|
-
|
46
|
-
ActiveRecord::Base.establish_connection(Multiverse.record_class.connection_config)
|
47
|
-
end
|
48
|
-
|
49
|
-
task :override_config do
|
50
|
-
ActiveRecord::Tasks::DatabaseTasks.current_config = ActiveRecord::Base.configurations[Multiverse.env(ActiveRecord::Tasks::DatabaseTasks.env)]
|
51
|
-
end
|
56
|
+
Rake::Task["db:load_config"].enhance do
|
57
|
+
Rake::Task["multiverse:load_config"].execute
|
52
58
|
end
|
53
|
-
|
54
|
-
Rake::Task["db:migrate:status"].enhance ["multiverse:load_config"]
|
55
|
-
Rake::Task["db:structure:dump"].enhance ["multiverse:load_config", "multiverse:override_config"]
|
56
|
-
Rake::Task["db:schema:cache:dump"].enhance ["multiverse:load_config"]
|
57
|
-
Rake::Task["db:version"].enhance ["multiverse:load_config"]
|
58
59
|
end
|
59
60
|
end
|
60
61
|
end
|
data/lib/multiverse/version.rb
CHANGED
data/multiverse.gemspec
CHANGED
@@ -19,7 +19,9 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_dependency "
|
22
|
+
spec.add_dependency "activesupport", ">= 4.2"
|
23
|
+
spec.add_dependency "activerecord", ">= 4.2"
|
24
|
+
spec.add_dependency "railties", ">= 4.2"
|
23
25
|
|
24
26
|
spec.add_development_dependency "bundler"
|
25
27
|
spec.add_development_dependency "rake"
|
metadata
CHANGED
@@ -1,29 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multiverse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: railties
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.2'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: bundler
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,7 +126,6 @@ files:
|
|
98
126
|
- lib/generators/multiverse/templates/record.rb
|
99
127
|
- lib/multiverse.rb
|
100
128
|
- lib/multiverse/generators.rb
|
101
|
-
- lib/multiverse/patches.rb
|
102
129
|
- lib/multiverse/railtie.rb
|
103
130
|
- lib/multiverse/version.rb
|
104
131
|
- multiverse.gemspec
|
data/lib/multiverse/patches.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
module Multiverse
|
2
|
-
module DatabaseTasks
|
3
|
-
def each_current_configuration(environment)
|
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
|
9
|
-
|
10
|
-
configurations = ActiveRecord::Base.configurations.values_at(*environments)
|
11
|
-
configurations.compact.each do |configuration|
|
12
|
-
yield configuration unless configuration['database'].blank?
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
module Migrator
|
18
|
-
def initialize(*_)
|
19
|
-
# ActiveRecord::Migration#initialize calls
|
20
|
-
# ActiveRecord::SchemaMigration.create_table and
|
21
|
-
# ActiveRecord::InternalMetadata.create_table
|
22
|
-
# which both inherit from ActiveRecord::Base
|
23
|
-
#
|
24
|
-
# We need to change this for migrations
|
25
|
-
# but not for db:schema:load, as this
|
26
|
-
# will mess up the Multiverse test environment
|
27
|
-
ActiveRecord::SchemaMigration.singleton_class.prepend(Multiverse::Connection)
|
28
|
-
ActiveRecord::InternalMetadata.singleton_class.prepend(Multiverse::Connection)
|
29
|
-
super
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
module Connection
|
34
|
-
def connection
|
35
|
-
Multiverse.record_class.connection
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
module Migration
|
40
|
-
# TODO don't checkout main connection at all
|
41
|
-
def exec_migration(_, direction)
|
42
|
-
Multiverse.record_class.connection_pool.with_connection do |conn|
|
43
|
-
super(conn, direction)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
module SchemaDumper
|
49
|
-
def dump(connection = ActiveRecord::Base.connection, stream = STDOUT, config = ActiveRecord::Base)
|
50
|
-
new(Multiverse.record_class.connection, generate_options(Multiverse.record_class)).dump(stream)
|
51
|
-
stream
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|