Make it possible to define prefix for table names

This commit is contained in:
Jan Oberhauser 2020-03-21 18:32:26 +01:00
parent 4469e9bb8f
commit 255d30b2c7
3 changed files with 18 additions and 1 deletions

View file

@ -4,6 +4,13 @@ By default, n8n uses SQLite to save credentials, past executions, and workflows.
n8n however also supports MongoDB and PostgresDB. 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 ## MongoDB
!> **WARNING**: Use Postgres if possible! Mongo has problems with saving large !> **WARNING**: Use Postgres if possible! Mongo has problems with saving large

View file

@ -20,6 +20,12 @@ const config = convict({
env: 'DB_MONGODB_CONNECTION_URL' env: 'DB_MONGODB_CONNECTION_URL'
} }
}, },
tablePrefix: {
doc: 'Prefix for table names',
format: '*',
default: '',
env: 'DB_TABLE_PREFIX'
},
postgresdb: { postgresdb: {
database: { database: {
doc: 'PostgresDB Database', doc: 'PostgresDB Database',

View file

@ -42,6 +42,7 @@ export async function init(synchronize?: boolean): Promise<IDatabaseCollections>
entities = MongoDb; entities = MongoDb;
connectionOptions = { connectionOptions = {
type: 'mongodb', type: 'mongodb',
entityPrefix: await GenericHelpers.getConfigValue('database.tablePrefix') as string,
url: await GenericHelpers.getConfigValue('database.mongodb.connectionUrl') as string, url: await GenericHelpers.getConfigValue('database.mongodb.connectionUrl') as string,
useNewUrlParser: true, useNewUrlParser: true,
}; };
@ -52,6 +53,7 @@ export async function init(synchronize?: boolean): Promise<IDatabaseCollections>
entities = PostgresDb; entities = PostgresDb;
connectionOptions = { connectionOptions = {
type: 'postgres', type: 'postgres',
entityPrefix: await GenericHelpers.getConfigValue('database.tablePrefix') as string,
database: await GenericHelpers.getConfigValue('database.postgresdb.database') as string, database: await GenericHelpers.getConfigValue('database.postgresdb.database') as string,
host: await GenericHelpers.getConfigValue('database.postgresdb.host') as string, host: await GenericHelpers.getConfigValue('database.postgresdb.host') as string,
password: await GenericHelpers.getConfigValue('database.postgresdb.password') as string, password: await GenericHelpers.getConfigValue('database.postgresdb.password') as string,
@ -67,10 +69,11 @@ export async function init(synchronize?: boolean): Promise<IDatabaseCollections>
connectionOptions = { connectionOptions = {
type: 'mysql', type: 'mysql',
database: await GenericHelpers.getConfigValue('database.mysqldb.database') as string, 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, host: await GenericHelpers.getConfigValue('database.mysqldb.host') as string,
password: await GenericHelpers.getConfigValue('database.mysqldb.password') as string, password: await GenericHelpers.getConfigValue('database.mysqldb.password') as string,
port: await GenericHelpers.getConfigValue('database.mysqldb.port') as number, 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; break;
@ -80,6 +83,7 @@ export async function init(synchronize?: boolean): Promise<IDatabaseCollections>
connectionOptions = { connectionOptions = {
type: 'sqlite', type: 'sqlite',
database: path.join(n8nFolder, 'database.sqlite'), database: path.join(n8nFolder, 'database.sqlite'),
entityPrefix: await GenericHelpers.getConfigValue('database.tablePrefix') as string,
}; };
break; break;