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

Open
wants to merge 7 commits into
base: master
from

Conversation

Projects
None yet
7 participants
@philsown

philsown commented Nov 5, 2017

Idea

  1. josegonzalez/dotenv is required from composer.json. The 2.* version was preferred to have consistency with the cakephp/app composer requirements.
  2. And .env.example file is included with example config variables. This would be copied to .env and edited by the developer
  3. A phinx.config.php.dist file is included with an example config array. This would be copied to phinx.config.php and edited by the developer to include config arrays for various environments, along with the default database config. This file references the getenv() function, so the values are read from .env. The array keys in this config file are the same as in phinx.yml.
  4. .gitignore has been updated to include .env and *.config.php files. The name .env is a standard name for the dotenv package. The phinx.config.php file could be named and placed anywhere. The .config.php extension is just a suggestion to make ignoring the config files easier. This file could be phinx.config.php in the root, or 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:

$ ./bin/phinx migrate  -e development -c phinx.config.php

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.

@codecov-io

This comment has been minimized.

Show comment
Hide comment
@codecov-io

codecov-io Nov 5, 2017

Codecov Report

Merging #1236 into master will decrease coverage by 0.04%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1236      +/-   ##
=========================================
- Coverage   74.84%   74.8%   -0.05%     
=========================================
  Files          35      35              
  Lines        4783    4767      -16     
=========================================
- Hits         3580    3566      -14     
+ Misses       1203    1201       -2
Impacted Files Coverage Δ
src/Phinx/Db/Table.php 94.89% <0%> (-0.98%) ⬇️
src/Phinx/Db/Adapter/SQLiteAdapter.php 87.64% <0%> (-0.19%) ⬇️
src/Phinx/Db/Adapter/PostgresAdapter.php 93.75% <0%> (ø) ⬆️
src/Phinx/Db/Adapter/SqlServerAdapter.php 0% <0%> (ø) ⬆️
src/Phinx/Db/Adapter/MysqlAdapter.php 98.88% <0%> (+0.16%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f3f3a0a...4d6628b. Read the comment docs.

codecov-io commented Nov 5, 2017

Codecov Report

Merging #1236 into master will decrease coverage by 0.04%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1236      +/-   ##
=========================================
- Coverage   74.84%   74.8%   -0.05%     
=========================================
  Files          35      35              
  Lines        4783    4767      -16     
=========================================
- Hits         3580    3566      -14     
+ Misses       1203    1201       -2
Impacted Files Coverage Δ
src/Phinx/Db/Table.php 94.89% <0%> (-0.98%) ⬇️
src/Phinx/Db/Adapter/SQLiteAdapter.php 87.64% <0%> (-0.19%) ⬇️
src/Phinx/Db/Adapter/PostgresAdapter.php 93.75% <0%> (ø) ⬆️
src/Phinx/Db/Adapter/SqlServerAdapter.php 0% <0%> (ø) ⬆️
src/Phinx/Db/Adapter/MysqlAdapter.php 98.88% <0%> (+0.16%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f3f3a0a...4d6628b. Read the comment docs.

Show outdated Hide outdated composer.json Outdated
Show outdated Hide outdated composer.json Outdated
@chinpei215

This comment has been minimized.

Show comment
Hide comment
@chinpei215

chinpei215 Dec 8, 2017

Member

Relates to #1085

Member

chinpei215 commented Dec 8, 2017

Relates to #1085

@philsown philsown referenced this pull request Mar 1, 2018

Closed

Support dotenv files #558

@dereuromark

This comment has been minimized.

Show comment
Hide comment
@dereuromark

dereuromark Mar 1, 2018

Member

Looks like we can move forward once the conflict is resolved 👍

Member

dereuromark commented Mar 1, 2018

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

This comment has been minimized.

@dereuromark

dereuromark Mar 1, 2018

Member

why is this needed? shouldnt this only be relevant for project's config files, not for inside vendor?

@dereuromark

dereuromark Mar 1, 2018

Member

why is this needed? shouldnt this only be relevant for project's config files, not for inside vendor?

This comment has been minimized.

@philsown

philsown Mar 1, 2018

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.

@philsown

philsown Mar 1, 2018

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.

This comment has been minimized.

@dereuromark

dereuromark Mar 1, 2018

Member

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?

@dereuromark

dereuromark Mar 1, 2018

Member

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?

This comment has been minimized.

@josegonzalez

josegonzalez Mar 4, 2018

Member

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.

@josegonzalez

josegonzalez Mar 4, 2018

Member

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.

This comment has been minimized.

@dereuromark

dereuromark Mar 4, 2018

Member

Sounds good.

@dereuromark

dereuromark Mar 4, 2018

Member

Sounds good.

Show outdated Hide outdated composer.json Outdated
@@ -0,0 +1,38 @@
<?php
// copy this file to phinx.config.php, or your preferred name/location

This comment has been minimized.

@dereuromark

dereuromark Mar 1, 2018

Member

Should we add the note here? composer require ... ?

@dereuromark

dereuromark Mar 1, 2018

Member

Should we add the note here? composer require ... ?

This comment has been minimized.

@josegonzalez

josegonzalez Mar 4, 2018

Member

We can probably add a note when installing the library somehow, though not sure where the best place for that would be.

@josegonzalez

josegonzalez Mar 4, 2018

Member

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.*"

This comment has been minimized.

@josegonzalez

josegonzalez Mar 4, 2018

Member

This can be 3.x.

@josegonzalez

josegonzalez Mar 4, 2018

Member

This can be 3.x.

@josegonzalez

This comment has been minimized.

Show comment
Hide comment
@josegonzalez

josegonzalez Mar 4, 2018

Member

Needs docs.

Member

josegonzalez commented Mar 4, 2018

Needs docs.

'environments' => [
'default_migration_table' => 'phinxlog',
'default_database' => getenv('APP_ENV'),
'develop' => [

This comment has been minimized.

@josephrace

josephrace Apr 24, 2018

I think this should match the APP_ENV value in .env.example - "development"

@josephrace

josephrace Apr 24, 2018

I think this should match the APP_ENV value in .env.example - "development"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment