Add billing tables (#8772)

Beforehand, the name of the branch is not representative of the work
that has been done in this PR

**TLDR:**

Solves https://github.com/twentyhq/private-issues/issues/192
Add 3 tables BillingCustomer, BillingProduct and BillingPrice and
BillingMeter to core, inspired by the Stripe implementation. Separates
migration, between common and billing on order to not populate the db of
the self-hosting instances with unused tables.

**In order to test:**

Run the command:
npx nx typeorm -- migration:run -d
src/database/typeorm/core/core.datasource.ts


**Considerations:**

I only put the information we should use right now in the Billing
module, for instance columns like meter or agreggation formula where
omitted in the creation of the tables.
These columns and other ones who fall on the same spectrum will be added
as we need them.

If you want to add more information to the table, I'll leave some
utility links down bellow:

- BillingPrices: https://docs.stripe.com/api/prices/object
- BillingCustomer: https://docs.stripe.com/api/customers/object
- BillingProduct:  https://docs.stripe.com/api/products/object

**Next Steps**

Use the Stripe Webhook in order to update the tables accordingly

---------

Co-authored-by: Félix Malfait <felix@twenty.com>
This commit is contained in:
Ana Sofia Marin Alexandre
2024-12-05 12:17:35 -03:00
committed by GitHub
parent c993f2de0b
commit 11d244194f
67 changed files with 824 additions and 102 deletions

View File

@ -18,9 +18,15 @@ export const typeORMCoreModuleOptions: TypeOrmModuleOptions = {
migrationsRun: false,
migrationsTableName: '_typeorm_migrations',
metadataTableName: '_typeorm_generated_columns_and_materialized_views',
migrations: [
`${isJest ? '' : 'dist/'}src/database/typeorm/core/migrations/*{.ts,.js}`,
],
migrations:
process.env.IS_BILLING_ENABLED === 'true'
? [
`${isJest ? '' : 'dist/'}src/database/typeorm/core/migrations/common/*{.ts,.js}`,
`${isJest ? '' : 'dist/'}src/database/typeorm/core/migrations/billing/*{.ts,.js}`,
]
: [
`${isJest ? '' : 'dist/'}src/database/typeorm/core/migrations/common/*{.ts,.js}`,
],
ssl:
process.env.PG_SSL_ALLOW_SELF_SIGNED === 'true'
? {

View File

@ -1,19 +0,0 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddIntervalToBillingSubscription1710926613773
implements MigrationInterface
{
name = 'AddIntervalToBillingSubscription1710926613773';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ADD "interval" character varying`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" DROP COLUMN "interval"`,
);
}
}

View File

@ -15,6 +15,9 @@ export class UpdateBillingCoreTables1709233666080
await queryRunner.query(
`ALTER TABLE "core"."billingSubscriptionItem" ADD CONSTRAINT "IndexOnBillingSubscriptionIdAndStripeProductIdUnique" UNIQUE ("billingSubscriptionId", "stripeProductId")`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscriptionItem" ALTER COLUMN "deletedAt" TYPE TIMESTAMP WITH TIME ZONE USING "deletedAt" AT TIME ZONE 'UTC'`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
@ -27,5 +30,8 @@ export class UpdateBillingCoreTables1709233666080
await queryRunner.query(
`ALTER TABLE "core"."billingSubscriptionItem" DROP COLUMN "stripeSubscriptionItemId"`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscriptionItem" ALTER COLUMN "deletedAt" TYPE TIMESTAMP`,
);
}
}

View File

@ -18,9 +18,27 @@ export class UpdateBillingSubscription1709914564361
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ADD CONSTRAINT "FK_4abfb70314c18da69e1bee1954d" FOREIGN KEY ("workspaceId") REFERENCES "core"."workspace"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "deletedAt" TYPE TIMESTAMP WITH TIME ZONE USING "deletedAt" AT TIME ZONE 'UTC'`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "status" TYPE text`,
);
await queryRunner.query(
`CREATE TYPE "core"."billingSubscription_status_enum" AS ENUM('active', 'canceled', 'incomplete', 'incomplete_expired', 'past_due', 'paused', 'trialing', 'unpaid')`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "status" TYPE "core"."billingSubscription_status_enum" USING "status"::"core"."billingSubscription_status_enum"`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "status" SET NOT NULL`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "status" DROP NOT NULL`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" DROP CONSTRAINT "FK_4abfb70314c18da69e1bee1954d"`,
);
@ -33,5 +51,17 @@ export class UpdateBillingSubscription1709914564361
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ADD CONSTRAINT "FK_4abfb70314c18da69e1bee1954d" FOREIGN KEY ("workspaceId") REFERENCES "core"."workspace"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "status" TYPE text`,
);
await queryRunner.query(
`DROP TYPE "core"."billingSubscription_status_enum"`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "status" TYPE character varying`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "deletedAt" TYPE TIMESTAMP`,
);
}
}

View File

@ -0,0 +1,34 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddIntervalToBillingSubscription1710926613773
implements MigrationInterface
{
name = 'AddIntervalToBillingSubscription1710926613773';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ADD "interval" character varying`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "interval" TYPE text`,
);
await queryRunner.query(
`CREATE TYPE "core"."billingSubscription_interval_enum" AS ENUM('day', 'month', 'week', 'year')`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "interval" TYPE "core"."billingSubscription_interval_enum" USING "interval"::"core"."billingSubscription_interval_enum"`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "interval" TYPE text`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" DROP COLUMN "interval"`,
);
await queryRunner.query(
`DROP TYPE "core"."billingSubscription_interval_enum"`,
);
}
}

