System Information
Strapi Version : 4.25.10
Operating System : Windows 11
Database : mySQL
Node Version : 18
NPM Version :
Yarn Version :
Hi everyone,
I tried to set up a connection to a MySQL database using a password as a token. However, I encountered an issue when I tried to do so. I’m not sure if Strapi supports it or if there is any solution that I can implement. Can anyone help me with this?
I found an issue with same question, but it has been closed now.
opened 10:21AM - 17 Oct 23 UTC
closed 05:22PM - 23 Jul 24 UTC
issue: feature request
<!--
Hello 👋 Thank you for submitting an issue.
Before you start, please mak… e sure your issue is understandable and reproducible.
To make your issue readable make sure you use valid Markdown syntax.
https://guides.github.com/features/mastering-markdown/
Please ensure you have also read and understand the contributing guide.
https://github.com/strapi/strapi/blob/main/CONTRIBUTING.md#reporting-an-issue
-->
## Bug report
### Required System information
- Node.js version: v18.14.2
- Yarn version: 1.22.19
- Strapi version: 4.14.4
- Database: postgres
- Operating system: darwin-arm64
- Is your project Javascript or Typescript: Typescript
### Describe the bug
[Knex supports dynamic database connection](https://knexjs.org/guide/#configuration-options) by providing a function for the database connection config. It's been noted that the data inside of the strapi db config is passed directly to knex however when I use a function for the strapi db connection config, I get the following error
`TypeError: Cannot read properties of undefined (reading 'schema')`
from the [getSchemaName() function](https://github.com/strapi/strapi/blob/7c56d94b0c60d76f26a6b3532475f001d5414b42/packages/core/database/src/index.ts#L141-L143) resulting in a failed startup.
The issue is that `this.connection.client.connectionSettings` is undefined when providing a function as the connection config.
### Steps to reproduce the behavior
1. Provide a function as the strapi db connection config. i.e.
```
export default ({ env }) => ({
connection: {
client: 'postgres',
connection: async () => {
const {
token,
tokenExpiration
} = await someCallToGetTheToken();
return {
host : 'your_host',
port : 5432,
user : 'your_database_user',
password : token,
database : 'myapp_test',
expirationChecker: () => {
return tokenExpiration <= Date.now();
}
};
}
}
})
```
2. Start strapi app
### Expected behavior
Strapi to support dynamic database connection via db connection config function.
### Screenshots
N/A
### Code snippets
N/A
### Additional context
N/A
Thanks
Can anyone help answer this?