Browse Source

feat: NC_MINIMAL_DBS env variable

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/4124/head
mertmit 2 years ago
parent
commit
fbd0faa51a
  1. 4
      .gitignore
  2. 4
      packages/nocodb/src/lib/Noco.ts
  3. 31
      packages/nocodb/src/lib/meta/api/projectApis.ts

4
.gitignore vendored

@ -89,3 +89,7 @@ mongod
shared.json shared.json
/scripts/Cypress/screenshots /scripts/Cypress/screenshots
/scripts/exp/ /scripts/exp/
# NC_DBs
#=========
nc_minimal_dbs/

4
packages/nocodb/src/lib/Noco.ts

@ -103,6 +103,10 @@ export default class Noco {
// todo: move // todo: move
process.env.NC_VERSION = '0090000'; process.env.NC_VERSION = '0090000';
if (process.env.NC_MINIMAL_DBS) {
process.env.NC_CONNECT_TO_EXTERNAL_DB_DISABLED = 'true';
}
this.router = express.Router(); this.router = express.Router();
this.projectRouter = express.Router(); this.projectRouter = express.Router();

31
packages/nocodb/src/lib/meta/api/projectApis.ts

@ -24,6 +24,7 @@ import mapDefaultPrimaryValue from '../helpers/mapDefaultPrimaryValue';
import { extractAndGenerateManyToManyRelations } from './metaDiffApis'; import { extractAndGenerateManyToManyRelations } from './metaDiffApis';
import { metaApiMetrics } from '../helpers/apiMetrics'; import { metaApiMetrics } from '../helpers/apiMetrics';
import { extractPropsAndSanitize } from '../helpers/extractProps'; import { extractPropsAndSanitize } from '../helpers/extractProps';
import NcConfigFactory from '../../utils/NcConfigFactory';
const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 4); const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 4);
@ -107,6 +108,35 @@ async function projectCreate(req: Request<any, any>, res) {
const ranId = nanoid(); const ranId = nanoid();
projectBody.prefix = `nc_${ranId}__`; projectBody.prefix = `nc_${ranId}__`;
projectBody.is_meta = true; projectBody.is_meta = true;
if (process.env.NC_MINIMAL_DBS) {
const fs = require('fs');
const toolDir = NcConfigFactory.getToolDir();
const nanoidv2 = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz', 14);
if (!fs.existsSync(`${toolDir}/nc_minimal_dbs`)) {
fs.mkdirSync(`${toolDir}/nc_minimal_dbs`);
}
const dbId = nanoidv2();
const projectTitle = DOMPurify.sanitize(projectBody.title);
projectBody.prefix = '';
projectBody.bases = [
{
type: "sqlite3",
config: {
client: "sqlite3",
connection: {
client: "sqlite3",
database: projectTitle,
connection: {
filename: `${toolDir}/nc_minimal_dbs/${projectTitle}_${dbId}.sql`,
},
useNullAsDefault: true,
},
},
inflection_column: "camelize",
inflection_table: "camelize",
},
];
} else {
const db = Noco.getConfig().meta?.db; const db = Noco.getConfig().meta?.db;
projectBody.bases = [ projectBody.bases = [
{ {
@ -117,6 +147,7 @@ async function projectCreate(req: Request<any, any>, res) {
inflection_table: 'camelize', inflection_table: 'camelize',
}, },
]; ];
}
} else { } else {
if (process.env.NC_CONNECT_TO_EXTERNAL_DB_DISABLED) { if (process.env.NC_CONNECT_TO_EXTERNAL_DB_DISABLED) {
NcError.badRequest('Connecting to external db is disabled'); NcError.badRequest('Connecting to external db is disabled');

Loading…
Cancel
Save