Standard migration command (#2236)

* Add Standard Object migration commands

* rebase

* add sync-tenant-metadata command

* fix naming

* renaming command class names

* remove field deletion and use object cascade instead

---------

Co-authored-by: Charles Bochet <charlesBochet@users.noreply.github.com>
This commit is contained in:
Weiko
2023-10-27 18:08:59 +02:00
committed by GitHub
parent e488a87ce4
commit acbcd2f162
18 changed files with 385 additions and 12 deletions

View File

@ -21,7 +21,7 @@ export class TenantMigrationService {
*
* @param workspaceId
*/
public async insertStandardMigrations(workspaceId: string) {
public async insertStandardMigrations(workspaceId: string): Promise<void> {
// TODO: we actually don't need to fetch all of them, to improve later so it scales well.
const insertedStandardMigrations =
await this.tenantMigrationRepository.find({
@ -34,20 +34,21 @@ export class TenantMigrationService {
return acc;
}, {});
const standardMigrationsList = standardMigrations;
const standardMigrationsListThatNeedToBeInserted = Object.entries(
standardMigrationsList,
standardMigrations,
)
.filter(([name]) => !insertedStandardMigrationsMapByName[name])
.map(([name, migrations]) => ({ name, migrations }));
await this.tenantMigrationRepository.save(
const standardMigrationsThatNeedToBeInserted =
standardMigrationsListThatNeedToBeInserted.map((migration) => ({
...migration,
workspaceId,
isCustom: false,
})),
}));
await this.tenantMigrationRepository.save(
standardMigrationsThatNeedToBeInserted,
);
}
@ -60,7 +61,7 @@ export class TenantMigrationService {
public async getPendingMigrations(
workspaceId: string,
): Promise<TenantMigration[]> {
return this.tenantMigrationRepository.find({
return await this.tenantMigrationRepository.find({
order: { createdAt: 'ASC' },
where: {
appliedAt: IsNull(),