feat: populate relation join column (#10212)

Fix
https://github.com/twentyhq/core-team-issues/issues/241#issue-2793030259
This commit is contained in:
Jérémy M
2025-02-25 11:24:05 +01:00
committed by GitHub
parent dde70ee3b0
commit a1eea40cf7
49 changed files with 677 additions and 496 deletions

View File

@ -7,22 +7,22 @@ import { Command } from 'nest-commander';
import { Repository } from 'typeorm';
import {
ActiveWorkspacesCommandOptions,
ActiveWorkspacesCommandRunner,
} from 'src/database/commands/active-workspaces.command';
ActiveWorkspacesMigrationCommandOptions,
ActiveWorkspacesMigrationCommandRunner,
} from 'src/database/commands/migration-command/active-workspaces-migration-command.runner';
import { BillingCustomer } from 'src/engine/core-modules/billing/entities/billing-customer.entity';
import { StripeSubscriptionService } from 'src/engine/core-modules/billing/stripe/services/stripe-subscription.service';
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
interface SyncCustomerDataCommandOptions
extends ActiveWorkspacesCommandOptions {}
extends ActiveWorkspacesMigrationCommandOptions {}
@Command({
name: 'billing:sync-customer-data',
description: 'Sync customer data from Stripe for all active workspaces',
})
export class BillingSyncCustomerDataCommand extends ActiveWorkspacesCommandRunner {
export class BillingSyncCustomerDataCommand extends ActiveWorkspacesMigrationCommandRunner {
constructor(
@InjectRepository(Workspace, 'core')
protected readonly workspaceRepository: Repository<Workspace>,
@ -34,7 +34,7 @@ export class BillingSyncCustomerDataCommand extends ActiveWorkspacesCommandRunne
super(workspaceRepository, twentyORMGlobalManager);
}
async executeActiveWorkspacesCommand(
async runMigrationCommandOnActiveWorkspaces(
_passedParam: string[],
options: SyncCustomerDataCommandOptions,
workspaceIds: string[],

View File

@ -7,9 +7,9 @@ import Stripe from 'stripe';
import { Repository } from 'typeorm';
import {
BaseCommandOptions,
BaseCommandRunner,
} from 'src/database/commands/base.command';
MigrationCommandOptions,
MigrationCommandRunner,
} from 'src/database/commands/migration-command/migration-command.runner';
import { BillingMeter } from 'src/engine/core-modules/billing/entities/billing-meter.entity';
import { BillingPrice } from 'src/engine/core-modules/billing/entities/billing-price.entity';
import { BillingProduct } from 'src/engine/core-modules/billing/entities/billing-product.entity';
@ -25,7 +25,7 @@ import { transformStripeProductToDatabaseProduct } from 'src/engine/core-modules
description:
'Fetches from stripe the plans data (meter, product and price) and upserts it into the database',
})
export class BillingSyncPlansDataCommand extends BaseCommandRunner {
export class BillingSyncPlansDataCommand extends MigrationCommandRunner {
private readonly batchSize = 5;
constructor(
@InjectRepository(BillingPrice, 'core')
@ -43,7 +43,7 @@ export class BillingSyncPlansDataCommand extends BaseCommandRunner {
private async upsertMetersRepositoryData(
meters: Stripe.Billing.Meter[],
options: BaseCommandOptions,
options: MigrationCommandOptions,
) {
meters.map(async (meter) => {
try {
@ -64,7 +64,7 @@ export class BillingSyncPlansDataCommand extends BaseCommandRunner {
private async upsertProductRepositoryData(
product: Stripe.Product,
options: BaseCommandOptions,
options: MigrationCommandOptions,
) {
try {
if (!options.dryRun) {
@ -83,7 +83,7 @@ export class BillingSyncPlansDataCommand extends BaseCommandRunner {
private async getBillingPrices(
products: Stripe.Product[],
options: BaseCommandOptions,
options: MigrationCommandOptions,
): Promise<Stripe.Price[][]> {
return await Promise.all(
products.map(async (product) => {
@ -113,7 +113,7 @@ export class BillingSyncPlansDataCommand extends BaseCommandRunner {
private async processBillingPricesByProductBatches(
products: Stripe.Product[],
options: BaseCommandOptions,
options: MigrationCommandOptions,
) {
const prices: Stripe.Price[][] = [];
@ -135,9 +135,9 @@ export class BillingSyncPlansDataCommand extends BaseCommandRunner {
return prices;
}
override async executeBaseCommand(
override async runMigrationCommand(
passedParams: string[],
options: BaseCommandOptions,
options: MigrationCommandOptions,
): Promise<void> {
const billingMeters = await this.stripeBillingMeterService.getAllMeters();