mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 06:55:50 +00:00
feat: support for the USE_DB_SCHEMA_IN_SUBAPP environment variable (#5481)
This commit is contained in:
parent
b08f364555
commit
e39d014b67
@ -61,7 +61,7 @@ const defaultSubAppUpgradeHandle: SubAppUpgradeHandler = async (mainApp: Applica
|
|||||||
|
|
||||||
const defaultDbCreator = async (app: Application) => {
|
const defaultDbCreator = async (app: Application) => {
|
||||||
const databaseOptions = app.options.database as any;
|
const databaseOptions = app.options.database as any;
|
||||||
const { host, port, username, password, dialect, database } = databaseOptions;
|
const { host, port, username, password, dialect, database, schema } = databaseOptions;
|
||||||
|
|
||||||
if (dialect === 'mysql') {
|
if (dialect === 'mysql') {
|
||||||
const mysql = require('mysql2/promise');
|
const mysql = require('mysql2/promise');
|
||||||
@ -91,7 +91,11 @@ const defaultDbCreator = async (app: Application) => {
|
|||||||
await client.connect();
|
await client.connect();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (process.env.USE_DB_SCHEMA_IN_SUBAPP === 'true') {
|
||||||
|
await client.query(`CREATE SCHEMA IF NOT EXISTS ${schema}`);
|
||||||
|
} else {
|
||||||
await client.query(`CREATE DATABASE "${database}"`);
|
await client.query(`CREATE DATABASE "${database}"`);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
@ -109,6 +113,8 @@ const defaultAppOptionsFactory = (appName: string, mainApp: Application) => {
|
|||||||
const mainStorageDir = path.dirname(mainAppStorage);
|
const mainStorageDir = path.dirname(mainAppStorage);
|
||||||
rawDatabaseOptions.storage = path.join(mainStorageDir, `${appName}.sqlite`);
|
rawDatabaseOptions.storage = path.join(mainStorageDir, `${appName}.sqlite`);
|
||||||
}
|
}
|
||||||
|
} else if (process.env.USE_DB_SCHEMA_IN_SUBAPP === 'true' && rawDatabaseOptions.dialect === 'postgres') {
|
||||||
|
rawDatabaseOptions.schema = appName;
|
||||||
} else {
|
} else {
|
||||||
rawDatabaseOptions.database = appName;
|
rawDatabaseOptions.database = appName;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user