diff --git a/models/inventory/src/migration.ts b/models/inventory/src/migration.ts index 515ba8551b..c657e925c3 100644 --- a/models/inventory/src/migration.ts +++ b/models/inventory/src/migration.ts @@ -13,9 +13,51 @@ // limitations under the License. // +import core, { TxOperations } from '@hcengineering/core' import { MigrateOperation, MigrationClient, MigrationUpgradeClient } from '@hcengineering/model' +import inventory from './plugin' + +async function createSpace (tx: TxOperations): Promise { + const categories = await tx.findOne(core.class.Space, { + _id: inventory.space.Category + }) + if (categories === undefined) { + await tx.createDoc( + core.class.Space, + core.space.Space, + { + name: 'Categories', + description: 'Categories', + private: false, + archived: false, + members: [] + }, + inventory.space.Category + ) + } + const products = await tx.findOne(core.class.Space, { + _id: inventory.space.Products + }) + if (products === undefined) { + await tx.createDoc( + core.class.Space, + core.space.Space, + { + name: 'Products', + description: 'Products', + private: false, + archived: false, + members: [] + }, + inventory.space.Products + ) + } +} export const inventoryOperation: MigrateOperation = { async migrate (client: MigrationClient): Promise {}, - async upgrade (client: MigrationUpgradeClient): Promise {} + async upgrade (client: MigrationUpgradeClient): Promise { + const tx = new TxOperations(client, core.account.System) + await createSpace(tx) + } }