View File

@ -0,0 +1,187 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddNewBillingStripeTables1733397937967
implements MigrationInterface
{
name = 'AddNewBillingStripeTables1733397937967';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "core"."billingCustomer" ("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(), "workspaceId" uuid NOT NULL, "stripeCustomerId" character varying NOT NULL, CONSTRAINT "UQ_b35a0ef2e2f0d40101dd7f161b9" UNIQUE ("stripeCustomerId"), CONSTRAINT "IndexOnWorkspaceIdAndStripeCustomerIdUnique" UNIQUE ("workspaceId", "stripeCustomerId"), CONSTRAINT "PK_5fffcd69bf722c297a3d5c3f3bc" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`CREATE TYPE "core"."billingMeter_status_enum" AS ENUM('ACTIVE', 'INACTIVE')`,
);
await queryRunner.query(
`CREATE TYPE "core"."billingMeter_eventtimewindow_enum" AS ENUM('DAY', 'HOUR')`,
);
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(
`CREATE TABLE "core"."billingProduct" ("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(), "active" boolean NOT NULL, "description" text, "name" character varying NOT NULL, "taxCode" text, "images" jsonb NOT NULL DEFAULT '[]', "marketingFeatures" jsonb NOT NULL DEFAULT '[]', "stripeProductId" character varying NOT NULL, "defaultStripePriceId" text, "metadata" jsonb NOT NULL DEFAULT '{}', "unitLabel" text, "url" text, CONSTRAINT "UQ_1ba1ba118792aa9eec92f132e82" UNIQUE ("stripeProductId"), CONSTRAINT "PK_8bb3c7be66db8e05476808b0ca7" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`CREATE TYPE "core"."billingPrice_taxbehavior_enum" AS ENUM('EXCLUSIVE', 'INCLUSIVE', 'UNSPECIFIED')`,
);
await queryRunner.query(
`CREATE TYPE "core"."billingPrice_type_enum" AS ENUM('ONE_TIME', 'RECURRING')`,
);
await queryRunner.query(
`CREATE TYPE "core"."billingPrice_billingscheme_enum" AS ENUM('PER_UNIT', 'TIERED')`,
);
await queryRunner.query(
`CREATE TYPE "core"."billingPrice_tiersmode_enum" AS ENUM('GRADUATED', 'VOLUME')`,
);
await queryRunner.query(
`CREATE TYPE "core"."billingPrice_usagetype_enum" AS ENUM('METERED', 'LICENSED')`,
);
await queryRunner.query(
`CREATE TYPE "core"."billingPrice_interval_enum" AS ENUM('day', 'month', 'week', 'year')`,
);
await queryRunner.query(
`CREATE TABLE "core"."billingPrice" ("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(), "stripePriceId" character varying NOT NULL, "active" boolean NOT NULL, "stripeProductId" character varying NOT NULL, "currency" character varying NOT NULL, "nickname" text, "taxBehavior" "core"."billingPrice_taxbehavior_enum" NOT NULL, "type" "core"."billingPrice_type_enum" NOT NULL, "billingScheme" "core"."billingPrice_billingscheme_enum" NOT NULL, "currencyOptions" jsonb, "tiers" jsonb, "recurring" jsonb, "transformQuantity" jsonb, "tiersMode" "core"."billingPrice_tiersmode_enum", "unitAmountDecimal" text, "unitAmount" numeric, "stripeMeterId" character varying, "usageType" "core"."billingPrice_usagetype_enum" NOT NULL, "interval" "core"."billingPrice_interval_enum", CONSTRAINT "UQ_f66d20a329f5f4b9d12afeae7d0" UNIQUE ("stripePriceId"), CONSTRAINT "PK_13927aef8d4e68e176a61c33d89" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscriptionItem" ADD "stripeSubscriptionId" character varying`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscriptionItem" ADD "metadata" jsonb NOT NULL DEFAULT '{}'`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscriptionItem" ADD "billingThresholds" jsonb`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ADD "cancelAtPeriodEnd" boolean NOT NULL DEFAULT false`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ADD "currency" character varying NOT NULL DEFAULT 'USD'`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ADD "currentPeriodEnd" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ADD "currentPeriodStart" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ADD "metadata" jsonb NOT NULL DEFAULT '{}'`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ADD "cancelAt" TIMESTAMP WITH TIME ZONE`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ADD "canceledAt" TIMESTAMP WITH TIME ZONE`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ADD "automaticTax" jsonb`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ADD "cancellationDetails" jsonb`,
);
await queryRunner.query(
`CREATE TYPE "core"."billingSubscription_collectionmethod_enum" AS ENUM('CHARGE_AUTOMATICALLY', 'SEND_INVOICE')`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ADD "collectionMethod" "core"."billingSubscription_collectionmethod_enum" NOT NULL DEFAULT 'CHARGE_AUTOMATICALLY'`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ADD "endedAt" TIMESTAMP WITH TIME ZONE`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ADD "trialStart" TIMESTAMP WITH TIME ZONE`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ADD "trialEnd" TIMESTAMP WITH TIME ZONE`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingCustomer" ADD CONSTRAINT "FK_53c2ef50e9611082f83d760897d" FOREIGN KEY ("workspaceId") REFERENCES "core"."workspace"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingPrice" ADD CONSTRAINT "FK_4d57ee4dbfc8b4075eb24026fca" FOREIGN KEY ("stripeProductId") REFERENCES "core"."billingProduct"("stripeProductId") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingPrice" ADD CONSTRAINT "FK_c8b4375b7bf8724ba54065372e1" FOREIGN KEY ("stripeMeterId") REFERENCES "core"."billingMeter"("stripeMeterId") ON DELETE NO ACTION ON UPDATE NO ACTION`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "core"."billingPrice" DROP CONSTRAINT "FK_c8b4375b7bf8724ba54065372e1"`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingPrice" DROP CONSTRAINT "FK_4d57ee4dbfc8b4075eb24026fca"`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingCustomer" DROP CONSTRAINT "FK_53c2ef50e9611082f83d760897d"`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" DROP COLUMN "trialEnd"`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" DROP COLUMN "trialStart"`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" DROP COLUMN "endedAt"`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" DROP COLUMN "collectionMethod"`,
);
await queryRunner.query(
`DROP TYPE "core"."billingSubscription_collectionmethod_enum"`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" DROP COLUMN "cancellationDetails"`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" DROP COLUMN "automaticTax"`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" DROP COLUMN "canceledAt"`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" DROP COLUMN "cancelAt"`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" DROP COLUMN "metadata"`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" DROP COLUMN "currentPeriodStart"`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" DROP COLUMN "currentPeriodEnd"`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" DROP COLUMN "currency"`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" DROP COLUMN "cancelAtPeriodEnd"`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscriptionItem" DROP COLUMN "billingThresholds"`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscriptionItem" DROP COLUMN "metadata"`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscriptionItem" DROP COLUMN "stripeSubscriptionId"`,
);
await queryRunner.query(`DROP TABLE "core"."billingPrice"`);
await queryRunner.query(`DROP TYPE "core"."billingPrice_interval_enum"`);
await queryRunner.query(`DROP TYPE "core"."billingPrice_usagetype_enum"`);
await queryRunner.query(`DROP TYPE "core"."billingPrice_tiersmode_enum"`);
await queryRunner.query(
`DROP TYPE "core"."billingPrice_billingscheme_enum"`,
);
await queryRunner.query(`DROP TYPE "core"."billingPrice_type_enum"`);
await queryRunner.query(`DROP TYPE "core"."billingPrice_taxbehavior_enum"`);
await queryRunner.query(`DROP TABLE "core"."billingProduct"`);
await queryRunner.query(`DROP TABLE "core"."billingMeter"`);
await queryRunner.query(
`DROP TYPE "core"."billingMeter_eventtimewindow_enum"`,
);
await queryRunner.query(`DROP TYPE "core"."billingMeter_status_enum"`);
await queryRunner.query(`DROP TABLE "core"."billingCustomer"`);
}
}

View File

@ -10,12 +10,7 @@ export class UseTimestampWithTZ1711633823798 implements MigrationInterface {
await queryRunner.query(
`ALTER TABLE "core"."featureFlag" ALTER COLUMN "updatedAt" TYPE TIMESTAMP WITH TIME ZONE USING "updatedAt" AT TIME ZONE 'UTC'`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscriptionItem" ALTER COLUMN "deletedAt" TYPE TIMESTAMP WITH TIME ZONE USING "deletedAt" AT TIME ZONE 'UTC'`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "deletedAt" TYPE TIMESTAMP WITH TIME ZONE USING "deletedAt" AT TIME ZONE 'UTC'`,
);
await queryRunner.query(
`ALTER TABLE "core"."workspace" ALTER COLUMN "deletedAt" TYPE TIMESTAMP WITH TIME ZONE USING "deletedAt" AT TIME ZONE 'UTC'`,
);
@ -43,12 +38,7 @@ export class UseTimestampWithTZ1711633823798 implements MigrationInterface {
await queryRunner.query(
`ALTER TABLE "core"."featureFlag" ALTER COLUMN "updatedAt" TYPE TIMESTAMP`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscriptionItem" ALTER COLUMN "deletedAt" TYPE TIMESTAMP`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "deletedAt" TYPE TIMESTAMP`,
);
await queryRunner.query(
`ALTER TABLE "core"."workspace" ALTER COLUMN "deletedAt" TYPE TIMESTAMP`,
);

View File

@ -9,12 +9,7 @@ export class UpdateInconsistentUserConstraint1715593226719
await queryRunner.query(
`ALTER TABLE "core"."user" DROP CONSTRAINT "FK_2ec910029395fa7655621c88908"`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "status" TYPE text`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "interval" TYPE text`,
);
await queryRunner.query(
`ALTER TABLE "core"."workspace" ALTER COLUMN "subscriptionStatus" TYPE text`,
);
@ -30,12 +25,6 @@ export class UpdateInconsistentUserConstraint1715593226719
await queryRunner.query(
`ALTER TABLE "core"."workspace" ALTER COLUMN "subscriptionStatus" TYPE character varying`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "interval" TYPE character varying`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "status" TYPE character varying`,
);
await queryRunner.query(
`ALTER TABLE "core"."user" ADD CONSTRAINT "FK_2ec910029395fa7655621c88908" FOREIGN KEY ("defaultWorkspaceId") REFERENCES "core"."workspace"("id") ON DELETE SET NULL ON UPDATE NO ACTION`,
);

View File

@ -6,21 +6,6 @@ export class UseEnumForSubscriptionStatusInterval1719327438923
name = 'UseEnumForSubscriptionStatusInterval1719327438923';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TYPE "core"."billingSubscription_status_enum" AS ENUM('active', 'canceled', 'incomplete', 'incomplete_expired', 'past_due', 'paused', 'trialing', 'unpaid')`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "status" TYPE "core"."billingSubscription_status_enum" USING "status"::"core"."billingSubscription_status_enum"`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "status" SET NOT NULL`,
);
await queryRunner.query(
`CREATE TYPE "core"."billingSubscription_interval_enum" AS ENUM('day', 'month', 'week', 'year')`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "interval" TYPE "core"."billingSubscription_interval_enum" USING "interval"::"core"."billingSubscription_interval_enum"`,
);
await queryRunner.query(
`CREATE TYPE "core"."workspace_subscriptionstatus_enum" AS ENUM('active', 'canceled', 'incomplete', 'incomplete_expired', 'past_due', 'paused', 'trialing', 'unpaid')`,
);
@ -45,17 +30,5 @@ export class UseEnumForSubscriptionStatusInterval1719327438923
await queryRunner.query(
`DROP TYPE "core"."workspace_subscriptionstatus_enum"`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "interval" TYPE text`,
);
await queryRunner.query(
`DROP TYPE "core"."billingSubscription_interval_enum"`,
);
await queryRunner.query(
`ALTER TABLE "core"."billingSubscription" ALTER COLUMN "status" TYPE text`,
);
await queryRunner.query(
`DROP TYPE "core"."billingSubscription_status_enum"`,
);
}
}

View File

@ -3,7 +3,11 @@ import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
import { DataSource } from 'typeorm';
import { AppToken } from 'src/engine/core-modules/app-token/app-token.entity';
import { BillingCustomer } from 'src/engine/core-modules/billing/entities/billing-customer.entity';
import { BillingEntitlement } from 'src/engine/core-modules/billing/entities/billing-entitlement.entity';
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';
import { BillingSubscriptionItem } from 'src/engine/core-modules/billing/entities/billing-subscription-item.entity';
import { BillingSubscription } from 'src/engine/core-modules/billing/entities/billing-subscription.entity';
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
@ -36,6 +40,10 @@ export class TypeORMService implements OnModuleInit, OnModuleDestroy {
FeatureFlagEntity,
BillingSubscription,
BillingSubscriptionItem,
BillingMeter,
BillingCustomer,
BillingProduct,
BillingPrice,
BillingEntitlement,
PostgresCredentials,
WorkspaceSSOIdentityProvider,