Clean metadata and schema (#2382)
This commit is contained in:
@ -161,6 +161,8 @@ export class WorkspaceService {
|
|||||||
this.delete({ where: { id: workspaceId } }),
|
this.delete({ where: { id: workspaceId } }),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
await this.tenantInitialisationService.delete(workspaceId);
|
||||||
|
|
||||||
return workspace;
|
return workspace;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,4 +41,8 @@ export class DataSourceMetadataService {
|
|||||||
order: { createdAt: 'DESC' },
|
order: { createdAt: 'DESC' },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async delete(workspaceId: string) {
|
||||||
|
await this.dataSourceMetadataRepository.delete({ workspaceId });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -121,6 +121,20 @@ export class DataSourceService implements OnModuleInit, OnModuleDestroy {
|
|||||||
return `workspace_${uuidToBase36(workspaceId)}`;
|
return `workspace_${uuidToBase36(workspaceId)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async deleteWorkspaceSchema(workspaceId: string) {
|
||||||
|
const schemaName = this.getSchemaName(workspaceId);
|
||||||
|
const queryRunner = this.mainDataSource.createQueryRunner();
|
||||||
|
const schemaAlreadyExists = await queryRunner.hasSchema(schemaName);
|
||||||
|
|
||||||
|
if (!schemaAlreadyExists) {
|
||||||
|
throw new Error(`Schema ${schemaName} does not exist`);
|
||||||
|
}
|
||||||
|
|
||||||
|
await queryRunner.dropSchema(schemaName, true, true);
|
||||||
|
|
||||||
|
await queryRunner.release();
|
||||||
|
}
|
||||||
|
|
||||||
async onModuleInit() {
|
async onModuleInit() {
|
||||||
// Init main data source "default" schema
|
// Init main data source "default" schema
|
||||||
await this.mainDataSource.initialize();
|
await this.mainDataSource.initialize();
|
||||||
|
|||||||
@ -120,4 +120,8 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadata> {
|
|||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async deleteObjectsAndFieldsMetadata(workspaceId: string) {
|
||||||
|
await this.objectMetadataRepository.delete({ workspaceId });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,4 +75,15 @@ export class TenantInitialisationService {
|
|||||||
|
|
||||||
standardObjectsPrefillData(workspaceDataSource, dataSourceMetadata.schema);
|
standardObjectsPrefillData(workspaceDataSource, dataSourceMetadata.schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async delete(workspaceId: string): Promise<void> {
|
||||||
|
// Delete data from metadata tables
|
||||||
|
await this.objectMetadataService.deleteObjectsAndFieldsMetadata(
|
||||||
|
workspaceId,
|
||||||
|
);
|
||||||
|
await this.tenantMigrationService.delete(workspaceId);
|
||||||
|
await this.dataSourceMetadataService.delete(workspaceId);
|
||||||
|
// Delete schema
|
||||||
|
await this.dataSourceService.deleteWorkspaceSchema(workspaceId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -103,4 +103,8 @@ export class TenantMigrationService {
|
|||||||
isCustom: true,
|
isCustom: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async delete(workspaceId: string) {
|
||||||
|
await this.tenantMigrationRepository.delete({ workspaceId });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user