Fix seeds for local workspace and newly created workspaces (#2333)

* Update metadata/data seeds

* fix

* fix

* move seeding into a transaction

* add no-non-null-assertion

---------

Co-authored-by: Charles Bochet <charlesBochet@users.noreply.github.com>
This commit is contained in:
Weiko
2023-11-03 14:33:45 +01:00
committed by GitHub
parent 56a5f99108
commit b56f6f3947
33 changed files with 1392 additions and 630 deletions

View File

@ -13,6 +13,7 @@ import { TenantMigrationService } from 'src/metadata/tenant-migration/tenant-mig
import { TenantMigrationTableAction } from 'src/metadata/tenant-migration/tenant-migration.entity';
import { MigrationRunnerService } from 'src/metadata/migration-runner/migration-runner.service';
import { ObjectMetadata } from 'src/metadata/object-metadata/object-metadata.entity';
import { standardObjectsMetadata } from 'src/metadata/standard-objects/standard-object-metadata';
@Injectable()
export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadata> {
@ -84,4 +85,32 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadata> {
where: { id: objectMetadataId, workspaceId },
});
}
/**
*
* Create all standard objects and fields metadata for a given workspace
*
* @param dataSourceMetadataId
* @param workspaceId
*/
public async createStandardObjectsAndFieldsMetadata(
dataSourceMetadataId: string,
workspaceId: string,
) {
await this.objectMetadataRepository.save(
Object.values(standardObjectsMetadata).map((objectMetadata) => ({
...objectMetadata,
dataSourceId: dataSourceMetadataId,
workspaceId,
isCustom: false,
isActive: true,
fields: objectMetadata.fields.map((field) => ({
...field,
workspaceId,
isCustom: false,
isActive: true,
})),
})),
);
}
}