Qfix: Always recreate space types (#5371)

This commit is contained in:
Alexey Zinoviev 2024-04-16 18:10:58 +04:00 committed by GitHub
parent c26ea595cd
commit fb0194af3e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 74 additions and 49 deletions

View File

@ -14,7 +14,7 @@
//
import { type Card, boardId } from '@hcengineering/board'
import { type Ref, TxOperations } from '@hcengineering/core'
import { TxOperations } from '@hcengineering/core'
import {
type MigrateOperation,
type MigrationClient,
@ -26,7 +26,7 @@ import {
import core, { DOMAIN_SPACE } from '@hcengineering/model-core'
import { DOMAIN_TASK, createProjectType, createSequence, fixTaskTypes } from '@hcengineering/model-task'
import tags from '@hcengineering/tags'
import task, { type ProjectType } from '@hcengineering/task'
import task from '@hcengineering/task'
import { PaletteColorIndexes } from '@hcengineering/ui/src/colors'
import board from './plugin'
@ -34,8 +34,8 @@ async function createSpace (tx: TxOperations): Promise<void> {
const current = await tx.findOne(core.class.Space, {
_id: board.space.DefaultBoard
})
if (current === undefined) {
const defaultType = await createDefaultProjectType(tx)
await tx.createDoc(
board.class.Board,
core.space.Space,
@ -45,15 +45,24 @@ async function createSpace (tx: TxOperations): Promise<void> {
private: false,
archived: false,
members: [],
type: defaultType
type: board.template.DefaultBoard
},
board.space.DefaultBoard
)
}
}
async function createDefaultProjectType (tx: TxOperations): Promise<Ref<ProjectType>> {
return await createProjectType(
async function createDefaultProjectType (tx: TxOperations): Promise<void> {
const existing = await tx.findOne(task.class.ProjectType, { _id: board.template.DefaultBoard })
const existingDeleted = await tx.findOne(core.class.TxRemoveDoc, {
objectId: board.template.DefaultBoard
})
if (existing !== undefined || existingDeleted !== undefined) {
return
}
await createProjectType(
tx,
{
name: 'Default board',
@ -185,11 +194,14 @@ export const boardOperation: MigrateOperation = {
])
},
async upgrade (client: MigrationUpgradeClient): Promise<void> {
const ops = new TxOperations(client, core.account.System)
// For now need to be created every time as it's system model
await createDefaultProjectType(ops)
await tryUpgrade(client, boardId, [
{
state: 'board0001',
func: async (client) => {
const ops = new TxOperations(client, core.account.System)
func: async () => {
await createDefaults(ops)
}
}

View File

@ -315,6 +315,10 @@ export const documentOperation: MigrateOperation = {
async upgrade (client: MigrationUpgradeClient): Promise<void> {
const tx = new TxOperations(client, core.account.System)
// Currently space type has to be recreated every time as it's in the model
// created by the system user
await createDefaultTeamspaceType(tx)
await tryUpgrade(client, documentId, [
{
state: 'u-default-project',
@ -323,9 +327,5 @@ export const documentOperation: MigrateOperation = {
}
}
])
// Currently space type has to be recreated every time as it's in the model
// created by the system user
await createDefaultTeamspaceType(tx)
}
}

View File

@ -189,6 +189,10 @@ export const leadOperation: MigrateOperation = {
},
async upgrade (client: MigrationUpgradeClient): Promise<void> {
const ops = new TxOperations(client, core.account.System)
// Currently space type has to be recreated every time as it's in the model
// created by the system user
await createSpaceType(ops)
await tryUpgrade(client, leadId, [
{
state: 'u-default-funnel',
@ -197,8 +201,5 @@ export const leadOperation: MigrateOperation = {
}
}
])
// Currently space type has to be recreated every time as it's in the model
// created by the system user
await createSpaceType(ops)
}
}

View File

@ -75,11 +75,14 @@ export const recruitOperation: MigrateOperation = {
])
},
async upgrade (client: MigrationUpgradeClient): Promise<void> {
const tx = new TxOperations(client, core.account.System)
// For now need to be created every time as it's system model
await createDefaultKanbanTemplate(tx)
await tryUpgrade(client, recruitId, [
{
state: 'create-default-project',
func: async (client) => {
const tx = new TxOperations(client, core.account.System)
await createDefaults(tx)
}
},
@ -150,7 +153,6 @@ async function createDefaults (tx: TxOperations): Promise<void> {
await createSequence(tx, recruit.class.Opinion)
await createSequence(tx, recruit.class.Applicant)
await createSequence(tx, recruit.class.Vacancy)
await createDefaultKanbanTemplate(tx)
}
async function createDefaultKanbanTemplate (tx: TxOperations): Promise<Ref<ProjectType>> {

View File

@ -61,36 +61,6 @@ async function createDefaultProject (tx: TxOperations): Promise<void> {
objectId: tracker.project.DefaultProject
})
if ((await tx.findOne(task.class.ProjectType, { _id: tracker.ids.ClassingProjectType })) === undefined) {
const states: Omit<Data<Status>, 'rank'>[] = createStatesData(classicIssueTaskStatuses)
await createProjectType(
tx,
{
name: 'Classic project',
descriptor: tracker.descriptors.ProjectType,
description: '',
tasks: [],
roles: 0,
classic: true
},
[
{
_id: tracker.taskTypes.Issue,
descriptor: tracker.descriptors.Issue,
name: 'Issue',
factory: states,
ofClass: tracker.class.Issue,
targetClass: tracker.class.Issue,
statusCategories: classicIssueTaskStatuses.map((it) => it.category),
statusClass: core.class.Status,
kind: 'both',
allowedAsChildOf: [tracker.taskTypes.Issue]
}
],
tracker.ids.ClassingProjectType
)
}
// temporary disabled until nice automation
// if ((await tx.findOne(task.class.ProjectType, { _id: tracker.ids.BaseProjectType })) === undefined) {
// const issueId: Ref<TaskType> = generateId()
@ -154,6 +124,43 @@ async function createDefaultProject (tx: TxOperations): Promise<void> {
}
}
async function createDefaultProjectType (tx: TxOperations): Promise<void> {
const existing = await tx.findOne(task.class.ProjectType, { _id: tracker.ids.ClassingProjectType })
const existingDeleted = await tx.findOne(core.class.TxRemoveDoc, {
objectId: tracker.ids.ClassingProjectType
})
if (existing === undefined && existingDeleted === undefined) {
const states: Omit<Data<Status>, 'rank'>[] = createStatesData(classicIssueTaskStatuses)
await createProjectType(
tx,
{
name: 'Classic project',
descriptor: tracker.descriptors.ProjectType,
description: '',
tasks: [],
roles: 0,
classic: true
},
[
{
_id: tracker.taskTypes.Issue,
descriptor: tracker.descriptors.Issue,
name: 'Issue',
factory: states,
ofClass: tracker.class.Issue,
targetClass: tracker.class.Issue,
statusCategories: classicIssueTaskStatuses.map((it) => it.category),
statusClass: core.class.Status,
kind: 'both',
allowedAsChildOf: [tracker.taskTypes.Issue]
}
],
tracker.ids.ClassingProjectType
)
}
}
async function createDefaults (tx: TxOperations): Promise<void> {
await createDefaultProject(tx)
await createOrUpdate(
@ -644,11 +651,14 @@ export const trackerOperation: MigrateOperation = {
])
},
async upgrade (client: MigrationUpgradeClient): Promise<void> {
const tx = new TxOperations(client, core.account.System)
// For now need to be created every time as it's system model
await createDefaultProjectType(tx)
await tryUpgrade(client, trackerId, [
{
state: 'create-defaults',
func: async (client) => {
const tx = new TxOperations(client, core.account.System)
func: async () => {
await createDefaults(tx)
}
}