feat: add dry-run option to sync-metadata command (#3758)
* feat: add dry-run option to sync-metadata command * feat: save metadata logs in dry-run mode
This commit is contained in:
@ -0,0 +1,70 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import fs from 'fs/promises';
|
||||
|
||||
import { WorkspaceSyncStorage } from 'src/workspace/workspace-sync-metadata/storage/workspace-sync.storage';
|
||||
import { WorkspaceMigrationEntity } from 'src/metadata/workspace-migration/workspace-migration.entity';
|
||||
|
||||
@Injectable()
|
||||
export class WorkspaceLogsService {
|
||||
constructor() {}
|
||||
|
||||
async saveLogs(
|
||||
storage: WorkspaceSyncStorage,
|
||||
workspaceMigrations: WorkspaceMigrationEntity[],
|
||||
) {
|
||||
// Save workspace migrations
|
||||
await fs.writeFile(
|
||||
'./logs/workspace-migrations.json',
|
||||
JSON.stringify(workspaceMigrations, null, 2),
|
||||
);
|
||||
|
||||
// Save object metadata create collection
|
||||
await fs.writeFile(
|
||||
'./logs/object-metadata-create-collection.json',
|
||||
JSON.stringify(storage.objectMetadataCreateCollection, null, 2),
|
||||
);
|
||||
|
||||
// Save object metadata update collection
|
||||
await fs.writeFile(
|
||||
'./logs/object-metadata-update-collection.json',
|
||||
JSON.stringify(storage.objectMetadataUpdateCollection, null, 2),
|
||||
);
|
||||
|
||||
// Save object metadata delete collection
|
||||
await fs.writeFile(
|
||||
'./logs/object-metadata-delete-collection.json',
|
||||
JSON.stringify(storage.objectMetadataDeleteCollection, null, 2),
|
||||
);
|
||||
|
||||
// Save field metadata create collection
|
||||
await fs.writeFile(
|
||||
'./logs/field-metadata-create-collection.json',
|
||||
JSON.stringify(storage.fieldMetadataCreateCollection, null, 2),
|
||||
);
|
||||
|
||||
// Save field metadata update collection
|
||||
await fs.writeFile(
|
||||
'./logs/field-metadata-update-collection.json',
|
||||
JSON.stringify(storage.fieldMetadataUpdateCollection, null, 2),
|
||||
);
|
||||
|
||||
// Save field metadata delete collection
|
||||
await fs.writeFile(
|
||||
'./logs/field-metadata-delete-collection.json',
|
||||
JSON.stringify(storage.fieldMetadataDeleteCollection, null, 2),
|
||||
);
|
||||
|
||||
// Save relation metadata create collection
|
||||
await fs.writeFile(
|
||||
'./logs/relation-metadata-create-collection.json',
|
||||
JSON.stringify(storage.relationMetadataCreateCollection, null, 2),
|
||||
);
|
||||
|
||||
// Save relation metadata delete collection
|
||||
await fs.writeFile(
|
||||
'./logs/relation-metadata-delete-collection.json',
|
||||
JSON.stringify(storage.relationMetadataDeleteCollection, null, 2),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -33,7 +33,7 @@ export class WorkspaceSyncObjectMetadataService {
|
||||
manager: EntityManager,
|
||||
storage: WorkspaceSyncStorage,
|
||||
workspaceFeatureFlagsMap: FeatureFlagMap,
|
||||
): Promise<void> {
|
||||
): Promise<WorkspaceMigrationEntity[]> {
|
||||
const objectMetadataRepository =
|
||||
manager.getRepository(ObjectMetadataEntity);
|
||||
const workspaceMigrationRepository = manager.getRepository(
|
||||
@ -153,6 +153,10 @@ export class WorkspaceSyncObjectMetadataService {
|
||||
this.logger.log('Saving migrations');
|
||||
|
||||
// Save migrations into DB
|
||||
await workspaceMigrationRepository.save(workspaceObjectMigrations);
|
||||
const workspaceMigrations = await workspaceMigrationRepository.save(
|
||||
workspaceObjectMigrations,
|
||||
);
|
||||
|
||||
return workspaceMigrations;
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ export class WorkspaceSyncRelationMetadataService {
|
||||
manager: EntityManager,
|
||||
storage: WorkspaceSyncStorage,
|
||||
workspaceFeatureFlagsMap: FeatureFlagMap,
|
||||
): Promise<void> {
|
||||
): Promise<WorkspaceMigrationEntity[]> {
|
||||
const objectMetadataRepository =
|
||||
manager.getRepository(ObjectMetadataEntity);
|
||||
const workspaceMigrationRepository = manager.getRepository(
|
||||
@ -106,6 +106,10 @@ export class WorkspaceSyncRelationMetadataService {
|
||||
);
|
||||
|
||||
// Save migrations into DB
|
||||
await workspaceMigrationRepository.save(workspaceRelationMigrations);
|
||||
const workspaceMigrations = await workspaceMigrationRepository.save(
|
||||
workspaceRelationMigrations,
|
||||
);
|
||||
|
||||
return workspaceMigrations;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user