From f6a0561ad483d89f1c12377055f7aa3171a8ab22 Mon Sep 17 00:00:00 2001 From: kravchenkodhealth <106426895+kravchenkodhealth@users.noreply.github.com> Date: Thu, 5 Jan 2023 18:39:24 +0200 Subject: [PATCH] [@dhealthdapps/backend] fix(database): create migration for activity --- .../migrations/005-AddMockedActivities.ts | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 runtime/backend/migrations/005-AddMockedActivities.ts diff --git a/runtime/backend/migrations/005-AddMockedActivities.ts b/runtime/backend/migrations/005-AddMockedActivities.ts new file mode 100644 index 00000000..f6047dff --- /dev/null +++ b/runtime/backend/migrations/005-AddMockedActivities.ts @@ -0,0 +1,74 @@ +/** + * This file is part of dHealth dApps Framework shared under LGPL-3.0 + * Copyright (C) 2022-present dHealth Network, All rights reserved. + * + * @package dHealth dApps Framework + * @subpackage Backend + * @author dHealth Network + * @license LGPL-3.0 + */ +// external dependencies +import { MigrationInterface } from "mongo-migrate-ts"; +import { Db } from "mongodb"; +import mongoose from "mongoose"; +/** + * @label DATABASE + * @class AddActivityPayoutFields + * @description This migration consists in one or more database + * schema and/or data updates. The following tasks are run: + * - Update the `activities` collection by creating new fields + * including: `payoutState` and `queuePosition`. + * + * @since v0.4.1 + */ +export class Test implements MigrationInterface { + async up(db: Db): Promise { + // uses collection `activities` + const collection = db.collection("activities"); + // update many `activities` documents such that + // - the `payoutState` field contains 0 (Not_Started) + await collection.insertOne({ + _id: new mongoose.Types.ObjectId("63529c31904bb2acae61d82a"), + address: "NBZTCWH3FCWBEPX2MR2GLDHHIVBKWGQWDEP6C7Q", + slug: "20221021-5-7996869084-96231663", + __v: 0, + activityAssets: [], + activityData: { + slug: "20221021-5-7996869084-96231663", + address: "NBZTCWH3FCWBEPX2MR2GLDHHIVBKWGQWDEP6C7Q", + name: "something", + sport: "Run", + startedAt: 1666354701000, + timezone: "(GMT+01:00) Europe/Madrid", + startLocation: [], + endLocation: [], + hasTrainerDevice: false, + elapsedTime: 3600, + movingTime: 3600, + distance: 9000, + elevation: 0, + kilojoules: 0, + calories: 0, + createdAt: new Date("2022-10-21T13:18:42.321Z"), + updatedAt: new Date("2022-10-21T13:18:42.321Z"), + _id: new mongoose.Types.ObjectId("63529c328873f89bf59c25a7"), + }, + createdAt: new Date("2022-10-21T13:18:41.375Z"), + dateSlug: "20221021", + processingState: 0, + provider: "strava", + remoteIdentifier: "7996869084", + updatedAt: new Date("2022-10-21T13:18:42.321Z"), + }); + // creates an index for field `payoutState` + await collection.createIndex("payoutState"); + } + async down(db: Db): Promise { + // uses collection `activities` + const collection = db.collection("activities"); + // delete item + await collection.deleteOne({ + _id: new mongoose.Types.ObjectId("63529c31904bb2acae61d82a"), + }); + } +}