From 2abb1674ed963c1a07397ead0eae2a8ebd9548d2 Mon Sep 17 00:00:00 2001 From: Rijk van Zanten Date: Thu, 2 Sep 2021 20:39:11 -0400 Subject: [PATCH] Add environment variable to force-exclude tables from Directus (#7789) --- api/src/database/index.ts | 1 + api/src/env.ts | 2 ++ api/src/utils/get-schema.ts | 5 +++++ docs/reference/environment-variables.md | 1 + 4 files changed, 9 insertions(+) diff --git a/api/src/database/index.ts b/api/src/database/index.ts index 20154cbe7b..2f17e7f6b7 100644 --- a/api/src/database/index.ts +++ b/api/src/database/index.ts @@ -22,6 +22,7 @@ export default function getDatabase(): Knex { 'DB_SEARCH_PATH', 'DB_CONNECTION_STRING', 'DB_POOL', + 'DB_EXCLUDE_TABLES', ]); const poolConfig = getConfigFromEnv('DB_POOL'); diff --git a/api/src/env.ts b/api/src/env.ts index 2dff4b2de1..75af7f7fde 100644 --- a/api/src/env.ts +++ b/api/src/env.ts @@ -19,6 +19,8 @@ const defaults: Record = { PUBLIC_URL: '/', MAX_PAYLOAD_SIZE: '100kb', + DB_EXCLUDE_TABLES: [], + STORAGE_LOCATIONS: 'local', STORAGE_LOCAL_DRIVER: 'local', STORAGE_LOCAL_ROOT: './uploads', diff --git a/api/src/utils/get-schema.ts b/api/src/utils/get-schema.ts index 80a9eda1cd..69d49ac9c6 100644 --- a/api/src/utils/get-schema.ts +++ b/api/src/utils/get-schema.ts @@ -116,6 +116,11 @@ async function getDatabaseSchema( ]; for (const [collection, info] of Object.entries(schemaOverview)) { + if (toArray(env.DB_EXCLUDE_TABLES).includes(collection)) { + logger.trace(`Collection "${collection}" is configured to be excluded and will be ignored`); + continue; + } + if (!info.primary) { logger.warn(`Collection "${collection}" doesn't have a primary key column and will be ignored`); continue; diff --git a/docs/reference/environment-variables.md b/docs/reference/environment-variables.md index d9cfe36882..f3cd4d9b14 100644 --- a/docs/reference/environment-variables.md +++ b/docs/reference/environment-variables.md @@ -34,6 +34,7 @@ needs to be publicly available on the internet. | `DB_FILENAME` | Where to read/write the SQLite database. **Required** when using `sqlite3`. | -- | | `DB_CONNECTION_STRING` | When using `pg`, you can submit a connection string instead of individual properties. Using this will ignore any of the other connection settings. | -- | | `DB_POOL_*` | Pooling settings. Passed on to [the `tarn.js`](https://github.com/vincit/tarn.js#usage) library. | -- | +| `DB_IGNORE_TABLES` | CSV of tables you want Directus to ignore completely | -- | ::: tip Additional Database Variables