Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@dhealthdapps/backend] feat(database): add migration for removing ac… #122

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion runtime/backend/config/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. ` +
Expand Down
50 changes: 50 additions & 0 deletions runtime/backend/migrations/006-RemoveIntegrations.ts
Original file line number Diff line number Diff line change
@@ -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 <[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 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<any> {
// 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",
});
}
}