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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: efd32f0437186abbe23bde74a36c059124592e49
4
- data.tar.gz: 848d77b215192dd19f7a5091225120fdfe7cba1b
3
+ metadata.gz: ce5783babc9113d0316026b66a1422a96197a3a6
4
+ data.tar.gz: 61c98174e4f294ec7b06153f5317d698c150b574
5
5
  SHA512:
6
- metadata.gz: c2080ba271e93150ddc91d790a109ced1258c1fea53a948f8a2661ef9e89ba34d05d1d081153793c10d1cd246b30ee6da15924d7cdf6fba1f4df5776ade9cd32
7
- data.tar.gz: ecfc897bedd8b7ccfc2e914db917f783b60256636c0aac57eae7f6e27152d94b96fd743b6b242470e4eaf29696ad86b0f97bbd16c55460361a112e17836bf85b
6
+ metadata.gz: 7fb064da5869d11381bed4badda210c0ea09eedde16a70ce1bae61a44f5f68fd34ecae1144cd6a9a6e5a10e5196b90fa3b5f541da5cbe21f75958579b1e9ad6a
7
+ data.tar.gz: b5756f721abc0b70b68c2aef1251ec7bdb6449c0dacee2cf005c891eb2602aa8e975a0e9b892a7b953544d47d4846a1cd2e38f86b5853eb655a7379319cf8836
@@ -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
@@ -1,3 +1,8 @@
1
+ ## 0.0.2
2
+
3
+ - Better configuration for SQLite
4
+ - Fixed issues with `db:schema:load` and `db:test:prepare`
5
+
1
6
  ## 0.0.1
2
7
 
3
8
  - First release
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 will run for the original database by default. To run commands for the new database, use the `DB` environment variable. For instance:
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
- Add to `config/puma.rb`
74
+ In `config/puma.rb`, add inside the `on_worker_boot` block
77
75
 
78
76
  ```ruby
79
- on_worker_boot do
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
- Add to `config/unicorn.rb`
82
+ In `config/unicorn.rb`, add inside the `before_fork` block
87
83
 
88
84
  ```ruby
89
- before_fork do |server, worker|
90
- CatalogRecord.connection.disconnect!
91
- end
85
+ CatalogRecord.connection.disconnect!
86
+ ```
92
87
 
93
- after_fork do |server, worker|
94
- CatalogRecord.establish_connection :"catalog_#{Rails.env}"
95
- end
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
- database: #{lower_name}_development
30
+ #{development_conf}
20
31
 
21
32
  #{name}_test:
22
33
  <<: *default
23
- database: #{lower_name}_test
34
+ #{test_conf}
24
35
 
25
36
  #{name}_production:
26
37
  <<: *default
27
- url: <%= ENV['#{lower_name.upcase}_DATABASE_URL'] %>
38
+ #{production_conf}
28
39
  "
29
40
  end
30
41
 
@@ -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::SchemaMigration.singleton_class.prepend Multiverse::SchemaMigration
43
+ ActiveRecord::Migrator.prepend Multiverse::Migrator
40
44
  ActiveRecord::SchemaDumper.singleton_class.prepend Multiverse::SchemaDumper
41
45
  end
@@ -1,15 +1,11 @@
1
1
  module Multiverse
2
2
  module DatabaseTasks
3
3
  def each_current_configuration(environment)
4
- if Multiverse.db
5
- environments = ["#{Multiverse.db}_#{environment}"]
6
- environments << "#{Multiverse.db}_test" if environment == "development"
7
- self.migrations_paths = Multiverse.migrate_path
8
- self.db_dir = Multiverse.db_dir
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 Migration
22
- def connection
23
- @connection || Multiverse.record_class.connection
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 SchemaMigration
42
+ module Connection
35
43
  def connection
36
44
  Multiverse.record_class.connection
37
45
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Multiverse
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "bundler"
25
25
  spec.add_development_dependency "rake"
26
26
  spec.add_development_dependency "minitest"
27
+ spec.add_development_dependency "sqlite3"
27
28
  end
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.1
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