Browse Source

Merge pull request #4124 from nocodb/feat/nc-minimal-dbs

feat: NC_MINIMAL_DBS env variable
pull/4137/head
navi 2 years ago committed by GitHub
parent
commit
fe79f099bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      .gitignore
  2. 4
      packages/nocodb/src/lib/Noco.ts
  3. 51
      packages/nocodb/src/lib/meta/api/projectApis.ts

4
.gitignore vendored

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

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

@ -103,6 +103,10 @@ export default class Noco {
// todo: move
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.projectRouter = express.Router();

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

@ -24,6 +24,7 @@ import mapDefaultPrimaryValue from '../helpers/mapDefaultPrimaryValue';
import { extractAndGenerateManyToManyRelations } from './metaDiffApis';
import { metaApiMetrics } from '../helpers/apiMetrics';
import { extractPropsAndSanitize } from '../helpers/extractProps';
import NcConfigFactory from '../../utils/NcConfigFactory';
const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 4);
@ -107,16 +108,46 @@ async function projectCreate(req: Request<any, any>, res) {
const ranId = nanoid();
projectBody.prefix = `nc_${ranId}__`;
projectBody.is_meta = true;
const db = Noco.getConfig().meta?.db;
projectBody.bases = [
{
type: db?.client,
config: null,
is_meta: true,
inflection_column: 'camelize',
inflection_table: 'camelize',
},
];
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;
projectBody.bases = [
{
type: db?.client,
config: null,
is_meta: true,
inflection_column: 'camelize',
inflection_table: 'camelize',
},
];
}
} else {
if (process.env.NC_CONNECT_TO_EXTERNAL_DB_DISABLED) {
NcError.badRequest('Connecting to external db is disabled');

Loading…
Cancel
Save