mirror of
https://github.com/twentyhq/twenty.git
synced 2024-09-11 23:37:21 +03:00
45 create billing core tables (#4096)
* Add self billing feature flag * Add two core tables for billing * Remove useless imports * Remove graphql decorators * Rename subscriptionProduct table
This commit is contained in:
parent
f407c70356
commit
d4fac2ea70
@ -155,6 +155,7 @@
|
|||||||
"scroll-into-view": "^1.16.2",
|
"scroll-into-view": "^1.16.2",
|
||||||
"semver": "^7.5.4",
|
"semver": "^7.5.4",
|
||||||
"sharp": "^0.32.1",
|
"sharp": "^0.32.1",
|
||||||
|
"stripe": "^14.17.0",
|
||||||
"ts-key-enum": "^2.0.12",
|
"ts-key-enum": "^2.0.12",
|
||||||
"tslib": "^2.3.0",
|
"tslib": "^2.3.0",
|
||||||
"tsup": "^8.0.1",
|
"tsup": "^8.0.1",
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [],
|
||||||
|
})
|
||||||
|
export class BillingModule {}
|
@ -0,0 +1,46 @@
|
|||||||
|
import {
|
||||||
|
Column,
|
||||||
|
CreateDateColumn,
|
||||||
|
Entity,
|
||||||
|
ManyToOne,
|
||||||
|
PrimaryGeneratedColumn,
|
||||||
|
UpdateDateColumn,
|
||||||
|
} from 'typeorm';
|
||||||
|
|
||||||
|
import { BillingSubscription } from 'src/core/billing/entities/billing-subscription.entity';
|
||||||
|
|
||||||
|
@Entity({ name: 'billingSubscriptionItem', schema: 'core' })
|
||||||
|
export class BillingSubscriptionItem {
|
||||||
|
@PrimaryGeneratedColumn('uuid')
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
@Column({ nullable: true })
|
||||||
|
deletedAt?: Date;
|
||||||
|
|
||||||
|
@CreateDateColumn({ type: 'timestamp with time zone' })
|
||||||
|
createdAt: Date;
|
||||||
|
|
||||||
|
@UpdateDateColumn({ type: 'timestamp with time zone' })
|
||||||
|
updatedAt: Date;
|
||||||
|
|
||||||
|
@Column({ nullable: false })
|
||||||
|
billingSubscriptionId: string;
|
||||||
|
|
||||||
|
@ManyToOne(
|
||||||
|
() => BillingSubscription,
|
||||||
|
(billingSubscription) => billingSubscription.billingSubscriptionItems,
|
||||||
|
{
|
||||||
|
onDelete: 'CASCADE',
|
||||||
|
},
|
||||||
|
)
|
||||||
|
billingSubscription: BillingSubscription;
|
||||||
|
|
||||||
|
@Column({ nullable: false })
|
||||||
|
stripeProductId: string;
|
||||||
|
|
||||||
|
@Column({ nullable: false })
|
||||||
|
stripePriceId: string;
|
||||||
|
|
||||||
|
@Column({ nullable: false })
|
||||||
|
quantity: number;
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
import {
|
||||||
|
Column,
|
||||||
|
CreateDateColumn,
|
||||||
|
Entity,
|
||||||
|
JoinColumn,
|
||||||
|
OneToMany,
|
||||||
|
OneToOne,
|
||||||
|
PrimaryGeneratedColumn,
|
||||||
|
UpdateDateColumn,
|
||||||
|
} from 'typeorm';
|
||||||
|
import Stripe from 'stripe';
|
||||||
|
|
||||||
|
import { Workspace } from 'src/core/workspace/workspace.entity';
|
||||||
|
import { BillingSubscriptionItem } from 'src/core/billing/entities/billing-subscription-item.entity';
|
||||||
|
|
||||||
|
@Entity({ name: 'billingSubscription', schema: 'core' })
|
||||||
|
export class BillingSubscription {
|
||||||
|
@PrimaryGeneratedColumn('uuid')
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
@Column({ nullable: true })
|
||||||
|
deletedAt?: Date;
|
||||||
|
|
||||||
|
@CreateDateColumn({ type: 'timestamp with time zone' })
|
||||||
|
createdAt: Date;
|
||||||
|
|
||||||
|
@UpdateDateColumn({ type: 'timestamp with time zone' })
|
||||||
|
updatedAt: Date;
|
||||||
|
|
||||||
|
@OneToOne(() => Workspace, (workspace) => workspace.billingSubscription, {
|
||||||
|
onDelete: 'CASCADE',
|
||||||
|
})
|
||||||
|
@JoinColumn()
|
||||||
|
workspace: Workspace;
|
||||||
|
|
||||||
|
@Column({ nullable: false, type: 'uuid' })
|
||||||
|
workspaceId: string;
|
||||||
|
|
||||||
|
@Column({ unique: true, nullable: false })
|
||||||
|
stripeCustomerId: string;
|
||||||
|
|
||||||
|
@Column({ unique: true, nullable: false })
|
||||||
|
stripeSubscriptionId: string;
|
||||||
|
|
||||||
|
@Column({ nullable: false })
|
||||||
|
status: Stripe.Subscription.Status;
|
||||||
|
|
||||||
|
@OneToMany(
|
||||||
|
() => BillingSubscriptionItem,
|
||||||
|
(billingSubscriptionItem) => billingSubscriptionItem.billingSubscription,
|
||||||
|
)
|
||||||
|
billingSubscriptionItems: BillingSubscriptionItem[];
|
||||||
|
}
|
@ -8,6 +8,7 @@ import { ApiRestModule } from 'src/core/api-rest/api-rest.module';
|
|||||||
import { FeatureFlagModule } from 'src/core/feature-flag/feature-flag.module';
|
import { FeatureFlagModule } from 'src/core/feature-flag/feature-flag.module';
|
||||||
import { OpenApiModule } from 'src/core/open-api/open-api.module';
|
import { OpenApiModule } from 'src/core/open-api/open-api.module';
|
||||||
import { TimelineMessagingModule } from 'src/core/messaging/timeline-messaging.module';
|
import { TimelineMessagingModule } from 'src/core/messaging/timeline-messaging.module';
|
||||||
|
import { BillingModule } from 'src/core/billing/billing.module';
|
||||||
|
|
||||||
import { AnalyticsModule } from './analytics/analytics.module';
|
import { AnalyticsModule } from './analytics/analytics.module';
|
||||||
import { FileModule } from './file/file.module';
|
import { FileModule } from './file/file.module';
|
||||||
@ -15,25 +16,26 @@ import { ClientConfigModule } from './client-config/client-config.module';
|
|||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
AuthModule,
|
|
||||||
WorkspaceModule,
|
|
||||||
UserModule,
|
|
||||||
RefreshTokenModule,
|
|
||||||
AnalyticsModule,
|
AnalyticsModule,
|
||||||
FileModule,
|
|
||||||
ClientConfigModule,
|
|
||||||
ApiRestModule,
|
ApiRestModule,
|
||||||
OpenApiModule,
|
AuthModule,
|
||||||
|
BillingModule,
|
||||||
|
ClientConfigModule,
|
||||||
FeatureFlagModule,
|
FeatureFlagModule,
|
||||||
|
FileModule,
|
||||||
|
OpenApiModule,
|
||||||
|
RefreshTokenModule,
|
||||||
TimelineMessagingModule,
|
TimelineMessagingModule,
|
||||||
|
UserModule,
|
||||||
|
WorkspaceModule,
|
||||||
],
|
],
|
||||||
exports: [
|
exports: [
|
||||||
AuthModule,
|
|
||||||
WorkspaceModule,
|
|
||||||
UserModule,
|
|
||||||
AnalyticsModule,
|
AnalyticsModule,
|
||||||
|
AuthModule,
|
||||||
FeatureFlagModule,
|
FeatureFlagModule,
|
||||||
TimelineMessagingModule,
|
TimelineMessagingModule,
|
||||||
|
UserModule,
|
||||||
|
WorkspaceModule,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class CoreModule {}
|
export class CoreModule {}
|
||||||
|
@ -18,6 +18,7 @@ export enum FeatureFlagKeys {
|
|||||||
IsCalendarEnabled = 'IS_CALENDAR_ENABLED',
|
IsCalendarEnabled = 'IS_CALENDAR_ENABLED',
|
||||||
IsMessagingEnabled = 'IS_MESSAGING_ENABLED',
|
IsMessagingEnabled = 'IS_MESSAGING_ENABLED',
|
||||||
IsNewRecordBoardEnabled = 'IS_NEW_RECORD_BOARD_ENABLED',
|
IsNewRecordBoardEnabled = 'IS_NEW_RECORD_BOARD_ENABLED',
|
||||||
|
IsSelfBillingEnabled = 'IS_SELF_BILLING_ENABLED',
|
||||||
IsWorkspaceCleanable = 'IS_WORKSPACE_CLEANABLE',
|
IsWorkspaceCleanable = 'IS_WORKSPACE_CLEANABLE',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,12 +6,14 @@ import {
|
|||||||
CreateDateColumn,
|
CreateDateColumn,
|
||||||
Entity,
|
Entity,
|
||||||
OneToMany,
|
OneToMany,
|
||||||
|
OneToOne,
|
||||||
PrimaryGeneratedColumn,
|
PrimaryGeneratedColumn,
|
||||||
UpdateDateColumn,
|
UpdateDateColumn,
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
|
|
||||||
import { User } from 'src/core/user/user.entity';
|
import { User } from 'src/core/user/user.entity';
|
||||||
import { FeatureFlagEntity } from 'src/core/feature-flag/feature-flag.entity';
|
import { FeatureFlagEntity } from 'src/core/feature-flag/feature-flag.entity';
|
||||||
|
import { BillingSubscription } from 'src/core/billing/entities/billing-subscription.entity';
|
||||||
|
|
||||||
@Entity({ name: 'workspace', schema: 'core' })
|
@Entity({ name: 'workspace', schema: 'core' })
|
||||||
@ObjectType('Workspace')
|
@ObjectType('Workspace')
|
||||||
@ -65,4 +67,10 @@ export class Workspace {
|
|||||||
|
|
||||||
@Field()
|
@Field()
|
||||||
activationStatus: 'active' | 'inactive';
|
activationStatus: 'active' | 'inactive';
|
||||||
|
|
||||||
|
@OneToOne(
|
||||||
|
() => BillingSubscription,
|
||||||
|
(billingSubscription) => billingSubscription.workspace,
|
||||||
|
)
|
||||||
|
billingSubscription: BillingSubscription;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||||
|
|
||||||
|
export class AddBillingCoreTables1708535112230 implements MigrationInterface {
|
||||||
|
name = 'AddBillingCoreTables1708535112230'
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`CREATE TABLE "core"."billingSubscriptionItem" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "deletedAt" TIMESTAMP, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "billingSubscriptionId" uuid NOT NULL, "stripeProductId" character varying NOT NULL, "stripePriceId" character varying NOT NULL, "quantity" integer NOT NULL, CONSTRAINT "PK_0287b2d9fca488edcbf748281fc" PRIMARY KEY ("id"))`);
|
||||||
|
await queryRunner.query(`CREATE TABLE "core"."billingSubscription" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "deletedAt" TIMESTAMP, "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, "stripeSubscriptionId" character varying NOT NULL, "status" character varying NOT NULL, CONSTRAINT "UQ_9120b7586c3471463480b58d20a" UNIQUE ("stripeCustomerId"), CONSTRAINT "UQ_1a858c28c7766d429cbd25f05e8" UNIQUE ("stripeSubscriptionId"), CONSTRAINT "REL_4abfb70314c18da69e1bee1954" UNIQUE ("workspaceId"), CONSTRAINT "PK_6e9c72c32d91640b8087cb53666" PRIMARY KEY ("id"))`);
|
||||||
|
await queryRunner.query(`ALTER TABLE "core"."billingSubscriptionItem" ADD CONSTRAINT "FK_a602e7c9da619b8290232f6eeab" FOREIGN KEY ("billingSubscriptionId") REFERENCES "core"."billingSubscription"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
|
||||||
|
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`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`ALTER TABLE "core"."billingSubscription" DROP CONSTRAINT "FK_4abfb70314c18da69e1bee1954d"`);
|
||||||
|
await queryRunner.query(`ALTER TABLE "core"."billingSubscriptionItem" DROP CONSTRAINT "FK_a602e7c9da619b8290232f6eeab"`);
|
||||||
|
await queryRunner.query(`DROP TABLE "core"."billingSubscription"`);
|
||||||
|
await queryRunner.query(`DROP TABLE "core"."billingSubscriptionItem"`);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -8,6 +8,8 @@ import { User } from 'src/core/user/user.entity';
|
|||||||
import { Workspace } from 'src/core/workspace/workspace.entity';
|
import { Workspace } from 'src/core/workspace/workspace.entity';
|
||||||
import { RefreshToken } from 'src/core/refresh-token/refresh-token.entity';
|
import { RefreshToken } from 'src/core/refresh-token/refresh-token.entity';
|
||||||
import { FeatureFlagEntity } from 'src/core/feature-flag/feature-flag.entity';
|
import { FeatureFlagEntity } from 'src/core/feature-flag/feature-flag.entity';
|
||||||
|
import { BillingSubscription } from 'src/core/billing/entities/billing-subscription.entity';
|
||||||
|
import { BillingSubscriptionItem } from 'src/core/billing/entities/billing-subscription-item.entity';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TypeORMService implements OnModuleInit, OnModuleDestroy {
|
export class TypeORMService implements OnModuleInit, OnModuleDestroy {
|
||||||
@ -21,7 +23,14 @@ export class TypeORMService implements OnModuleInit, OnModuleDestroy {
|
|||||||
type: 'postgres',
|
type: 'postgres',
|
||||||
logging: false,
|
logging: false,
|
||||||
schema: 'core',
|
schema: 'core',
|
||||||
entities: [User, Workspace, RefreshToken, FeatureFlagEntity],
|
entities: [
|
||||||
|
User,
|
||||||
|
Workspace,
|
||||||
|
RefreshToken,
|
||||||
|
FeatureFlagEntity,
|
||||||
|
BillingSubscription,
|
||||||
|
BillingSubscriptionItem,
|
||||||
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
20
yarn.lock
20
yarn.lock
@ -15797,6 +15797,15 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"@types/node@npm:>=8.1.0":
|
||||||
|
version: 20.11.19
|
||||||
|
resolution: "@types/node@npm:20.11.19"
|
||||||
|
dependencies:
|
||||||
|
undici-types: "npm:~5.26.4"
|
||||||
|
checksum: f451ef0a1d78f29c57bad7b77e49ebec945f2a6d0d7a89851d7e185ee9fe7ad94d651c0dfbcb7858c9fa791310c8b40a881e2260f56bd3c1b7e7ae92723373ae
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"@types/node@npm:^10.1.0":
|
"@types/node@npm:^10.1.0":
|
||||||
version: 10.17.60
|
version: 10.17.60
|
||||||
resolution: "@types/node@npm:10.17.60"
|
resolution: "@types/node@npm:10.17.60"
|
||||||
@ -42787,6 +42796,16 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"stripe@npm:^14.17.0":
|
||||||
|
version: 14.17.0
|
||||||
|
resolution: "stripe@npm:14.17.0"
|
||||||
|
dependencies:
|
||||||
|
"@types/node": "npm:>=8.1.0"
|
||||||
|
qs: "npm:^6.11.0"
|
||||||
|
checksum: ec783c4b125ad6c2f8181d3aa07b7d6a7126a588310ace8d9189269014ce84ba3e98d43464bc557bfcefcc05d7c5aebc551dd4e19c32316165c76944898a719a
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"strnum@npm:^1.0.5":
|
"strnum@npm:^1.0.5":
|
||||||
version: 1.0.5
|
version: 1.0.5
|
||||||
resolution: "strnum@npm:1.0.5"
|
resolution: "strnum@npm:1.0.5"
|
||||||
@ -44394,6 +44413,7 @@ __metadata:
|
|||||||
storybook: "npm:^7.6.3"
|
storybook: "npm:^7.6.3"
|
||||||
storybook-addon-cookie: "npm:^3.2.0"
|
storybook-addon-cookie: "npm:^3.2.0"
|
||||||
storybook-addon-pseudo-states: "npm:^2.1.2"
|
storybook-addon-pseudo-states: "npm:^2.1.2"
|
||||||
|
stripe: "npm:^14.17.0"
|
||||||
supertest: "npm:^6.1.3"
|
supertest: "npm:^6.1.3"
|
||||||
ts-jest: "npm:^29.1.1"
|
ts-jest: "npm:^29.1.1"
|
||||||
ts-key-enum: "npm:^2.0.12"
|
ts-key-enum: "npm:^2.0.12"
|
||||||
|
Loading…
Reference in New Issue
Block a user