Add environment variable to force-exclude tables from Directus (#7789)

This commit is contained in:
Rijk van Zanten
2021-09-02 20:39:11 -04:00
committed by GitHub
parent 9cf957445c
commit 2abb1674ed
4 changed files with 9 additions and 0 deletions

View File

@@ -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');

View File

@@ -19,6 +19,8 @@ const defaults: Record<string, any> = {
PUBLIC_URL: '/',
MAX_PAYLOAD_SIZE: '100kb',
DB_EXCLUDE_TABLES: [],
STORAGE_LOCATIONS: 'local',
STORAGE_LOCAL_DRIVER: 'local',
STORAGE_LOCAL_ROOT: './uploads',

View File

@@ -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;

View File

@@ -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