dotenv_rails_db_tasks_fix 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -4
- data/dotenv_rails_db_tasks_fix.gemspec +2 -2
- data/lib/dotenv_rails_db_tasks_fix.rb +10 -1
- data/lib/dotenv_rails_db_tasks_fix/version.rb +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8127fe472de6728fa0d18707961b69b73b4067866a2425f87a38eec321e46d47
|
4
|
+
data.tar.gz: 64028a6e992a511022449f0613a269b91efc2fbc697d98945c9a7ae8dd3e3f70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f36e0a137fe0a32359f56ca1ae097088dfc7f59c82c797996e880c28194f57e6b18676cf3982b465e3abe47d45e858087f996faf3e1d2e2e27af84141bb77f89
|
7
|
+
data.tar.gz: 1e86e695b50432c8e713d01ce857f84deaec78088e9a350c31a0542ae6faba894d111024f120178f4e89d63edce62ef7f50ce1f4fb8e2e034b91b287f6ccb417
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# DotenvRailsDbTasksFix
|
2
2
|
|
3
|
-
#### Fix for the issue when ActiveRecord `rake db:*` tasks are magically executed in both
|
3
|
+
#### Fix for the issue when ActiveRecord `rake db:*` tasks are magically executed in both development 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.
|
5
|
+
*You are viewing the README of version [v0.3.0](https://github.com/thisismydesign/dotenv_rails_db_tasks_fix/releases/tag/v0.3.0). You can find other releases [here](https://github.com/thisismydesign/dotenv_rails_db_tasks_fix/releases).*
|
6
6
|
|
7
7
|
| Branch | Status |
|
8
8
|
| ------ | ------ |
|
@@ -78,13 +78,16 @@ ActiveRecord has this feature that it executes DB tasks in `test` env as well if
|
|
78
78
|
|
79
79
|
Dotenv's recommendation is to use different env var names (e.g. `TEST_DB_NAME`, `DEVELOPMENT_DB_NAME`) but that would be counter-intuitive. Instead via this gem `ActiveRecord::Tasks::DatabaseTasks` is monkey patched to explicitly reload env vars and the DB config when it switches to test env. *This approach undoubtedly has its cons but in this case it only affects the development environment and restores the expected behaviour of this widely used feature therefore sparing the annoyance and possible effort of investigation.*
|
80
80
|
|
81
|
-
See also [this issue](https://github.com/
|
81
|
+
See also [this issue](https://github.com/rails/rails/issues/32926) and [this article](http://www.zhuwu.me/blog/posts/rake-db-tasks-always-runs-twice-in-development-environment).
|
82
|
+
|
83
|
+
## Version support
|
84
|
+
|
85
|
+
Supports `ActiveRecord` 5.0.0 - 5.2.0. For certain versions of ActiveRecord 4 you can explicitly set `RAILS_ENV` to `development` to avoid execution in `test` env ([see e.g. 4.2](https://github.com/rails/rails/blob/v4.2.0/activerecord/lib/active_record/tasks/database_tasks.rb#L271)).
|
82
86
|
|
83
87
|
## Caveats
|
84
88
|
|
85
89
|
- Outside of `development` environment `DotenvRailsDbTasksFix.activate` will `raise` and will _not_ monkey patch
|
86
90
|
- Database config is expected to reside in Rails default `#{DatabaseTasks.root}/config/database.yml` (if you're using Rails `DatabaseTasks.root == Rails.root`)
|
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
91
|
- 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
92
|
- If you introduce this to a project currently in use a final `db:environment:set` might be needed if prompted
|
90
93
|
|
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "dotenv"
|
22
|
-
spec.add_dependency "activerecord", ">= 5.
|
21
|
+
spec.add_dependency "dotenv", ">= 0.10.0" # `overload` introduced https://github.com/bkeepers/dotenv/commit/4cafc36c0c36a0eb243a37d2e18d26be3dab3d43#diff-299309060038a014968e16897bf9e21d
|
22
|
+
spec.add_dependency "activerecord", ">= 5.0.0", "<= 5.2.0"
|
23
23
|
|
24
24
|
spec.add_development_dependency "sqlite3"
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.16"
|
@@ -30,7 +30,16 @@ module DotenvRailsDbTasksFix
|
|
30
30
|
|
31
31
|
db_config = Pathname.new(self.root).join("config", "database.yml")
|
32
32
|
config = YAML::load(ERB.new(File.read(db_config)).result)
|
33
|
-
|
33
|
+
|
34
|
+
active_record_version = Gem::Version.new(ActiveRecord.version)
|
35
|
+
|
36
|
+
if active_record_version < Gem::Version.new("5.1.5")
|
37
|
+
# https://github.com/rails/rails/blob/v5.1.0/activerecord/lib/active_record/tasks/database_tasks.rb#L298-L306
|
38
|
+
yield config[environment] if config[environment]["database"]
|
39
|
+
else
|
40
|
+
# https://github.com/rails/rails/blob/v5.1.5/activerecord/lib/active_record/tasks/database_tasks.rb#L298-L307
|
41
|
+
yield config[environment], environment if config[environment]["database"]
|
42
|
+
end
|
34
43
|
end
|
35
44
|
end
|
36
45
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thisismydesign
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|
@@ -16,34 +16,34 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.10.0
|
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: 0.10.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 5.
|
34
|
-
- - "
|
33
|
+
version: 5.0.0
|
34
|
+
- - "<="
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: 5.
|
36
|
+
version: 5.2.0
|
37
37
|
type: :runtime
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: 5.
|
44
|
-
- - "
|
43
|
+
version: 5.0.0
|
44
|
+
- - "<="
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: 5.
|
46
|
+
version: 5.2.0
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: sqlite3
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|