From 892e7b1dbc27764755a1721daa299289ae709256 Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Fri, 17 Mar 2023 22:01:35 +0600 Subject: [PATCH] Add component migration (#2764) Signed-off-by: Denis Bykhov --- dev/generator/src/issues.ts | 14 +++++++++----- models/tracker/src/migration.ts | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/dev/generator/src/issues.ts b/dev/generator/src/issues.ts index 8b32211e42..a6cb28e3c8 100644 --- a/dev/generator/src/issues.ts +++ b/dev/generator/src/issues.ts @@ -53,9 +53,13 @@ export async function generateIssues ( const client = new TxOperations(connection, account._id) const ctx = new MeasureMetricsContext('recruit', {}) + const statuses = (await client.findAll(tracker.class.IssueStatus, { space }, { projection: { _id: 1 } })).map( + (p) => p._id + ) + for (let index = 0; index < options.count; index++) { console.log(`Generating issue ${index + 1}...`) - await genIssue(client) + await genIssue(client, statuses) } await connection.close() @@ -64,7 +68,7 @@ export async function generateIssues ( console.info(metricsToString(ctx.metrics, 'Client')) } -async function genIssue (client: TxOperations): Promise { +async function genIssue (client: TxOperations, statuses: Ref[]): Promise { const lastOne = await client.findOne(tracker.class.Issue, {}, { sort: { rank: SortingOrder.Descending } }) const incResult = await client.updateDoc( tracker.class.Project, @@ -76,14 +80,14 @@ async function genIssue (client: TxOperations): Promise { true ) const value: AttachedData = { - title: faker.name.title(), + title: faker.commerce.productName(), description: faker.lorem.paragraphs(), assignee: object.assignee, component: object.component, sprint: object.sprint, number: (incResult as any).object.sequence, - status: object.status, - priority: object.priority, + status: faker.random.arrayElement(statuses), + priority: faker.random.arrayElement(Object.values(IssuePriority)) as IssuePriority, rank: calcRank(lastOne, undefined), comments: 0, subIssues: 0, diff --git a/models/tracker/src/migration.ts b/models/tracker/src/migration.ts index 1673d6ffe5..37f0042288 100644 --- a/models/tracker/src/migration.ts +++ b/models/tracker/src/migration.ts @@ -429,6 +429,29 @@ async function renameProject (client: MigrationClient): Promise { $rename: { project: 'component' } } ) + await client.update( + DOMAIN_TRACKER, + { + _id: tracker.class.Project + }, + { + _class: tracker.class.Component + } + ) + const components = await client.find(DOMAIN_TRACKER, { _class: tracker.class.Component }) + for (const component of components) { + await client.update( + DOMAIN_TX, + { + objectId: component._id, + objectClass: tracker.class.Project + }, + { + objectClass: tracker.class.Component + } + ) + } + await client.update( DOMAIN_TX, {