From ba7b72b39a3322007bea4bf3bbd0bfc4ce3d05a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordi=20Guti=C3=A9rrez=20Hermoso?= Date: Mon, 5 Aug 2024 12:41:25 -0400 Subject: [PATCH] Activations: add an enabled_at column For #1140, I considered trying to use the existing fields in a better way, but because we already use the activations table to store preferences, we need to keep all of the existing data and its usage as-is. The enterprise code will use this new column to decide how long the trial period should be. --- app/gen-server/entity/Activation.ts | 9 +++++++++ .../1722529827161-Activation-Enabled.ts | 18 ++++++++++++++++++ test/gen-server/migrations.ts | 4 +++- 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 app/gen-server/migration/1722529827161-Activation-Enabled.ts diff --git a/app/gen-server/entity/Activation.ts b/app/gen-server/entity/Activation.ts index ca84c3f7..6507f99e 100644 --- a/app/gen-server/entity/Activation.ts +++ b/app/gen-server/entity/Activation.ts @@ -22,6 +22,15 @@ export class Activation extends BaseEntity { @Column({name: 'updated_at', default: () => "CURRENT_TIMESTAMP"}) public updatedAt: Date; + // When the enterprise activation was first enabled, so we know when + // to start counting the trial date. + // + // Activations are created at Grist installation to track other + // things such as prefs, but the user might not enable Enterprise + // until later. + @Column({name: 'enabled_at', type: nativeValues.dateTimeType, nullable: true}) + public enabledAt: Date|null; + public checkProperties(props: any): props is Partial { for (const key of Object.keys(props)) { if (!installPropertyKeys.includes(key)) { diff --git a/app/gen-server/migration/1722529827161-Activation-Enabled.ts b/app/gen-server/migration/1722529827161-Activation-Enabled.ts new file mode 100644 index 00000000..611cf61a --- /dev/null +++ b/app/gen-server/migration/1722529827161-Activation-Enabled.ts @@ -0,0 +1,18 @@ +import * as sqlUtils from "app/gen-server/sqlUtils"; +import { MigrationInterface, QueryRunner, TableColumn } from "typeorm"; + +export class ActivationEnabled1722529827161 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + const dbType = queryRunner.connection.driver.options.type; + const datetime = sqlUtils.datetime(dbType); + await queryRunner.addColumn('activations', new TableColumn({ + name: 'enabled_at', + type: datetime, + isNullable: true, + })); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.dropColumn('activations', 'enabled_at'); + } +} diff --git a/test/gen-server/migrations.ts b/test/gen-server/migrations.ts index f3cc32df..bc8dd1b1 100644 --- a/test/gen-server/migrations.ts +++ b/test/gen-server/migrations.ts @@ -44,6 +44,8 @@ import {Shares1701557445716 as Shares} from 'app/gen-server/migration/1701557445 import {Billing1711557445716 as BillingFeatures} from 'app/gen-server/migration/1711557445716-Billing'; import {UserLastConnection1713186031023 as UserLastConnection} from 'app/gen-server/migration/1713186031023-UserLastConnection'; +import {ActivationEnabled1722529827161 + as ActivationEnabled} from 'app/gen-server/migration/1722529827161-Activation-Enabled'; const home: HomeDBManager = new HomeDBManager(); @@ -53,7 +55,7 @@ const migrations = [Initial, Login, PinDocs, UserPicture, DisplayEmail, DisplayE ExternalBilling, DocOptions, Secret, UserOptions, GracePeriodStart, DocumentUsage, Activations, UserConnectId, UserUUID, UserUniqueRefUUID, Forks, ForkIndexes, ActivationPrefs, AssistantLimit, Shares, BillingFeatures, - UserLastConnection]; + UserLastConnection, ActivationEnabled]; // Assert that the "members" acl rule and group exist (or not). function assertMembersGroup(org: Organization, exists: boolean) {