diff --git a/models/all/src/migration.ts b/models/all/src/migration.ts index 67316c969f..df2acd3521 100644 --- a/models/all/src/migration.ts +++ b/models/all/src/migration.ts @@ -18,5 +18,6 @@ import { MigrateOperation } from '@anticrm/model' // Import migrate operations. import { taskOperation } from '@anticrm/model-task' import { attachmentOperation } from '@anticrm/model-attachment' +import { leadOperation } from '@anticrm/model-lead' -export const migrateOperations: MigrateOperation[] = [taskOperation, attachmentOperation] +export const migrateOperations: MigrateOperation[] = [taskOperation, attachmentOperation, leadOperation] diff --git a/models/lead/src/index.ts b/models/lead/src/index.ts index 6aaa30f4ba..acbf62ce1b 100644 --- a/models/lead/src/index.ts +++ b/models/lead/src/index.ts @@ -141,3 +141,4 @@ export function createModel (builder: Builder): void { } export { default } from './plugin' +export { leadOperation } from './migration' diff --git a/models/lead/src/migration.ts b/models/lead/src/migration.ts new file mode 100644 index 0000000000..3533e90869 --- /dev/null +++ b/models/lead/src/migration.ts @@ -0,0 +1,46 @@ +// +// Copyright © 2020, 2021 Anticrm Platform Contributors. +// Copyright © 2021 Hardcore Engineering Inc. +// +// Licensed under the Eclipse Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. You may +// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import { Doc, TxOperations } from '@anticrm/core' +import { MigrateOperation, MigrationClient, MigrationUpgradeClient } from '@anticrm/model' +import core from '@anticrm/model-core' +import view from '@anticrm/model-view' +import { createKanban } from '@anticrm/lead' +import lead from './plugin' + +export const leadOperation: MigrateOperation = { + async migrate (client: MigrationClient): Promise<void> { + + }, + async upgrade (client: MigrationUpgradeClient): Promise<void> { + console.log('Lead: Performing model upgrades') + + const ops = new TxOperations(client, core.account.System) + if (await client.findOne(view.class.Kanban, { attachedTo: lead.space.DefaultFunnel }) === undefined) { + console.info('Create kanban for default funnel.') + await createKanban(lead.space.DefaultFunnel, async (_class, space, data, id) => { + const doc = await ops.findOne<Doc>(_class, { _id: id }) + if (doc === undefined) { + await ops.createDoc(_class, space, data, id) + } else { + await ops.updateDoc(_class, space, id, data) + } + }).catch((err) => console.error(err)) + } else { + console.log('Lead: => default funnel Kanban is ok') + } + } +}