-
Notifications
You must be signed in to change notification settings - Fork 891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support for dotenv using the -c config file option #1236
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1236 +/- ##
============================================
- Coverage 74.84% 74.62% -0.23%
- Complexity 0 1965 +1965
============================================
Files 35 54 +19
Lines 4783 5817 +1034
============================================
+ Hits 3580 4341 +761
- Misses 1203 1476 +273
Continue to review full report at Codecov.
|
composer.json
Outdated
@@ -27,7 +27,8 @@ | |||
"php": ">=5.4", | |||
"symfony/console": "~2.8|~3.0|~4.0", | |||
"symfony/config": "~2.8|~3.0|~4.0", | |||
"symfony/yaml": "~2.8|~3.0|~4.0" | |||
"symfony/yaml": "~2.8|~3.0|~4.0", | |||
"vlucas/phpdotenv": "^2.4" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cakephp skeleton app uses josegonzalez/dotenv
for providing dotenv support. While phinx is standalone lib it would be better if projects under the cakephp family used same external libs when possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. I didn't know that. I'll change this to use the josegonzalez/dotenv
library soon today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made this change. Went with "2.*" to be consistent with cakephp.
composer.json
Outdated
@@ -28,7 +28,7 @@ | |||
"symfony/console": "~2.8|~3.0|~4.0", | |||
"symfony/config": "~2.8|~3.0|~4.0", | |||
"symfony/yaml": "~2.8|~3.0|~4.0", | |||
"vlucas/phpdotenv": "^2.4" | |||
"josegonzalez/dotenv": "2.*" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not semver?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I picked this version to be consistent with the version used in cakephp/app.
Relates to #1085 |
Looks like we can move forward once the conflict is resolved 👍 |
@@ -36,3 +36,9 @@ phpunit.xml | |||
|
|||
# sqlite test database | |||
phinx_testing.sqlite3 | |||
|
|||
# ignore dotenv .env file | |||
.env |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this needed? shouldnt this only be relevant for project's config files, not for inside vendor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dotenv file (which is a config file) is typically placed in the root, and is ignored, because it will most likely be different in every environment an application is deployed to.
The .env.example is committed to give people a starting point. The naming of this file is also fairly standard across various project.
I'm not sure what you're asking about the vendor directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vendor/cakephp/phinx/.gitignore => this file
How does that relate to .env files that are in root dir?
Does this PR create a tmp .env file here in the plugin directly for testing etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for development of the project. if someone is working with phinx directly and using .env
files, then this is useful for them not accidentally committing local items.
The bit where cakephp puts it in a config directory is kinda silly - but hey, we listen to kooks all the time!
As far as users ignoring it in their projects, we should almost certainly just document that the file should be gitignored as a best practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
composer.json
Outdated
@@ -28,7 +28,8 @@ | |||
"php": ">=5.4", | |||
"symfony/console": "^2.8|^3.0|^4.0", | |||
"symfony/config": "^2.8|^3.0|^4.0", | |||
"symfony/yaml": "^2.8|^3.0|^4.0" | |||
"symfony/yaml": "^2.8|^3.0|^4.0", | |||
"josegonzalez/dotenv": "2.*" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does anyone think this should be require-dev as optional one for those that do not use/want it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The migrations will probably be run in every environment, not just while developing, right? In which case, I think this should be a requirement, not a dev requirement. Just my 2 cents but I maybe wrong in my understanding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A dev requirement (along with suggest text) means that the functionality is there but dormant.
Once you require it in your root level (project application), it then becomes a real functionality.
So no, this should be up to the dev IMO. Along with a documentation on how to enable this of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.
@@ -0,0 +1,38 @@ | |||
<?php | |||
|
|||
// copy this file to phinx.config.php, or your preferred name/location |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add the note here? composer require ... ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably add a note when installing the library somehow, though not sure where the best place for that would be.
@@ -33,7 +33,8 @@ | |||
"require-dev": { | |||
"phpunit/phpunit": "^4.8.35|^5.7|^6.5", | |||
"sebastian/comparator": ">=1.2.3", | |||
"cakephp/cakephp-codesniffer": "^3.0" | |||
"cakephp/cakephp-codesniffer": "^3.0", | |||
"josegonzalez/dotenv": "2.*" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be 3.x.
Needs docs. |
phinx.config.php.dist
Outdated
'environments' => [ | ||
'default_migration_table' => 'phinxlog', | ||
'default_database' => getenv('APP_ENV'), | ||
'develop' => [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should match the APP_ENV
value in .env.example - "development"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🏓
Closing due to no activity. |
Idea
phinx.yml
.configs/phinx.config.php
or anywhere, really.Usage
When running phinx at the command line, the -c or --configuration flag is used and the value is pointed at the phinx.config.php file, like so:
The
josegonzalez\Dotenv\Loader
class is only loaded in the configuration file, so if the configuration file is not used, that class won't be loaded.Again, the naming of the config file is merely a suggestion.
Note: Correct me if I'm wrong, but I don't think this needs any tests, since loading a config file is already tested. If it needs tests, I'll add them.