-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Backfill workspace version column #10637
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
|
||
import chalk from 'chalk'; | ||
import { Repository } from 'typeorm'; | ||
|
||
import { BatchActiveWorkspacesMigrationCommandRunner } from 'src/database/commands/migration-command/batch-active-workspaces-migration-command.runner'; | ||
import { MigrationCommand } from 'src/database/commands/migration-command/decorators/migration-command.decorator'; | ||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity'; | ||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager'; | ||
|
||
@MigrationCommand({ | ||
name: 'backfill-workspace-version', | ||
description: 'Backfill workspace version field to "0.43"', | ||
version: '0.43', | ||
}) | ||
export class BackfillWorkspaceVersionCommand extends BatchActiveWorkspacesMigrationCommandRunner { | ||
constructor( | ||
@InjectRepository(Workspace, 'core') | ||
protected readonly workspaceRepository: Repository<Workspace>, | ||
protected readonly twentyORMGlobalManager: TwentyORMGlobalManager, | ||
) { | ||
super(workspaceRepository, twentyORMGlobalManager); | ||
} | ||
|
||
async runMigrationCommandOnWorkspace( | ||
workspaceId: string, | ||
index: number, | ||
total: number, | ||
): Promise<void> { | ||
try { | ||
this.logger.log( | ||
`Running version backfill for workspace ${workspaceId} ${index + 1}/${total}`, | ||
); | ||
|
||
await this.backfillWorkspaceVersion(workspaceId); | ||
|
||
this.logger.log( | ||
chalk.green(`Command completed for workspace ${workspaceId}.`), | ||
); | ||
} catch (error) { | ||
this.logger.log( | ||
chalk.red(`Error in workspace ${workspaceId} - ${error.message}`), | ||
); | ||
} | ||
} | ||
|
||
private async backfillWorkspaceVersion(workspaceId: string): Promise<void> { | ||
await this.workspaceRepository.update( | ||
{ id: workspaceId }, | ||
{ version: '0.43' }, | ||
); | ||
|
||
this.logger.log( | ||
chalk.green( | ||
`Successfully backfilled version to "0.43" for workspace ${workspaceId}`, | ||
), | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,6 +4,7 @@ import { TypeOrmModule } from '@nestjs/typeorm'; | |||||
import { MigrationCommandModule } from 'src/database/commands/migration-command/miration-command.module'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. syntax: Typo in import path: 'miration-command.module' should be 'migration-command.module'
Suggested change
|
||||||
import { StandardizationOfActorCompositeContextTypeCommand } from 'src/database/commands/upgrade-version/0-42/0-42-standardization-of-actor-composite-context-type'; | ||||||
import { AddTasksAssignedToMeViewCommand } from 'src/database/commands/upgrade-version/0-43/0-43-add-tasks-assigned-to-me-view.command'; | ||||||
import { BackfillWorkspaceVersionCommand } from 'src/database/commands/upgrade-version/0-43/0-43-backfill-workspace-version.command'; | ||||||
import { MigrateRelationsToFieldMetadataCommand } from 'src/database/commands/upgrade-version/0-43/0-43-migrate-relations-to-field-metadata.command'; | ||||||
import { MigrateSearchVectorOnNoteAndTaskEntitiesCommand } from 'src/database/commands/upgrade-version/0-43/0-43-migrate-search-vector-on-note-and-task-entities.command'; | ||||||
import { UpdateDefaultViewRecordOpeningOnWorkflowObjectsCommand } from 'src/database/commands/upgrade-version/0-43/0-43-update-default-view-record-opening-on-workflow-objects.command'; | ||||||
|
@@ -32,6 +33,7 @@ import { WorkspaceMigrationRunnerModule } from 'src/engine/workspace-manager/wor | |||||
], | ||||||
providers: [ | ||||||
AddTasksAssignedToMeViewCommand, | ||||||
BackfillWorkspaceVersionCommand, | ||||||
MigrateSearchVectorOnNoteAndTaskEntitiesCommand, | ||||||
UpdateDefaultViewRecordOpeningOnWorkflowObjectsCommand, | ||||||
StandardizationOfActorCompositeContextTypeCommand, | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,13 @@ | ||||||||||||||
import { readFileSync } from 'fs'; | ||||||||||||||
import { join } from 'path'; | ||||||||||||||
|
||||||||||||||
export const getAppVersion = (): string | null => { | ||||||||||||||
try { | ||||||||||||||
const packageJsonPath = join(__dirname, '../../../../package.json'); | ||||||||||||||
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8')); | ||||||||||||||
|
||||||||||||||
return packageJson.version; | ||||||||||||||
Comment on lines
+7
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: No validation that packageJson.version exists or is in valid semver format
Suggested change
|
||||||||||||||
} catch (error) { | ||||||||||||||
return null; | ||||||||||||||
} | ||||||||||||||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Error is only logged but not propagated. Could lead to silent failures in the migration process.