Skip to content

Improve seeds 3 #12740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 20, 2025
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Logger } from '@nestjs/common';
import { Command, CommandRunner } from 'nest-commander';

import {
SEED_ACME_WORKSPACE_ID,
SEED_APPLE_WORKSPACE_ID,
SEED_YCOMBINATOR_WORKSPACE_ID,
} from 'src/engine/workspace-manager/dev-seeder/core/utils/seed-workspaces.util';
import { DevSeederService } from 'src/engine/workspace-manager/dev-seeder/services/dev-seeder.service';
@Command({
Expand All @@ -13,7 +13,7 @@ import { DevSeederService } from 'src/engine/workspace-manager/dev-seeder/servic
'Seed workspace with initial data. This command is intended for development only.',
})
export class DataSeedWorkspaceCommand extends CommandRunner {
workspaceIds = [SEED_APPLE_WORKSPACE_ID, SEED_ACME_WORKSPACE_ID];
workspaceIds = [SEED_APPLE_WORKSPACE_ID, SEED_YCOMBINATOR_WORKSPACE_ID];
private readonly logger = new Logger(DataSeedWorkspaceCommand.name);

constructor(private readonly devSeederService: DevSeederService) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class ObjectMetadataRelatedRecordsService {
type: 'table',
name: `All ${objectMetadata.labelPlural}`,
key: 'INDEX',
icon: objectMetadata.icon,
icon: 'IconList',
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { RoleService } from 'src/engine/metadata-modules/role/role.service';
import { UserRoleService } from 'src/engine/metadata-modules/user-role/user-role.service';
import { USER_WORKSPACE_DATA_SEED_IDS } from 'src/engine/workspace-manager/dev-seeder/core/utils/seed-user-workspaces.util';
import {
SEED_ACME_WORKSPACE_ID,
SEED_APPLE_WORKSPACE_ID,
SEED_APPLE_WORKSPACE_ID,
SEED_YCOMBINATOR_WORKSPACE_ID,
} from 'src/engine/workspace-manager/dev-seeder/core/utils/seed-workspaces.util';

@Injectable()
Expand Down Expand Up @@ -46,7 +46,7 @@ export class DevSeederPermissionsService {
userWorkspaceId: USER_WORKSPACE_DATA_SEED_IDS.PHIL,
roleId: guestRole.id,
});
} else if (workspaceId === SEED_ACME_WORKSPACE_ID) {
} else if (workspaceId === SEED_YCOMBINATOR_WORKSPACE_ID) {
adminUserWorkspaceId = USER_WORKSPACE_DATA_SEED_IDS.TIM_ACME;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { DataSource } from 'typeorm';
import { UserWorkspace } from 'src/engine/core-modules/user-workspace/user-workspace.entity';
import { USER_DATA_SEED_IDS } from 'src/engine/workspace-manager/dev-seeder/core/utils/seed-users.util';
import {
SEED_ACME_WORKSPACE_ID,
SEED_APPLE_WORKSPACE_ID,
SEED_YCOMBINATOR_WORKSPACE_ID,
} from 'src/engine/workspace-manager/dev-seeder/core/utils/seed-workspaces.util';

const tableName = 'userWorkspace';
Expand Down Expand Up @@ -46,7 +46,7 @@ export const seedUserWorkspaces = async (
];
}

