Convert metadata tables to camelCase (#2400)
* Convert metadata tables to camelCase * datasourcemetadataid to datasourceid * refactor metadata folders * fix command * move commands out of metadata * fix seed * rename objectId and fieldId in objectMetadataId and fieldMetadataId in FE * fix field-metadata * Fix * Fix * remove logs --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
66
server/src/database/commands/data-seed-tenant.command.ts
Normal file
66
server/src/database/commands/data-seed-tenant.command.ts
Normal file
@ -0,0 +1,66 @@
|
||||
import { InjectDataSource } from '@nestjs/typeorm';
|
||||
|
||||
import { Command, CommandRunner } from 'nest-commander';
|
||||
import { DataSource } from 'typeorm';
|
||||
|
||||
import { DataSourceMetadataService } from 'src/metadata/data-source-metadata/data-source-metadata.service';
|
||||
import { TenantMigrationService } from 'src/metadata/tenant-migration/tenant-migration.service';
|
||||
import { TenantMigrationRunnerService } from 'src/tenant-migration-runner/tenant-migration-runner.service';
|
||||
import { seedCompanies } from 'src/database/typeorm-seeds/tenant/companies';
|
||||
import { seedViewFields } from 'src/database/typeorm-seeds/tenant/view-fields';
|
||||
import { seedViews } from 'src/database/typeorm-seeds/tenant/views';
|
||||
import { seedFieldMetadata } from 'src/database/typeorm-seeds/metadata/field-metadata';
|
||||
import { seedObjectMetadata } from 'src/database/typeorm-seeds/metadata/object-metadata';
|
||||
import { TypeORMService } from 'src/database/typeorm/typeorm.service';
|
||||
|
||||
// TODO: implement dry-run
|
||||
@Command({
|
||||
name: 'tenant:seed',
|
||||
description:
|
||||
'Seed tenant with initial data. This command is intended for development only.',
|
||||
})
|
||||
export class DataSeedTenantCommand extends CommandRunner {
|
||||
workspaceId = 'twenty-7ed9d212-1c25-4d02-bf25-6aeccf7ea419';
|
||||
|
||||
constructor(
|
||||
@InjectDataSource('metadata')
|
||||
private readonly metadataDataSource: DataSource,
|
||||
private readonly dataSourceMetadataService: DataSourceMetadataService,
|
||||
private readonly typeORMService: TypeORMService,
|
||||
private readonly tenantMigrationService: TenantMigrationService,
|
||||
private readonly migrationRunnerService: TenantMigrationRunnerService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
async run(): Promise<void> {
|
||||
const dataSourceMetadata =
|
||||
await this.dataSourceMetadataService.getLastDataSourceMetadataFromWorkspaceIdOrFail(
|
||||
this.workspaceId,
|
||||
);
|
||||
|
||||
const workspaceDataSource = await this.typeORMService.connectToDataSource(
|
||||
dataSourceMetadata,
|
||||
);
|
||||
|
||||
if (!workspaceDataSource) {
|
||||
throw new Error('Could not connect to workspace data source');
|
||||
}
|
||||
|
||||
await seedObjectMetadata(this.metadataDataSource, 'metadata');
|
||||
await seedFieldMetadata(this.metadataDataSource, 'metadata');
|
||||
|
||||
await this.tenantMigrationService.insertStandardMigrations(
|
||||
this.workspaceId,
|
||||
);
|
||||
await this.migrationRunnerService.executeMigrationFromPendingMigrations(
|
||||
this.workspaceId,
|
||||
);
|
||||
|
||||
await seedCompanies(workspaceDataSource, dataSourceMetadata.schema);
|
||||
await seedViewFields(workspaceDataSource, dataSourceMetadata.schema);
|
||||
await seedViews(workspaceDataSource, dataSourceMetadata.schema);
|
||||
|
||||
await this.typeORMService.disconnectFromDataSource(dataSourceMetadata.id);
|
||||
}
|
||||
}
|
||||
@ -2,21 +2,36 @@ import { Module } from '@nestjs/common';
|
||||
|
||||
import { DataCleanInactiveCommand } from 'src/database/commands/clean-inactive-workspaces.command';
|
||||
import { ConfirmationQuestion } from 'src/database/commands/questions/confirmation.question';
|
||||
import { WorkspaceService } from 'src/core/workspace/services/workspace.service';
|
||||
import { PipelineModule } from 'src/core/pipeline/pipeline.module';
|
||||
import { CompanyModule } from 'src/core/company/company.module';
|
||||
import { PersonModule } from 'src/core/person/person.module';
|
||||
import { TenantInitialisationModule } from 'src/metadata/tenant-initialisation/tenant-initialisation.module';
|
||||
import { PrismaModule } from 'src/database/prisma.module';
|
||||
import { TenantManagerModule } from 'src/tenant-manager/tenant-manager.module';
|
||||
import { DataSourceMetadataModule } from 'src/metadata/data-source-metadata/data-source-metadata.module';
|
||||
import { TenantMigrationModule } from 'src/metadata/tenant-migration/tenant-migration.module';
|
||||
import { TenantMigrationRunnerModule } from 'src/tenant-migration-runner/tenant-migration-runner.module';
|
||||
import { TypeORMModule } from 'src/database/typeorm/typeorm.module';
|
||||
import { WorkspaceModule } from 'src/core/workspace/workspace.module';
|
||||
|
||||
import { DataSeedTenantCommand } from './data-seed-tenant.command';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
PipelineModule,
|
||||
CompanyModule,
|
||||
PersonModule,
|
||||
TenantInitialisationModule,
|
||||
TenantManagerModule,
|
||||
PrismaModule,
|
||||
DataSourceMetadataModule,
|
||||
TypeORMModule,
|
||||
TenantMigrationModule,
|
||||
TenantMigrationRunnerModule,
|
||||
WorkspaceModule,
|
||||
],
|
||||
providers: [
|
||||
DataSeedTenantCommand,
|
||||
DataCleanInactiveCommand,
|
||||
ConfirmationQuestion,
|
||||
],
|
||||
providers: [DataCleanInactiveCommand, ConfirmationQuestion, WorkspaceService],
|
||||
})
|
||||
export class DatabaseCommandModule {}
|
||||
|
||||
Reference in New Issue
Block a user