Skip to content

Commit

Permalink
[@dhealthdapps/backend] fix(database): create migration for activity
Browse files Browse the repository at this point in the history
  • Loading branch information
kravchenkodhealth authored and evias committed Jan 9, 2023
1 parent 6c024a7 commit f6a0561
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions runtime/backend/migrations/005-AddMockedActivities.ts
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
* @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<any> {
// 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<any> {
// uses collection `activities`
const collection = db.collection("activities");
// delete item
await collection.deleteOne({
_id: new mongoose.Types.ObjectId("63529c31904bb2acae61d82a"),
});
}
}

0 comments on commit f6a0561

Please sign in to comment.