if (workspaceId === SEED_ACME_WORKSPACE_ID) {
if (workspaceId === SEED_YCOMBINATOR_WORKSPACE_ID) {
userWorkspaces = [
{
id: USER_WORKSPACE_DATA_SEED_IDS.TIM_ACME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { extractVersionMajorMinorPatch } from 'src/utils/version/extract-version
const tableName = 'workspace';

export const SEED_APPLE_WORKSPACE_ID = '20202020-1c25-4d02-bf25-6aeccf7ea419';
export const SEED_ACME_WORKSPACE_ID = '3b8e6458-5fc1-4e63-8563-008ccddaa6db';
export const SEED_YCOMBINATOR_WORKSPACE_ID =
'3b8e6458-5fc1-4e63-8563-008ccddaa6db';

export type SeedWorkspaceArgs = {
dataSource: DataSource;
Expand Down Expand Up @@ -49,12 +50,12 @@ export const seedWorkspaces = async ({
activationStatus: WorkspaceActivationStatus.PENDING_CREATION, // will be set to active after default role creation
version: version,
},
[SEED_ACME_WORKSPACE_ID]: {
id: SEED_ACME_WORKSPACE_ID,
displayName: 'Acme',
subdomain: 'acme',
inviteHash: 'acme.dev-invite-hash',
logo: 'https://logos-world.net/wp-content/uploads/2022/05/Acme-Logo-700x394.png',
[SEED_YCOMBINATOR_WORKSPACE_ID]: {
id: SEED_YCOMBINATOR_WORKSPACE_ID,
displayName: 'YCombinator',
subdomain: 'yc',
inviteHash: 'yc.dev-invite-hash',
logo: 'https://twentyhq.github.io/placeholder-images/workspaces/ycombinator-logo.png',
activationStatus: WorkspaceActivationStatus.PENDING_CREATION, // will be set to active after default role creation
version: version,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,57 @@ export const CALENDAR_CHANNEL_DATA_SEED_COLUMNS: (keyof CalendarChannelDataSeed)
'isSyncEnabled',
];

export const CALENDAR_CHANNEL_DATA_SEED_IDS = {
TIM: '20202020-a40f-4faf-bb9f-c6f9945b8203',
const GENERATE_CALENDAR_CHANNEL_IDS = (): Record<string, string> => {
const CHANNEL_IDS: Record<string, string> = {};

CHANNEL_IDS['TIM'] = '20202020-a40f-4faf-bb9f-c6f9945b8203';
CHANNEL_IDS['JONY'] = '20202020-a40f-4faf-bb9f-c6f9945b8204';
CHANNEL_IDS['PHIL'] = '20202020-a40f-4faf-bb9f-c6f9945b8205';
CHANNEL_IDS['COMPANY_MAIN'] = '20202020-a40f-4faf-bb9f-c6f9945b8206';
CHANNEL_IDS['TEAM_CALENDAR'] = '20202020-a40f-4faf-bb9f-c6f9945b8207';

return CHANNEL_IDS;
};

export const CALENDAR_CHANNEL_DATA_SEED_IDS = GENERATE_CALENDAR_CHANNEL_IDS();

export const CALENDAR_CHANNEL_DATA_SEEDS: CalendarChannelDataSeed[] = [
{
id: CALENDAR_CHANNEL_DATA_SEED_IDS.TIM,
connectedAccountId: CONNECTED_ACCOUNT_DATA_SEED_IDS.TIM,
handle: '[email protected]',
visibility: CalendarChannelVisibility.METADATA,
isContactAutoCreationEnabled: true,
isSyncEnabled: true,
},
{
id: CALENDAR_CHANNEL_DATA_SEED_IDS.JONY,
connectedAccountId: CONNECTED_ACCOUNT_DATA_SEED_IDS.JONY,
handle: '[email protected]',
visibility: CalendarChannelVisibility.SHARE_EVERYTHING,
isContactAutoCreationEnabled: true,
isSyncEnabled: true,
},
{
id: CALENDAR_CHANNEL_DATA_SEED_IDS.PHIL,
connectedAccountId: CONNECTED_ACCOUNT_DATA_SEED_IDS.PHIL,
handle: '[email protected]',
visibility: CalendarChannelVisibility.METADATA,
isContactAutoCreationEnabled: true,
isSyncEnabled: true,
},
{
id: CALENDAR_CHANNEL_DATA_SEED_IDS.COMPANY_MAIN,
connectedAccountId: CONNECTED_ACCOUNT_DATA_SEED_IDS.TIM,
handle: '[email protected]',
visibility: CalendarChannelVisibility.SHARE_EVERYTHING,
isContactAutoCreationEnabled: true,
isSyncEnabled: true,
},
{
id: CALENDAR_CHANNEL_DATA_SEED_IDS.TEAM_CALENDAR,
connectedAccountId: CONNECTED_ACCOUNT_DATA_SEED_IDS.TIM,
handle: '[email protected]',
visibility: CalendarChannelVisibility.SHARE_EVERYTHING,
isContactAutoCreationEnabled: true,
isSyncEnabled: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,83 @@ export const CALENDAR_CHANNEL_EVENT_ASSOCIATION_DATA_SEED_COLUMNS: (keyof Calend
'recurringEventExternalId',
];

export const CALENDAR_CHANNEL_EVENT_ASSOCIATION_DATA_SEED_IDS = {
ID_1: '20202020-0687-4c41-b707-ed1bfca972a2',
const GENERATE_CALENDAR_CHANNEL_EVENT_ASSOCIATION_IDS = (): Record<
string,
string
> => {
const ASSOCIATION_IDS: Record<string, string> = {};

for (let INDEX = 1; INDEX <= 800; INDEX++) {
const HEX_INDEX = INDEX.toString(16).padStart(4, '0');

ASSOCIATION_IDS[`ID_${INDEX}`] =
`20202020-${HEX_INDEX}-4e7c-8001-123456789abc`;
}

return ASSOCIATION_IDS;
};

export const CALENDAR_CHANNEL_EVENT_ASSOCIATION_DATA_SEEDS: CalendarChannelEventAssociationDataSeed[] =
[
{
id: CALENDAR_CHANNEL_EVENT_ASSOCIATION_DATA_SEED_IDS.ID_1,
calendarChannelId: CALENDAR_CHANNEL_DATA_SEED_IDS.TIM,
calendarEventId: CALENDAR_EVENT_DATA_SEED_IDS.ID_1,
eventExternalId: 'exampleExternalId',
recurringEventExternalId: 'exampleRecurringExternalId',
},
];
export const CALENDAR_CHANNEL_EVENT_ASSOCIATION_DATA_SEED_IDS =
GENERATE_CALENDAR_CHANNEL_EVENT_ASSOCIATION_IDS();

const GENERATE_CALENDAR_CHANNEL_EVENT_ASSOCIATION_SEEDS =
(): CalendarChannelEventAssociationDataSeed[] => {
const ASSOCIATION_SEEDS: CalendarChannelEventAssociationDataSeed[] = [];

// Get all event IDs and channel IDs
const EVENT_IDS = Object.keys(CALENDAR_EVENT_DATA_SEED_IDS).map(
(key) =>
CALENDAR_EVENT_DATA_SEED_IDS[
key as keyof typeof CALENDAR_EVENT_DATA_SEED_IDS
],
);

const CHANNEL_IDS = [
CALENDAR_CHANNEL_DATA_SEED_IDS.TIM,
CALENDAR_CHANNEL_DATA_SEED_IDS.JONY,
CALENDAR_CHANNEL_DATA_SEED_IDS.PHIL,
CALENDAR_CHANNEL_DATA_SEED_IDS.COMPANY_MAIN,
CALENDAR_CHANNEL_DATA_SEED_IDS.TEAM_CALENDAR,
];

// Create associations for each event
EVENT_IDS.forEach((eventId, index) => {
// Distribute events across channels with weighted distribution
let CHANNEL_ID: string;
const CHANNEL_RAND = Math.random();

if (CHANNEL_RAND < 0.3) {
// 30% - Tim's personal calendar
CHANNEL_ID = CHANNEL_IDS[0]; // TIM
} else if (CHANNEL_RAND < 0.45) {
// 15% - Jony's personal calendar
CHANNEL_ID = CHANNEL_IDS[1]; // JONY
} else if (CHANNEL_RAND < 0.6) {
// 15% - Phil's personal calendar
CHANNEL_ID = CHANNEL_IDS[2]; // PHIL
} else if (CHANNEL_RAND < 0.8) {
// 20% - Company main calendar
CHANNEL_ID = CHANNEL_IDS[3]; // COMPANY_MAIN
} else {
// 20% - Team calendar
CHANNEL_ID = CHANNEL_IDS[4]; // TEAM_CALENDAR
}

const ASSOCIATION_INDEX = index + 1;

ASSOCIATION_SEEDS.push({
id: CALENDAR_CHANNEL_EVENT_ASSOCIATION_DATA_SEED_IDS[
`ID_${ASSOCIATION_INDEX}`
],
calendarChannelId: CHANNEL_ID,
calendarEventId: eventId,
eventExternalId: `external_event_${ASSOCIATION_INDEX}@calendar.com`,
recurringEventExternalId: `recurring_${ASSOCIATION_INDEX}@calendar.com`,
});
});

return ASSOCIATION_SEEDS;
};

export const CALENDAR_CHANNEL_EVENT_ASSOCIATION_DATA_SEEDS =
GENERATE_CALENDAR_CHANNEL_EVENT_ASSOCIATION_SEEDS();
Loading
Loading