Skip to content

Commit

Permalink
Remove old schema files
Browse files Browse the repository at this point in the history
  • Loading branch information
u12206050 committed Jun 7, 2024
1 parent ec08f47 commit 7e7fb41
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Version 2.1.1
# Version 2.1.2

- Remove old schema files when genereating new schema files.
- This is to remove files of deleted collections.

## Version 2.1.1

- Outputs additional helpful information when error occurs.
- Link to an issue when trying to import empty files.
Expand Down
2 changes: 0 additions & 2 deletions src/collectionExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,10 @@ class CollectionExporter implements IExporter {
return map;
}, {} as Record<PrimaryKey, Item>);

let hasDependents = false;
items.forEach(o => {
for (const fieldName of linkedFields) {
const value = o[fieldName];
if (value && itemsMap[value]) {
hasDependents = true;
itemsMap[value].__dependents.push(o);
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/schemaExporter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Snapshot, SnapshotField, SnapshotRelation } from '@directus/api/dist/types';
import type { ApiExtensionContext } from '@directus/extensions';
import { Collection } from '@directus/types';
import { readFile, writeFile, mkdir } from 'fs/promises';
import { readFile, writeFile, mkdir, rm } from 'fs/promises';
import { glob } from 'glob';
import { condenseAction } from './condenseAction.js';
import { exportHook } from './schemaExporterHooks.js';
Expand All @@ -26,6 +26,12 @@ export class SchemaExporter implements IExporter {
protected ensureSchemaFilesDir = async () => {
if (!(await ExportHelper.fileExists(`${ExportHelper.dataDir}/schema`))) {
await mkdir(`${ExportHelper.dataDir}/schema`, { recursive: true });
} else {
// Clean up old schema files
const files = await glob(this.schemaFilesPath('*'));
for (const file of files) {
await rm(file);
}
}
};

Expand Down

0 comments on commit 7e7fb41

Please sign in to comment.