-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command to backfill new onboarding user vars (#6526)
As per our guideline to maintain a smooth migration to the new minor versions, this command is backfilling existing workspaces with the 3 userVars used to keep track of user onboarding: ``` ONBOARDING_CONNECT_ACCOUNT_COMPLETE = 'ONBOARDING_CONNECT_ACCOUNT_COMPLETE', ONBOARDING_INVITE_TEAM_COMPLETE = 'ONBOARDING_INVITE_TEAM_COMPLETE', ONBOARDING_CREATE_PROFILE_COMPLETE = 'ONBOARDING_CREATE_PROFILE_COMPLETE', ```
- Loading branch information
1 parent
7cd5427
commit 76185c2
Showing
9 changed files
with
116 additions
and
5 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
...rver/src/database/commands/upgrade-version/0-23/0-23-backfill-new-onboarding-user-vars.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { Logger } from '@nestjs/common'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
|
||
import chalk from 'chalk'; | ||
import { Command, CommandRunner, Option } from 'nest-commander'; | ||
import { Repository } from 'typeorm'; | ||
|
||
import { UpdateFileFolderStructureCommand } from 'src/database/commands/upgrade-version/0-23/0-23-update-file-folder-structure.command'; | ||
import { OnboardingService } from 'src/engine/core-modules/onboarding/onboarding.service'; | ||
import { | ||
Workspace, | ||
WorkspaceActivationStatus, | ||
} from 'src/engine/core-modules/workspace/workspace.entity'; | ||
|
||
interface BackfillNewOnboardingUserVarsCommandOptions { | ||
workspaceId?: string; | ||
} | ||
|
||
@Command({ | ||
name: 'upgrade-0.23:backfill-new-onboarding-user-vars', | ||
description: 'Backfill new onboarding user vars for existing workspaces', | ||
}) | ||
export class BackfillNewOnboardingUserVarsCommand extends CommandRunner { | ||
private readonly logger = new Logger(UpdateFileFolderStructureCommand.name); | ||
constructor( | ||
@InjectRepository(Workspace, 'core') | ||
private readonly workspaceRepository: Repository<Workspace>, | ||
private readonly onboardingService: OnboardingService, | ||
) { | ||
super(); | ||
} | ||
|
||
@Option({ | ||
flags: '-w, --workspace-id [workspace_id]', | ||
description: 'workspace id. Command runs on all workspaces if not provided', | ||
required: false, | ||
}) | ||
parseWorkspaceId(value: string): string { | ||
return value; | ||
} | ||
|
||
async run( | ||
_passedParam: string[], | ||
options: BackfillNewOnboardingUserVarsCommandOptions, | ||
): Promise<void> { | ||
let workspaces; | ||
|
||
if (options.workspaceId) { | ||
workspaces = await this.workspaceRepository.find({ | ||
where: { | ||
activationStatus: WorkspaceActivationStatus.ACTIVE, | ||
id: options.workspaceId, | ||
}, | ||
relations: ['users'], | ||
}); | ||
} else { | ||
workspaces = await this.workspaceRepository.find({ | ||
where: { activationStatus: WorkspaceActivationStatus.ACTIVE }, | ||
relations: ['users'], | ||
}); | ||
} | ||
|
||
if (!workspaces.length) { | ||
this.logger.log(chalk.yellow('No workspace found')); | ||
|
||
return; | ||
} | ||
|
||
this.logger.log( | ||
chalk.green(`Running command on ${workspaces.length} workspaces`), | ||
); | ||
|
||
for (const workspace of workspaces) { | ||
this.logger.log( | ||
chalk.green(`Running command on workspace ${workspace.id}`), | ||
); | ||
|
||
await this.onboardingService.toggleOnboardingInviteTeamCompletion({ | ||
workspaceId: workspace.id, | ||
value: true, | ||
}); | ||
|
||
for (const user of workspace.users) { | ||
await this.onboardingService.toggleOnboardingConnectAccountCompletion({ | ||
userId: user.id, | ||
workspaceId: workspace.id, | ||
value: true, | ||
}); | ||
|
||
await this.onboardingService.toggleOnboardingCreateProfileCompletion({ | ||
userId: user.id, | ||
workspaceId: workspace.id, | ||
value: true, | ||
}); | ||
} | ||
} | ||
|
||
this.logger.log(chalk.green(`Command completed!`)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters