-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Loading dotEnv file and ormconfig.js #3420
Comments
its controversial. Some people may point that they have development configuration in ormconfig and on production they want to override that using env variables. why you simply won't override .env with your .env.testing (mount it, replace it or something)? |
Thanks for taking the time to reply to this. That use case is fine, though I think we should be more explicit on how Typeorm is loading the configuration file. Having implicit ordering can be a nightmare to debug later on. Perhaps if we cannot solve the controversy, would it be fine to document this behavior in the documentation, so that people know how Typeorm decides from where to take the configuration? As for the I cannot override the |
yeah, we can add docs. But there is also some discussion on what we shall do with current configuration loading. Feel free to PR against docs. I think best in your case is to manually send options to |
…-typeorm-config-load (#3420) Add documentation on typeorm config load
Done (thanks for the quick merging!).
Thanks, that could work. Because I'm not sure if it will also work for the CLI. I'll check and if it does, then I can close this issue. |
to make it to work with CLI probably you have only one option - left only |
It is true that Typeorm will still load my My options are: making Typeorm a special case and tell my team that the configuration of the project resides in both the It seems to me that this specific behavior of Typeorm (Loading the env file) is causing an undesirable effect. However, I understand that it has it's use cases. Would you accept PRs to customize this behavior under an option, or under a flag for the CLI? Thanks! |
We are planning to rework this mechanizm in the future, so I want to prevent additional specific changes in the current implementation. If you found a solution for your use case its better to stay with it. |
Sounds good, thanks! I'll override the Closing this issue. |
Arguably it is outside of TypeORM's responsibility to manage This is a very unexpected and magical behaviour. This magical behaviour can lead to many issues. Arguably implicitly reading config from any env is a bad behaviour. What if I accidentally set an env variable and forget to unset it, and can destroy data this way. I think the best way is to offload config loading to third party packages that can be loaded separately. |
I just spend 2 hours finding out why my env vars are not being expanded properly, loading of custom I think it is bad practice to have a tool implicitly (magically) ingest |
Another case where I spent 2 hours figuring out why I wasn't able to load a |
I too spent 1 hour and came across this thread. I want to explicitly set the env file but no way to do it. |
i'm facing the same problem. There is no way to implement this feature in the future? |
same problem in 2022 |
Issue type:
[ ] question
[ ] bug report
[x] feature request
[ ] documentation issue
Database system/driver:
[ ]
cordova
[ ]
mongodb
[ ]
mssql
[ ]
mysql
/mariadb
[ ]
oracle
[ ]
postgres
[ ]
sqlite
[ ]
sqljs
[ ]
react-native
[ ]
expo
TypeORM version:
[x]
latest
[ ]
@next
[ ]
0.x.x
(or put your version here)Coming from Sequelize, this is a very awesome ORM!
I'm implementing multi-environment variables (
.env
,.env.testing
) that is part of a Docker setup in my project. I created an ormconfig.js file and attempted to load my.env.testing
usingdotenv
, but found out that someone had already loaded an environment.It seems that Typeorm is pre-loading the dotEnv file in the ConnectionOptionsReader file without allowing the option to customize this load.
This introduces two issues for me:
If the variable
TYPEORM_CONNECTION
exists then myormconfig.js
file won't be loaded. This was probably intentional, but not a very intuitive behavior. Shouldn't explicit configurations (such as anormconfig,js
file) override the less explicit ones (such as a .env defined variable)?I cannot load the environment that I want because Typeorm already loaded one and overriding already-defined environment variables is not supported by
dotenv
, due to security reasons.The temporal workaround that I'm using is to override the env variables and also had to rename my env variables to avoid Typeorm not loading my
ormconfig
file.Would it be possible to address (2) by giving the user the option to load the environment (or to specify the path) using a config file? For (1), would it be possible to attempt to load the
ormconfig
files before loading the.env
variables?The text was updated successfully, but these errors were encountered: