Skip to content

The open alternative to Salesforce, designed for AI.

fix(billing): drop billingPrice.stripeMeterId before dropping billingMeter (#28435)

Etienned8bcef6dbe01
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-50/2-50-instance-command-fast-1792480059403-drop-billing-meter-table.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-50/2-50-instance-command-fast-1792480059403-drop-billing-meter-table.ts
index f4d1d4c1d29..7f6a8685514 100644
--- a/packages/twenty-server/src/database/commands/upgrade-version-command/2-50/2-50-instance-command-fast-1792480059403-drop-billing-meter-table.ts
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-50/2-50-instance-command-fast-1792480059403-drop-billing-meter-table.ts
@@ -6,6 +6,9 @@ import { FastInstanceCommand } from 'src/engine/core-modules/upgrade/interfaces/
@RegisteredInstanceCommand('2.50.0', 1792480059403)
export class DropBillingMeterTableFastInstanceCommand implements FastInstanceCommand {
public async up(queryRunner: QueryRunner): Promise<void> {
+ await queryRunner.query(
+ `ALTER TABLE IF EXISTS "core"."billingPrice" DROP COLUMN IF EXISTS "stripeMeterId"`,
+ );
await queryRunner.query(`DROP TABLE IF EXISTS "core"."billingMeter"`);
await queryRunner.query(
`DROP TYPE IF EXISTS "core"."billingMeter_eventtimewindow_enum"`,
@@ -33,5 +36,8 @@ export class DropBillingMeterTableFastInstanceCommand implements FastInstanceCom
await queryRunner.query(
`CREATE TABLE "core"."billingMeter" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "deletedAt" TIMESTAMP WITH TIME ZONE, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "stripeMeterId" character varying NOT NULL, "displayName" character varying NOT NULL, "eventName" character varying NOT NULL, "status" "core"."billingMeter_status_enum" NOT NULL, "customerMapping" jsonb NOT NULL, "eventTimeWindow" "core"."billingMeter_eventtimewindow_enum", "valueSettings" jsonb NOT NULL, CONSTRAINT "UQ_340c08c4e5dd33cf963cbb133ae" UNIQUE ("stripeMeterId"), CONSTRAINT "PK_0bba5f7d2e3713332a0138ea1b3" PRIMARY KEY ("id"))`,
);
+ await queryRunner.query(
+ `ALTER TABLE "core"."billingPrice" ADD COLUMN "stripeMeterId" character varying`,
+ );
}
}
diff --git a/packages/twenty-server/src/engine/core-modules/billing-webhook/utils/__tests__/transform-stripe-price-event-to-database-price.util.spec.ts b/packages/twenty-server/src/engine/core-modules/billing-webhook/utils/__tests__/transform-stripe-price-event-to-database-price.util.spec.ts
index 0b18a92087c..21da1c8e955 100644
--- a/packages/twenty-server/src/engine/core-modules/billing-webhook/utils/__tests__/transform-stripe-price-event-to-database-price.util.spec.ts
+++ b/packages/twenty-server/src/engine/core-modules/billing-webhook/utils/__tests__/transform-stripe-price-event-to-database-price.util.spec.ts
@@ -39,7 +39,6 @@ describe('transformStripePriceEventToDatabasePrice', () => {
stripePriceId: 'price_123',
active: true,
stripeProductId: 'prod_123',
- stripeMeterId: undefined,
currency: 'USD',
nickname: undefined,
taxBehavior: undefined,
@@ -172,7 +171,6 @@ describe('transformStripePriceEventToDatabasePrice', () => {
const result = transformStripePriceEventToDatabasePrice(mockData as any);
- expect(result.stripeMeterId).toBe('meter_123');
expect(result.usageType).toBe(BillingUsageType.METERED);
expect(result.transformQuantity).toEqual(mockTransformQuantity);
});
diff --git a/packages/twenty-server/src/engine/core-modules/billing-webhook/utils/transform-stripe-price-event-to-database-price.util.ts b/packages/twenty-server/src/engine/core-modules/billing-webhook/utils/transform-stripe-price-event-to-database-price.util.ts
index 561a3991141..ea7b861d6a4 100644
--- a/packages/twenty-server/src/engine/core-modules/billing-webhook/utils/transform-stripe-price-event-to-database-price.util.ts
+++ b/packages/twenty-server/src/engine/core-modules/billing-webhook/utils/transform-stripe-price-event-to-database-price.util.ts
@@ -15,7 +15,6 @@ export const transformStripePriceEventToDatabasePrice = (
stripePriceId: data.id,
active: data.active,
stripeProductId: String(data.product),
- stripeMeterId: data.recurring?.meter,
currency: data.currency.toUpperCase(),
nickname: data.nickname === null ? undefined : data.nickname,
taxBehavior: data.tax_behavior
diff --git a/packages/twenty-server/src/engine/core-modules/billing/entities/billing-price.entity.ts b/packages/twenty-server/src/engine/core-modules/billing/entities/billing-price.entity.ts
index 5f848ae18c6..55e8baebd73 100644
--- a/packages/twenty-server/src/engine/core-modules/billing/entities/billing-price.entity.ts
+++ b/packages/twenty-server/src/engine/core-modules/billing/entities/billing-price.entity.ts
@@ -91,9 +91,6 @@ export class BillingPriceEntity {
@Column({ nullable: true, type: 'numeric' })
unitAmount: number | null;
- @Column({ nullable: true, type: 'text' })
- stripeMeterId: string | null;
-
@Column({ nullable: false, type: 'jsonb', default: {} })
metadata: BillingPriceMetadata;
diff --git a/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/transform-stripe-price-to-database-price.util.spec.ts b/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/transform-stripe-price-to-database-price.util.spec.ts
index 3d7f2fc7e54..18a8ae0d5ac 100644
--- a/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/transform-stripe-price-to-database-price.util.spec.ts
+++ b/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/transform-stripe-price-to-database-price.util.spec.ts
@@ -40,7 +40,6 @@ describe('transformStripePriceToDatabasePrice', () => {
stripePriceId: 'price_123',
active: true,
stripeProductId: 'prod_123',
- stripeMeterId: null,
currency: 'USD',
nickname: undefined,
taxBehavior: undefined,
@@ -128,7 +127,7 @@ describe('transformStripePriceToDatabasePrice', () => {
});
describe('recurring price configurations', () => {
- it('should handle metered pricing with meter ID', () => {
+ it('should handle metered pricing', () => {
const mockPrice = createMockPrice({
recurring: {
usage_type: 'metered',
@@ -138,7 +137,6 @@ describe('transformStripePriceToDatabasePrice', () => {
});
const result = transformStripePriceToDatabasePrice(mockPrice);
- expect(result.stripeMeterId).toBe('meter_123');
expect(result.usageType).toBe(BillingUsageType.METERED);
});
diff --git a/packages/twenty-server/src/engine/core-modules/billing/utils/transform-stripe-price-to-database-price.util.ts b/packages/twenty-server/src/engine/core-modules/billing/utils/transform-stripe-price-to-database-price.util.ts
index 10199e389dc..4ed29750771 100644
--- a/packages/twenty-server/src/engine/core-modules/billing/utils/transform-stripe-price-to-database-price.util.ts
+++ b/packages/twenty-server/src/engine/core-modules/billing/utils/transform-stripe-price-to-database-price.util.ts
@@ -13,7 +13,6 @@ export const transformStripePriceToDatabasePrice = (data: Stripe.Price) => {
stripePriceId: data.id,
active: data.active,
stripeProductId: String(data.product),
- stripeMeterId: data.recurring?.meter,
currency: data.currency.toUpperCase(),
nickname: data.nickname === null ? undefined : data.nickname,
taxBehavior: data.tax_behavior
diff --git a/packages/twenty-server/test/integration/billing/suites/billing-controller.integration-spec.ts b/packages/twenty-server/test/integration/billing/suites/billing-controller.integration-spec.ts
index 5eeb503ea1e..696209ebda7 100644
--- a/packages/twenty-server/test/integration/billing/suites/billing-controller.integration-spec.ts
+++ b/packages/twenty-server/test/integration/billing/suites/billing-controller.integration-spec.ts
@@ -37,7 +37,6 @@ describe('BillingController (integration)', () => {
.expect(200)
.then((res) => {
expect(res.body.stripePriceId).toBeDefined();
- expect(res.body.stripeMeterId).toBeDefined();
});
});
it('should handle subscription.created webhook event', async () => {