feat: Add seed people and companies data for demo environment (#2207) (#2307)

* feat: seed companies and people data

* init DataSeedDemoWorkspaceCommand to handle:
- seedCoreSchema()
- seedMetadataSchema()

* feature: Seed workspace with demo data

- delete workspace
- initDemo() with prefillWorkspaceWithDemoObjects()

* added companies-demo.ts with data
* added people-demo.ts with data

* added workspaceId to seedFeatureFlags()

* delete previous CoreSchema before seedCoreSchema

* added workspaceMemberPrefillData

* getDemoWorkspaces() to get DEMO_WORKSPACES from config

* defined DemoSeedUserIds

- created core/demo/ to keep modified seedCoreSchema() there
- DemoSeedUserIds with new set of users and Ids

* generateOpportunities() to seed demo opportunities (limit = 50)

* Code review and fixes

* Fix

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Ruslan
2023-12-03 00:37:45 +07:00
committed by GitHub
parent 31f29582d0
commit fd9467c54d
35 changed files with 5190 additions and 38 deletions
@@ -0,0 +1,52 @@
import { Command, CommandRunner } from 'nest-commander';
import { DataSource } from 'typeorm';
import {
deleteCoreSchema,
seedCoreSchema,
} from 'src/database/typeorm-seeds/core/demo';
import { EnvironmentService } from 'src/integrations/environment/environment.service';
import { WorkspaceManagerService } from 'src/workspace/workspace-manager/workspace-manager.service';
@Command({
name: 'workspace:seed:demo',
description:
'Seed workspace with demo data. This command is intended for development only.',
})
export class DataSeedDemoWorkspaceCommand extends CommandRunner {
constructor(
private readonly environmentService: EnvironmentService,
private readonly workspaceManagerService: WorkspaceManagerService,
) {
super();
}
async run(): Promise<void> {
try {
const dataSource = new DataSource({
url: this.environmentService.getPGDatabaseUrl(),
type: 'postgres',
logging: true,
schema: 'public',
});
await dataSource.initialize();
const demoWorkspaceIds = this.environmentService.getDemoWorkspaceIds();
if (demoWorkspaceIds.length === 0) {
throw new Error(
'Could not get DEMO_WORKSPACE_IDS. Please specify in .env',
);
}
for (const workspaceId of demoWorkspaceIds) {
await deleteCoreSchema(dataSource, workspaceId);
await this.workspaceManagerService.delete(workspaceId);
await seedCoreSchema(dataSource, workspaceId);
await this.workspaceManagerService.initDemo(workspaceId);
}
} catch (error) {
console.error(error);
return;
}
}
}
@@ -18,7 +18,7 @@ import { EnvironmentService } from 'src/integrations/environment/environment.ser
// TODO: implement dry-run
@Command({
name: 'workspace:seed',
name: 'workspace:seed:dev',
description:
'Seed workspace with initial data. This command is intended for development only.',
})
@@ -45,7 +45,7 @@ export class DataSeedWorkspaceCommand extends CommandRunner {
});
await dataSource.initialize();
await seedCoreSchema(dataSource);
await seedCoreSchema(dataSource, this.workspaceId);
await seedMetadataSchema(dataSource);
} catch (error) {
console.error(error);
@@ -7,7 +7,8 @@ import { WorkspaceMigrationModule } from 'src/metadata/workspace-migration/works
import { WorkspaceMigrationRunnerModule } from 'src/workspace/workspace-migration-runner/workspace-migration-runner.module';
import { TypeORMModule } from 'src/database/typeorm/typeorm.module';
import { WorkspaceModule } from 'src/core/workspace/workspace.module';
import { DataSeedWorkspaceCommand } from 'src/database/commands/data-seed-workspace.command';
import { DataSeedWorkspaceCommand } from 'src/database/commands/data-seed-dev-workspace.command';
import { DataSeedDemoWorkspaceCommand } from 'src/database/commands/data-seed-demo-workspace.command';
@Module({
imports: [
@@ -18,6 +19,10 @@ import { DataSeedWorkspaceCommand } from 'src/database/commands/data-seed-worksp
WorkspaceMigrationRunnerModule,
WorkspaceModule,
],
providers: [DataSeedWorkspaceCommand, ConfirmationQuestion],
providers: [
DataSeedWorkspaceCommand,
DataSeedDemoWorkspaceCommand,
ConfirmationQuestion,
],
})
export class DatabaseCommandModule {}