2024-06-14 11:09:53 +00:00
|
|
|
import DataMigrationBase from "./DataMigrationBase";
|
|
|
|
import LIMIT_MAX from "Common/Types/Database/LimitMax";
|
|
|
|
import Sleep from "Common/Types/Sleep";
|
|
|
|
import { IsBillingEnabled } from "CommonServer/EnvironmentConfig";
|
|
|
|
import ProjectService from "CommonServer/Services/ProjectService";
|
|
|
|
import AllMeteredPlans from "CommonServer/Types/Billing/MeteredPlan/AllMeteredPlans";
|
|
|
|
import QueryHelper from "CommonServer/Types/Database/QueryHelper";
|
2024-08-05 19:00:31 +00:00
|
|
|
import Project from "Common/Models/DatabaseModels/Project";
|
2024-01-11 10:49:55 +00:00
|
|
|
|
|
|
|
export default class UpdateActiveMonitorCountToBillingProvider extends DataMigrationBase {
|
2024-06-14 11:09:53 +00:00
|
|
|
public constructor() {
|
|
|
|
super("UpdateActiveMonitorCountToBillingProvider");
|
|
|
|
}
|
2024-01-11 10:49:55 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
public override async migrate(): Promise<void> {
|
|
|
|
if (!IsBillingEnabled) {
|
|
|
|
return;
|
|
|
|
}
|
2024-01-11 10:49:55 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
const projects: Array<Project> = await ProjectService.findBy({
|
|
|
|
query: {
|
|
|
|
paymentProviderMeteredSubscriptionId: QueryHelper.notNull(),
|
|
|
|
},
|
|
|
|
select: {
|
|
|
|
_id: true,
|
|
|
|
paymentProviderMeteredSubscriptionId: true,
|
|
|
|
},
|
|
|
|
limit: LIMIT_MAX,
|
|
|
|
skip: 0,
|
|
|
|
props: {
|
|
|
|
isRoot: true,
|
|
|
|
},
|
|
|
|
});
|
2024-01-11 10:49:55 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
for (const project of projects) {
|
|
|
|
for (const meteredPlan of AllMeteredPlans) {
|
|
|
|
await meteredPlan.reportQuantityToBillingProvider(project.id!, {});
|
|
|
|
}
|
2024-01-11 10:49:55 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
await Sleep.sleep(100);
|
2024-01-11 10:49:55 +00:00
|
|
|
}
|
2024-06-14 11:09:53 +00:00
|
|
|
}
|
2024-01-11 10:49:55 +00:00
|
|
|
|
2024-06-14 11:09:53 +00:00
|
|
|
public override async rollback(): Promise<void> {
|
|
|
|
return;
|
|
|
|
}
|
2024-01-11 10:49:55 +00:00
|
|
|
}
|