dotenv_rails_db_tasks_fix 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab842233cb330350cc2a4fa074cc42a313cc9520427768d6033c2bbf2aab67ba
4
- data.tar.gz: 53aa623b5c8e2f2e930c62377ec7206bbef0166009802934342b07afde348340
3
+ metadata.gz: 7cdbc7371e683a8fffbeb782c080b6e4a6eeb5b004c0ea9ecd20f6bf0ff33db9
4
+ data.tar.gz: eff0da22841e866e4c63dbb5d1c400a992e78c854c73dbcc7a6c61c35209e0e8
5
5
  SHA512:
6
- metadata.gz: fd703d7e2bbc0c48c57bc5d40b95976c420e2f0c276c8865570d03f4708aa9dac2f5de8bec39ba62a27425b67f598b56b63f6c2db72a697023051c54c5c0bc39
7
- data.tar.gz: 2381d0d03e5036c10574068d80c8eb1796a910a6a446ac0d94e8a3379dae1ee5c3ffd78485f7615cba5925ef1d5ad57d8913cfc87ad5cb3d216fdcbe093edccd
6
+ metadata.gz: adf98752b518ccf7d585951a420b7a2268cc8d6cd42c8b4253bae0ca138765185351042b6192ac6baa2300c8cfc6c2e2f69cdd9ca8cd33541b1d4c7680ff7e5b
7
+ data.tar.gz: f14069f3af974b9b23234310b782a7e38980287c146ebe1004dc7e3ac8019186466e42f45a78f9ec1d900bee306e0c5d62d576bf7db4a4f50ad34e5fb7fc2fce
data/.env.development CHANGED
@@ -1 +1 @@
1
- DB_DATABASE=development
1
+ DB_DATABASE=file:mem_db_development?mode=memory
data/.env.test CHANGED
@@ -1 +1 @@
1
- DB_DATABASE=test
1
+ DB_DATABASE=file:mem_db_test?mode=memory
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  #### Fix for the issue when ActiveRecord `rake db:*` tasks are magically executed in both developement and test environments, but environment variables loaded via `dotenv` are not picking up the change.
4
4
 
5
- *You are viewing the README of version [v0.2.0](https://github.com/thisismydesign/dotenv_rails_db_tasks_fix/releases/tag/v0.2.0). You can find other releases [here](https://github.com/thisismydesign/dotenv_rails_db_tasks_fix/releases).*
5
+ *You are viewing the README of version [v0.2.1](https://github.com/thisismydesign/dotenv_rails_db_tasks_fix/releases/tag/v0.2.1). You can find other releases [here](https://github.com/thisismydesign/dotenv_rails_db_tasks_fix/releases).*
6
6
 
7
7
  | Branch | Status |
8
8
  | ------ | ------ |
@@ -85,7 +85,7 @@ See also [this issue](https://github.com/thisismydesign/dotenv_rails_db_tasks_fi
85
85
  - Outside of `development` environment `DotenvRailsDbTasksFix.activate` will `raise` and will _not_ monkey patch
86
86
  - Database config is expected to reside in Rails default `#{DatabaseTasks.root}/config/database.yml` (if you're using Rails `DatabaseTasks.root == Rails.root`)
87
87
  - Requires ActiveRecord >= 5.1.5, ~> 5.1.6 (because there're slight differences in the private API, althoguh following this solution it would be easy to extend support for other versions)
88
- - There's some weirdness with `Rails.env` vs `DatabaseTasks.env`. From trial-and-error it seems changing `DatabaseTasks.env` to reflect the current execution env will result in issues (with e.g. `db:setup` and `db:reset`), while changing `Rails.env` is actually required for `db:setup` to work correctly. [This fix](https://github.com/thisismydesign/dotenv_rails_db_tasks_fix/blob/be83ad6f97e4c1eb4bcfb5a2860eb3b53d7ff063/lib/dotenv_rails_db_tasks_fix.rb#L24-L28) seems to work for the use cases I tried but it's good to keep this in mind in case any similar issue presents.
88
+ - There's some weirdness with `Rails.env` vs `DatabaseTasks.env`. From trial-and-error it seems changing `DatabaseTasks.env` to reflect the current execution env will result in issues (with e.g. `db:setup` and `db:reset`), while changing `Rails.env` is actually required for `db:setup` to work correctly. [This fix](https://github.com/thisismydesign/dotenv_rails_db_tasks_fix/blob/v0.2.0/lib/dotenv_rails_db_tasks_fix.rb#L25-L29) seems to work for the use cases I tried but it's good to keep this in mind in case any similar issue presents. This might be due to this issue: https://github.com/rails/rails/issues/32910
89
89
  - If you introduce this to a project currently in use a final `db:environment:set` might be needed if prompted
90
90
 
91
91
  ## Installation
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
- require 'dotenv'
3
+ require "dotenv"
4
+ require "yaml"
5
+ require "erb"
4
6
 
5
7
  require_relative "lib/dotenv_rails_db_tasks_fix"
6
8
  require_relative "spec/support/active_record_tasks"
@@ -12,8 +14,17 @@ task :default => :spec
12
14
  RSPEC_ROOT = Pathname.new(File.dirname(__FILE__)).join("spec")
13
15
  environment = ENV["RAILS_ENV"] || "development"
14
16
  project_path = Pathname.new(RSPEC_ROOT).join("example_project")
17
+ class Seeder; def load_seed; end; end
18
+ # Root path has to be execution path, see: https://github.com/rails/rails/issues/32910
19
+ # Config is expected at `#{root}/config/database.yml`
20
+ # If the issue above is fixed it can be moved to `#{root}/spec/example_project/config/database.yml`
21
+ root = Pathname.new(".")
22
+ db_config = root.join("config", "database.yml")
23
+ db_dir = root.join("config")
15
24
 
16
25
  Dotenv.overload(".env", ".env.#{environment}", ".env.local", ".env.#{environment}.local")
17
- load_active_record_tasks(project_path: project_path, env: environment)
26
+ config = YAML::load(ERB.new(File.read(db_config)).result)
27
+
28
+ load_active_record_tasks(database_configuration: config, root: root, db_dir: db_dir, seed_loader: Seeder.new)
18
29
 
19
30
  DotenvRailsDbTasksFix.activate
@@ -0,0 +1,7 @@
1
+ development:
2
+ adapter: sqlite3
3
+ database: <%= ENV["DB_DATABASE"] %>
4
+
5
+ test:
6
+ adapter: sqlite3
7
+ database: <%= ENV["DB_DATABASE"] %>
data/config/schema.rb ADDED
File without changes
@@ -1,3 +1,3 @@
1
1
  module DotenvRailsDbTasksFix
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dotenv_rails_db_tasks_fix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - thisismydesign
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-14 00:00:00.000000000 Z
11
+ date: 2018-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -132,6 +132,8 @@ files:
132
132
  - Rakefile
133
133
  - bin/console
134
134
  - bin/setup
135
+ - config/database.yml
136
+ - config/schema.rb
135
137
  - dotenv_rails_db_tasks_fix.gemspec
136
138
  - lib/dotenv_rails_db_tasks_fix.rb
137
139
  - lib/dotenv_rails_db_tasks_fix/version.rb