Browse Source

refactor: env name refactoring

pull/9601/head
Pranav C 2 months ago
parent
commit
76600d4178
  1. 6
      packages/noco-docs/docs/020.getting-started/050.self-hosted/020.environment-variables.md
  2. 14
      packages/nocodb/src/helpers/initBaseBehaviour.ts
  3. 2
      packages/nocodb/src/services/bases.service.ts
  4. 21
      packages/nocodb/src/utils/getInstance.ts

6
packages/noco-docs/docs/020.getting-started/050.self-hosted/020.environment-variables.md

@ -90,14 +90,14 @@ For production use cases, it is crucial to set all environment variables marked
| `NC_ALLOW_LOCAL_HOOKS` | No | Allows webhooks to call local network links, posing potential security risks. Set to `true` to enable; all other values are considered `false`. | Defaults to `false`. |
| `NC_SANITIZE_COLUMN_NAME` | No | Enables sanitization of column names during their creation to prevent SQL injection and other security issues. | Defaults to `true`. |
| `NC_TOOL_DIR` | No | Specifies the directory to store metadata and app-related files. In Docker setups, this maps to `/usr/app/data/` for mounting volumes. | Defaults to the current working directory. |
| `NC_DISABLE_BASE_AS_PG_SCHEMA` | No | Disables the creation of a schema for each base in PostgreSQL. [Click here for more detail](#postgres-base-as-schema) | |
| `NC_DISABLE_PG_DATA_REFLECTION` | No | Disables the creation of a schema for each base in PostgreSQL. [Click here for more detail](#postgres-data-reflection) | |
| `NC_MIGRATIONS_DISABLED` | No | Disables NocoDB migrations. | |
| `NC_DISABLE_AUDIT` | No | Disables the audit log feature. | Defaults to `false`. |
| `NC_AUTOMATION_LOG_LEVEL` | No | Configures logging levels for automation features. Possible values: `OFF`, `ERROR`, `ALL`. More details can be found under [Webhooks](/automation/webhook/create-webhook). | Defaults to `OFF`. |
### Postgres Base as Schema
### Postgres Data Reflection
For PostgreSQL, a unique schema is created for each base, providing logical separation within the database. This feature is enabled by default if the user has the required permissions. To disable it, set the `NC_DISABLE_BASE_AS_PG_SCHEMA` environment variable to `false`.
NocoDB UI is exactly what's in your Postgres database schema. Same tables, same columns—everything is perfectly mirrored. This is done by creating a schema for each base in PostgreSQL. This feature is enabled by default if the user has the required permissions. To disable it, set the `NC_DISABLE_PG_DATA_REFLECTION` environment variable to `false`.
## Logging & Monitoring

14
packages/nocodb/src/helpers/initBaseBehaviour.ts

@ -48,8 +48,8 @@ export async function initBaseBehavior() {
return;
}
// disable minimal databases feature if NC_DISABLE_BASE_AS_PG_SCHEMA is set to true
if (process.env.NC_DISABLE_BASE_AS_PG_SCHEMA === 'true') {
// disable minimal databases feature if NC_DISABLE_PG_DATA_REFLECTION is set to true
if (process.env.NC_DISABLE_PG_DATA_REFLECTION === 'true') {
return;
}
@ -64,8 +64,8 @@ export async function initBaseBehavior() {
// if schema creation is not allowed, return
if (!schemaCreateAllowed?.rows?.[0]?.has_database_privilege) {
// set NC_MINIMAL_DBS to false if it's set to true and log warning
process.env.NC_DISABLE_BASE_AS_PG_SCHEMA = 'true';
// set NC_DISABLE_PG_DATA_REFLECTION to true and log warning
process.env.NC_DISABLE_PG_DATA_REFLECTION = 'true';
logger.warn(
`User ${
(dataConfig.connection as PgConnectionConfig)?.user
@ -74,13 +74,13 @@ export async function initBaseBehavior() {
return;
}
// set NC_MINIMAL_DBS to true
process.env.NC_DISABLE_BASE_AS_PG_SCHEMA = 'false';
// set NC_DISABLE_PG_DATA_REFLECTION to false
process.env.NC_DISABLE_PG_DATA_REFLECTION = 'false';
} catch (error) {
logger.warn(
`Error while checking schema creation permission: ${error.message}`,
);
process.env.NC_DISABLE_BASE_AS_PG_SCHEMA = 'true';
process.env.NC_DISABLE_PG_DATA_REFLECTION = 'true';
} finally {
// close the connection since it's only used to verify permission
await tempConnection?.destroy();

2
packages/nocodb/src/services/bases.service.ts

@ -166,7 +166,7 @@ export class BasesService {
if (
dataConfig?.client === 'pg' &&
process.env.NC_DISABLE_BASE_AS_PG_SCHEMA !== 'true'
process.env.NC_DISABLE_PG_DATA_REFLECTION !== 'true'
) {
baseBody.prefix = '';
baseBody.sources = [

21
packages/nocodb/src/utils/getInstance.ts

@ -39,10 +39,29 @@ export default async function (force = false, ncMeta = Noco.ncMeta) {
.count('storage as count')
.first()
.then((c) => c.count);
const tables = await ncMeta
.knex(MetaTable.MODELS)
.count('id as count')
.first()
.then((c) => c.created_at);
const views = await ncMeta
.knex(MetaTable.VIEWS)
.count('id as count')
.first()
.then((c) => c.created_at);
const nc_db_type = Noco.getConfig()?.meta?.db?.client;
res = { projectsMeta, projectsExt, impacted, nc_db_type, created, files };
res = {
projectsMeta,
projectsExt,
impacted,
nc_db_type,
created,
files,
tables,
views,
};
await NocoCache.set(CacheScope.INSTANCE_META, res);
}
return res;

Loading…
Cancel
Save