From 5b5fe16dd76fb1b8e63eae3a7f5590fa7e459a7f Mon Sep 17 00:00:00 2001 From: Dieter Stinglhamber Date: Wed, 31 Aug 2022 14:20:27 +0200 Subject: [PATCH] update db template --- .../database-templates/js/database.template | 10 +++---- .../database-templates/ts/database.template | 28 +++++++++++++------ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/packages/generators/app/lib/resources/templates/database-templates/js/database.template b/packages/generators/app/lib/resources/templates/database-templates/js/database.template index 21d1615832..badff6cecb 100644 --- a/packages/generators/app/lib/resources/templates/database-templates/js/database.template +++ b/packages/generators/app/lib/resources/templates/database-templates/js/database.template @@ -5,7 +5,7 @@ module.exports = ({ env }) => { const connections = { mysql: { - connection: { + connection: env('DATABASE_URL') || { host: env('DATABASE_HOST', 'localhost'), port: env.int('DATABASE_PORT', 3306), database: env('DATABASE_NAME', 'strapi'), @@ -22,7 +22,7 @@ module.exports = ({ env }) => { }, }, postgres: { - connection: { + connection: env('DATABASE_URL') || { host: env('DATABASE_HOST', 'localhost'), port: env.int('DATABASE_PORT', 5431), database: env('DATABASE_NAME', 'strapi'), @@ -40,18 +40,16 @@ module.exports = ({ env }) => { }, sqlite: { connection: { - filename: path.join(__dirname, '..', env('DATABASE_FILENAME', 'data.db')), + filename: env('DATABASE_URL') || path.join(__dirname, '..', env('DATABASE_FILENAME', 'data.db')), }, useNullAsDefault: true, } } - const connection = env('DATABASE_URL') ? { connection: env('DATABASE_URL') } : connections[client] - return { connection: { client, - ...connection, + ...connections[client], }, }; } diff --git a/packages/generators/app/lib/resources/templates/database-templates/ts/database.template b/packages/generators/app/lib/resources/templates/database-templates/ts/database.template index 73c6f34d48..4eb4003228 100644 --- a/packages/generators/app/lib/resources/templates/database-templates/ts/database.template +++ b/packages/generators/app/lib/resources/templates/database-templates/ts/database.template @@ -5,39 +5,51 @@ export default ({ env }) => { const connections = { mysql: { - connection: { + connection: env('DATABASE_URL') || { host: env('DATABASE_HOST', 'localhost'), port: env.int('DATABASE_PORT', 3306), database: env('DATABASE_NAME', 'strapi'), user: env('DATABASE_USERNAME', 'strapi'), password: env('DATABASE_PASSWORD', 'strapi'), - ssl: env.bool('DATABASE_SSL', false), + ssl: env.bool('DATABASE_SSL', false) && { + key: env('DATABASE_SSL_KEY', undefined), + cert: env('DATABASE_SSL_CERT', undefined), + ca: env('DATABASE_SSL_CA', undefined), + capath: env('DATABASE_SSL_CAPATH', undefined), + cipher: env('DATABASE_SSL_CIPHER', undefined), + rejectUnauthorized: env.bool('DATABASE_SSL_REJECT_UNAUTHORIZED', true), + }, }, }, postgres: { - connection: { + connection: env('DATABASE_URL') || { host: env('DATABASE_HOST', 'localhost'), port: env.int('DATABASE_PORT', 5431), database: env('DATABASE_NAME', 'strapi'), user: env('DATABASE_USERNAME', 'strapi'), password: env('DATABASE_PASSWORD', 'strapi'), - ssl: env.bool('DATABASE_SSL', false), + ssl: env.bool('DATABASE_SSL', false) && { + key: env('DATABASE_SSL_KEY', undefined), + cert: env('DATABASE_SSL_CERT', undefined), + ca: env('DATABASE_SSL_CA', undefined), + capath: env('DATABASE_SSL_CAPATH', undefined), + cipher: env('DATABASE_SSL_CIPHER', undefined), + rejectUnauthorized: env.bool('DATABASE_SSL_REJECT_UNAUTHORIZED', true), + }, }, }, sqlite: { connection: { - filename: path.join(__dirname, '..', '..', env('DATABASE_FILENAME', 'data.db')), + filename: env('DATABASE_URL') || path.join(__dirname, '..', env('DATABASE_FILENAME', 'data.db')), }, useNullAsDefault: true, } } - const connection = env('DATABASE_URL') ? { connection: env('DATABASE_URL') } : connections[client] - return { connection: { client, - ...connection, + ...connections[client], }, }; }