From 255d30b2c768877bbdad37197824da16a35a2cbb Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Sat, 21 Mar 2020 18:32:26 +0100 Subject: [PATCH] :sparkles: Make it possible to define prefix for table names --- docs/database.md | 7 +++++++ packages/cli/config/index.ts | 6 ++++++ packages/cli/src/Db.ts | 6 +++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/database.md b/docs/database.md index 61226e36cf..8fa4325394 100644 --- a/docs/database.md +++ b/docs/database.md @@ -4,6 +4,13 @@ By default, n8n uses SQLite to save credentials, past executions, and workflows. n8n however also supports MongoDB and PostgresDB. +## Shared Settings + +The following environment variables get used by all databases: + + - `DB_TABLE_PREFIX` (default: '') - Prefix for table names + + ## MongoDB !> **WARNING**: Use Postgres if possible! Mongo has problems with saving large diff --git a/packages/cli/config/index.ts b/packages/cli/config/index.ts index 343236547a..6405620e07 100644 --- a/packages/cli/config/index.ts +++ b/packages/cli/config/index.ts @@ -20,6 +20,12 @@ const config = convict({ env: 'DB_MONGODB_CONNECTION_URL' } }, + tablePrefix: { + doc: 'Prefix for table names', + format: '*', + default: '', + env: 'DB_TABLE_PREFIX' + }, postgresdb: { database: { doc: 'PostgresDB Database', diff --git a/packages/cli/src/Db.ts b/packages/cli/src/Db.ts index 110fcd92a8..a97cbaa837 100644 --- a/packages/cli/src/Db.ts +++ b/packages/cli/src/Db.ts @@ -42,6 +42,7 @@ export async function init(synchronize?: boolean): Promise entities = MongoDb; connectionOptions = { type: 'mongodb', + entityPrefix: await GenericHelpers.getConfigValue('database.tablePrefix') as string, url: await GenericHelpers.getConfigValue('database.mongodb.connectionUrl') as string, useNewUrlParser: true, }; @@ -52,6 +53,7 @@ export async function init(synchronize?: boolean): Promise entities = PostgresDb; connectionOptions = { type: 'postgres', + entityPrefix: await GenericHelpers.getConfigValue('database.tablePrefix') as string, database: await GenericHelpers.getConfigValue('database.postgresdb.database') as string, host: await GenericHelpers.getConfigValue('database.postgresdb.host') as string, password: await GenericHelpers.getConfigValue('database.postgresdb.password') as string, @@ -67,10 +69,11 @@ export async function init(synchronize?: boolean): Promise connectionOptions = { type: 'mysql', database: await GenericHelpers.getConfigValue('database.mysqldb.database') as string, + entityPrefix: await GenericHelpers.getConfigValue('database.tablePrefix') as string, host: await GenericHelpers.getConfigValue('database.mysqldb.host') as string, password: await GenericHelpers.getConfigValue('database.mysqldb.password') as string, port: await GenericHelpers.getConfigValue('database.mysqldb.port') as number, - username: await GenericHelpers.getConfigValue('database.mysqldb.user') as string + username: await GenericHelpers.getConfigValue('database.mysqldb.user') as string, }; break; @@ -80,6 +83,7 @@ export async function init(synchronize?: boolean): Promise connectionOptions = { type: 'sqlite', database: path.join(n8nFolder, 'database.sqlite'), + entityPrefix: await GenericHelpers.getConfigValue('database.tablePrefix') as string, }; break;