From 4f922dca789b047bfb29fdd2557d4e2fc54ded00 Mon Sep 17 00:00:00 2001 From: Laszlo Kecskes Date: Thu, 18 Apr 2024 12:53:23 +0200 Subject: [PATCH] migration test and implementation --- .../165-default_empty_metadata/index.ts | 100 ++++++ .../specs/165-default_empty_metadata.spec.ts | 120 ++++++- .../specs/fixtures.ts | 294 ++++++++---------- .../165-default_empty_metadata/types.ts | 6 +- 4 files changed, 331 insertions(+), 189 deletions(-) diff --git a/app/api/migrations/migrations/165-default_empty_metadata/index.ts b/app/api/migrations/migrations/165-default_empty_metadata/index.ts index 29c5141f44..2e9442e2f6 100644 --- a/app/api/migrations/migrations/165-default_empty_metadata/index.ts +++ b/app/api/migrations/migrations/165-default_empty_metadata/index.ts @@ -1,4 +1,11 @@ +/* eslint-disable no-await-in-loop */ import { Db } from 'mongodb'; +import { Entity, Template } from './types'; + +let entitiesToUpdate: Entity[] = []; + +const propDoesNotExist = (obj: Record, prop: string) => + !obj.hasOwnProperty(prop) || obj[prop] === null || obj[prop] === undefined; export default { delta: 165, @@ -7,9 +14,102 @@ export default { description: 'Adds empty array as default metadata for all entities.', + batchSize: 1000, + reindex: false, + propertiesByTemplate: {} as Record, + + fullEmptyMetadataByTemplate: {} as Record>, + + async readProperties(db: Db) { + const templates = await db.collection