From 236fe585849fa78ef0758444c2fb63843933bef2 Mon Sep 17 00:00:00 2001 From: Evgenij Shangin Date: Fri, 15 Nov 2024 17:15:24 +0300 Subject: [PATCH] Delete tenant migration (#208) --- api/db.ts | 10 -- src/db/models/new/migration-tenant/index.ts | 25 --- src/db/presentations/index.ts | 2 - .../joined-entry-migration-tenant/index.ts | 40 ----- .../joined-migration-tenant/index.ts | 144 ------------------ 5 files changed, 221 deletions(-) delete mode 100644 src/db/models/new/migration-tenant/index.ts delete mode 100644 src/db/presentations/joined-entry-migration-tenant/index.ts delete mode 100644 src/db/presentations/joined-migration-tenant/index.ts diff --git a/api/db.ts b/api/db.ts index 51d081e1..4e455524 100644 --- a/api/db.ts +++ b/api/db.ts @@ -16,7 +16,6 @@ export { } from '../src/db/models/new/revision'; export {Tenant, TenantColumn} from '../src/db/models/new/tenant'; -export {MigrationTenant, MigrationTenantColumn} from '../src/db/models/new/migration-tenant'; export {WorkbookModel, WorkbookModelColumn} from '../src/db/models/new/workbook'; export {CollectionModel, CollectionModelColumn} from '../src/db/models/new/collection'; @@ -55,15 +54,6 @@ export { JoinedEntryRevisionFavorite, JoinedEntryRevisionFavoriteColumns, } from '../src/db/presentations/joined-entry-revision-favorite'; -export { - JoinMigrationTenantArgs, - JoinedMigrationTenant, - JoinedMigrationTenantColumn, - joinMigrationTenant, - LeftJoinedMigrationTenantColumns, - SelectedTenantColumns, -} from '../src/db/presentations/joined-migration-tenant'; -export {JoinedEntryMigrationTenant} from '../src/db/presentations/joined-entry-migration-tenant'; export { JoinedEmbedEmbeddingSecret, JoinedEmbedEmbeddingSecretColumns, diff --git a/src/db/models/new/migration-tenant/index.ts b/src/db/models/new/migration-tenant/index.ts deleted file mode 100644 index 660c5984..00000000 --- a/src/db/models/new/migration-tenant/index.ts +++ /dev/null @@ -1,25 +0,0 @@ -import {Model} from '../../..'; - -export const MigrationTenantColumn = { - FromId: 'fromId', - ToId: 'toId', - Migrating: 'migrating', - MigrationMeta: 'migrationMeta', - CreatedAt: 'createdAt', -} as const; - -export class MigrationTenant extends Model { - static get tableName() { - return 'migrationsTenants'; - } - - static get idColumn() { - return [MigrationTenantColumn.FromId, MigrationTenantColumn.ToId]; - } - - [MigrationTenantColumn.FromId]!: string; - [MigrationTenantColumn.ToId]!: string; - [MigrationTenantColumn.Migrating]!: boolean; - [MigrationTenantColumn.MigrationMeta]!: Record; - [MigrationTenantColumn.CreatedAt]!: string; -} diff --git a/src/db/presentations/index.ts b/src/db/presentations/index.ts index d5c1de4a..23416e0b 100644 --- a/src/db/presentations/index.ts +++ b/src/db/presentations/index.ts @@ -1,6 +1,4 @@ export * from './joined-entry-revision'; export * from './joined-entry-revision-favorite'; -export * from './joined-migration-tenant'; -export * from './joined-entry-migration-tenant'; export * from './joined-embed-embedding-secret'; export * from './joined-entry-favorite'; diff --git a/src/db/presentations/joined-entry-migration-tenant/index.ts b/src/db/presentations/joined-entry-migration-tenant/index.ts deleted file mode 100644 index 3794805a..00000000 --- a/src/db/presentations/joined-entry-migration-tenant/index.ts +++ /dev/null @@ -1,40 +0,0 @@ -import type {Knex} from 'knex'; -import {TransactionOrKnex} from 'objection'; -import {Entry, EntryColumn} from '../../models/new/entry'; -import {Tenant, TenantColumn} from '../../models/new/tenant'; -import {MigrationTenant} from '../../models/new/migration-tenant'; -import { - LeftJoinedMigrationTenantColumns, - selectedJoinedMigrationTenantColumns, - JoinMigrationTenantArgs, - joinMigrationTenant, -} from '../joined-migration-tenant'; - -const joinEntryMigrationTenant = (builder: Knex.JoinClause) => { - builder.on( - `${Entry.tableName}.${EntryColumn.TenantId}`, - `${Tenant.tableName}.${TenantColumn.TenantId}`, - ); -}; - -export class JoinedEntryMigrationTenant extends Entry { - static findOneTenant({ - where, - joinMigrationTenantArgs, - trx, - }: { - where: Record | ((builder: Knex.QueryBuilder) => void); - joinMigrationTenantArgs: JoinMigrationTenantArgs; - trx: TransactionOrKnex; - }) { - return JoinedEntryMigrationTenant.query(trx) - .select(selectedJoinedMigrationTenantColumns) - .join(Tenant.tableName, joinEntryMigrationTenant) - .leftJoin(MigrationTenant.tableName, joinMigrationTenant(joinMigrationTenantArgs)) - .where(where) - .first() - .timeout(JoinedEntryMigrationTenant.DEFAULT_QUERY_TIMEOUT) as unknown as Promise< - Optional - >; - } -} diff --git a/src/db/presentations/joined-migration-tenant/index.ts b/src/db/presentations/joined-migration-tenant/index.ts deleted file mode 100644 index cd1f3b4f..00000000 --- a/src/db/presentations/joined-migration-tenant/index.ts +++ /dev/null @@ -1,144 +0,0 @@ -import type {Knex} from 'knex'; -import {TransactionOrKnex} from 'objection'; -import {Tenant, TenantColumn} from '../../models/new/tenant'; -import {MigrationTenant, MigrationTenantColumn} from '../../models/new/migration-tenant'; - -const selectedTenantColumns = [ - TenantColumn.TenantId, - TenantColumn.Meta, - TenantColumn.CreatedAt, - TenantColumn.Enabled, - TenantColumn.Deleting, - TenantColumn.LastInitAt, - TenantColumn.RetriesCount, - TenantColumn.CollectionsEnabled, - TenantColumn.FoldersEnabled, - TenantColumn.BillingInstanceServiceId, - TenantColumn.BillingPausedByUser, - TenantColumn.BillingInstanceServiceIsActive, - TenantColumn.BillingStartedAt, - TenantColumn.BillingEndedAt, - TenantColumn.Branding, - TenantColumn.Settings, -] as const; - -const selectedMigrationTenantColumns = [ - MigrationTenantColumn.FromId, - MigrationTenantColumn.ToId, - MigrationTenantColumn.Migrating, - MigrationTenantColumn.MigrationMeta, -] as const; - -export const JoinedMigrationTenantColumn = { - TenantId: TenantColumn.TenantId, - Meta: TenantColumn.Meta, - CreatedAt: TenantColumn.CreatedAt, - Enabled: TenantColumn.Enabled, - Deleting: TenantColumn.Deleting, - LastInitAt: TenantColumn.LastInitAt, - RetriesCount: TenantColumn.RetriesCount, - CollectionsEnabled: TenantColumn.CollectionsEnabled, - FoldersEnabled: TenantColumn.FoldersEnabled, - BillingInstanceServiceId: TenantColumn.BillingInstanceServiceId, - BillingInstanceServiceIsActive: TenantColumn.BillingInstanceServiceIsActive, - BillingPausedByUser: TenantColumn.BillingPausedByUser, - BillingStartedAt: TenantColumn.BillingStartedAt, - BillingEndedAt: TenantColumn.BillingEndedAt, - FromId: MigrationTenantColumn.FromId, - ToId: MigrationTenantColumn.ToId, - Migrating: MigrationTenantColumn.Migrating, - MigrationMeta: MigrationTenantColumn.MigrationMeta, - Branding: TenantColumn.Branding, - Settings: TenantColumn.Settings, -} as const; - -export const selectedJoinedMigrationTenantColumns = [ - ...selectedTenantColumns.map((col) => `${Tenant.tableName}.${col}`), - ...selectedMigrationTenantColumns.map((col) => `${MigrationTenant.tableName}.${col}`), -]; - -export type JoinMigrationTenantArgs = { - joinColumnId: - | typeof JoinedMigrationTenantColumn.FromId - | typeof JoinedMigrationTenantColumn.ToId; -}; - -export const joinMigrationTenant = - ({joinColumnId}: JoinMigrationTenantArgs) => - (builder: Knex.JoinClause) => { - builder.on( - `${Tenant.tableName}.${TenantColumn.TenantId}`, - `${MigrationTenant.tableName}.${joinColumnId}`, - ); - }; - -export type SelectedTenantColumns = Pick>; - -type SelectedMigrationTenantColumns = Pick< - MigrationTenant, - ArrayElement ->; - -export type LeftJoinedMigrationTenantColumns = SelectedTenantColumns & - NullableValues; - -type FullJoinedMigrationTenantColumns = NullableValues & - NullableValues; - -export class JoinedMigrationTenant extends Tenant { - static findOneLeftJoined({ - where, - joinMigrationTenantArgs, - trx, - }: { - where: Record | ((builder: Knex.QueryBuilder) => void); - joinMigrationTenantArgs: JoinMigrationTenantArgs; - trx: TransactionOrKnex; - }) { - return JoinedMigrationTenant.query(trx) - .select(selectedJoinedMigrationTenantColumns) - .leftJoin(MigrationTenant.tableName, joinMigrationTenant(joinMigrationTenantArgs)) - .where(where) - .first() - .timeout(JoinedMigrationTenant.DEFAULT_QUERY_TIMEOUT) as unknown as Promise< - Optional - >; - } - - static findLeftJoined({ - where, - joinMigrationTenantArgs, - trx, - }: { - where: Record | ((builder: Knex.QueryBuilder) => void); - joinMigrationTenantArgs: JoinMigrationTenantArgs; - trx: TransactionOrKnex; - }) { - return JoinedMigrationTenant.query(trx) - .select(selectedJoinedMigrationTenantColumns) - .leftJoin(MigrationTenant.tableName, joinMigrationTenant(joinMigrationTenantArgs)) - .where(where) - .timeout(JoinedMigrationTenant.DEFAULT_QUERY_TIMEOUT) as unknown as Promise< - LeftJoinedMigrationTenantColumns[] - >; - } - - static findOneFullJoined({ - where, - joinMigrationTenantArgs, - trx, - }: { - where: Record | ((builder: Knex.QueryBuilder) => void); - joinMigrationTenantArgs: JoinMigrationTenantArgs; - trx: TransactionOrKnex; - }) { - return JoinedMigrationTenant.query(trx) - .select(selectedJoinedMigrationTenantColumns) - .fullOuterJoin(MigrationTenant.tableName, joinMigrationTenant(joinMigrationTenantArgs)) - .where(where) - .first() - .timeout(JoinedMigrationTenant.DEFAULT_QUERY_TIMEOUT) as unknown as Promise< - Optional - >; - } -}