diff --git a/runtime/backend/config/migrations.ts b/runtime/backend/config/migrations.ts index 5cf0ab26..b90f06b6 100644 --- a/runtime/backend/config/migrations.ts +++ b/runtime/backend/config/migrations.ts @@ -25,7 +25,8 @@ let rootFolderPath = : `${__dirname}/../../..`; // runtime/backend/config // environment configuration -const envFilePath = `${rootFolderPath}/.env`; +const envFilePath = `${rootFolderPath}/env/${(process.env.NODE_ENV = + "development")}.env`; if (!fs.existsSync(envFilePath)) { throw new Error( `An error occurred configuring the database migrations. ` + diff --git a/runtime/backend/migrations/006-RemoveIntegrations.ts b/runtime/backend/migrations/006-RemoveIntegrations.ts new file mode 100644 index 00000000..27a3bb00 --- /dev/null +++ b/runtime/backend/migrations/006-RemoveIntegrations.ts @@ -0,0 +1,50 @@ +/** + * 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 RemoveIntegrations + * @description This migration consists in one or more database + * schema and/or data updates. The following tasks are run: + * - Remove accountintegrations that were created before 18.01.2023 + * @since v0.6.0 + */ +export class RemoveIntegrations implements MigrationInterface { + async up(db: Db): Promise { + // uses collection `accountintegrations` + const collection = db.collection("accountintegrations"); + + await collection.deleteMany({ + createdAt: { $lt: new Date(2023, 0, 18) }, + }); + } + + async down(db: Db) { + // uses collection `accountintegrations` + const collection = db.collection("accountintegrations"); + // create one activity with date earlier than 18.01.2023 + await collection.insertOne({ + _id: new mongoose.Types.ObjectId("63c18d84648b5b53bdf54af3"), + address: "NATZJETZTZCGGRBUYVQRBEUFN5LEGDRSTNF2GYA", + name: "strava", + __v: 0, + authorizationHash: "fakeHashShouldNotWork", + createdAt: new Date(2023, 0, 13), + updatedAt: new Date(2023, 0, 13), + encAccessToken: "fakeTokenShouldNotWork", + encRefreshToken: "fakeTokenShouldNotWork2", + expiresAt: 1673647946000, + remoteIdentifier: "fakeIdentifier", + }); + } +}