Skip to content

Commit 75535ec

Browse files
committed
Fix snapshot issue
1 parent c0d2507 commit 75535ec

File tree

9 files changed

+518
-223
lines changed

9 files changed

+518
-223
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# Version 3.1.0
1+
# Version 3.1.1
2+
3+
- **Fixed** Snapshot undefined issue
4+
5+
## Version 3.1.0
26

37
- **Updated** Packages and build.
48
- **Added** More logging for schema import

package-lock.json

Lines changed: 497 additions & 205 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "directus-extension-schema-sync",
33
"description": "Sync schema and data betwreen Directus instances",
44
"icon": "sync_alt",
5-
"version": "3.1.0",
5+
"version": "3.1.1",
66
"repository": {
77
"type": "git",
88
"url": "https://github.com/bcc-code/directus-schema-sync.git"
@@ -36,6 +36,8 @@
3636
"release-channel": "node ./scripts/release-channel.js"
3737
},
3838
"devDependencies": {
39+
"@directus/extensions": "^3.0.15",
40+
"@directus/types": "^13.5.0",
3941
"@types/keyv": "^4.2.0",
4042
"@types/node": "^20.14.15",
4143
"rollup-plugin-exclude-dependencies-from-bundle": "^1.1.24",
@@ -45,8 +47,6 @@
4547
"glob": "^10.4.5"
4648
},
4749
"peerDependencies": {
48-
"@directus/api": "^32.1.1",
49-
"@directus/extensions": "^3.0.14",
50-
"@directus/types": "^13.4.0"
50+
"@directus/api": "^32.0.0"
5151
}
5252
}

src/collectionExporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ApiExtensionContext } from '@directus/extensions';
2-
import { Item, PrimaryKey, Query } from '@directus/types';
2+
import type { Item, PrimaryKey, Query } from '@directus/types';
33
import { mkdir, readFile, rm, writeFile } from 'fs/promises';
44
import { glob } from 'glob';
55
import { condenseAction } from './condenseAction.js';

src/exportManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ActionHandler } from '@directus/types';
21
import type { ApiExtensionContext } from '@directus/extensions';
2+
import type { ActionHandler } from '@directus/types';
33
import { CollectionExporter } from './collectionExporter.js';
44
import { ExportCollectionConfig, IExporterConfig, IGetItemsService } from './types';
55

src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getFlowManager } from '@directus/api/flows';
1+
import { useBus } from '@directus/api/bus/index';
22
import type { HookConfig } from '@directus/extensions';
33
import type { SchemaOverview } from '@directus/types';
44
import { condenseAction } from './condenseAction';
@@ -99,8 +99,10 @@ const registerHook: HookConfig = async ({ action, init }, { env, services, datab
9999
}
100100

101101
async function reloadDirectusModules() {
102-
const flowManager = getFlowManager();
103-
await flowManager.reload();
102+
const messenger = useBus();
103+
if (!messenger) return;
104+
105+
messenger.publish('flows', { type: 'reload' });
104106
}
105107

106108
// LOAD EXPORTED SCHEMAS & COLLECTIONS

src/schemaExporter.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Snapshot, SnapshotField, SnapshotRelation } from '@directus/api/dist/types';
22
import type { ApiExtensionContext } from '@directus/extensions';
3-
import { Collection } from '@directus/types';
3+
import type { Collection, ExtensionsServices } from '@directus/types';
44
import { mkdir, readFile, rm, writeFile } from 'fs/promises';
55
import { glob } from 'glob';
66
import { condenseAction } from './condenseAction.js';
@@ -10,16 +10,14 @@ import { ExportHelper } from './utils.js';
1010

1111
export class SchemaExporter implements IExporter {
1212
protected _filePath: string;
13-
protected _getSchemaService: () => Promise<any>;
1413
protected _exportHandler = condenseAction(() => this.createAndSaveSnapshot());
1514

1615
// Directus SchemaService, database and getSchema
1716
constructor(
18-
getSchemaService: () => Promise<any>,
17+
protected getSchemaService: () => Promise<InstanceType<ExtensionsServices['SchemaService']>>,
1918
protected logger: ApiExtensionContext['logger'],
2019
protected options = { split: true }
2120
) {
22-
this._getSchemaService = () => getSchemaService();
2321
this._filePath = `${ExportHelper.dataDir}/schema.json`;
2422
}
2523

@@ -47,7 +45,7 @@ export class SchemaExporter implements IExporter {
4745
* Import the schema from file to the database
4846
*/
4947
public load = async () => {
50-
const svc = await this._getSchemaService();
48+
const svc = await this.getSchemaService();
5149
let json;
5250
try {
5351
json = await readFile(this._filePath, { encoding: 'utf8' });
@@ -128,7 +126,7 @@ export class SchemaExporter implements IExporter {
128126
* Create and save the schema snapshot to file
129127
*/
130128
protected createAndSaveSnapshot = async () => {
131-
const svc = this._getSchemaService();
129+
const svc = await this.getSchemaService();
132130
let snapshot = (await svc.snapshot()) as Snapshot;
133131
snapshot = exportHook(snapshot);
134132
let hash = svc.getHashedSnapshot(snapshot).hash;

src/updateManager.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { Knex } from 'knex';
2-
import { ExportHelper } from './utils';
32

43
export class UpdateManager {
54
protected db: Knex;

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Accountability } from '@directus/types';
1+
import type { Accountability } from '@directus/types';
22
import { createHash } from 'crypto';
33
import { access, readFile, readdir, writeFile } from 'fs/promises';
44
import { resolve } from 'path';

0 commit comments

Comments
 (0)