-
Notifications
You must be signed in to change notification settings - Fork 562
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6923 from ever-co/feat/6909-active-archived-softD…
…elete-records Feat/6909 active archived soft delete records
- Loading branch information
Showing
28 changed files
with
5,547 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,35 @@ | ||
import { ITenant } from './tenant.model'; | ||
import { IOrganization } from './organization.model'; | ||
|
||
// Common properties for entities with relations | ||
export interface IBaseRelationsEntityModel { | ||
readonly relations?: string[]; | ||
relations?: string[]; // List of related entities | ||
} | ||
|
||
// Common properties for soft delete entities | ||
export interface IBaseSoftDeleteEntityModel { | ||
deletedAt?: Date; | ||
deletedAt?: Date; // Indicates if the record is soft deleted | ||
} | ||
|
||
export interface IBaseEntityModel extends IBaseSoftDeleteEntityModel { | ||
id?: string; | ||
// Common properties for entities | ||
export interface IBaseEntityModel extends IBaseSoftDeleteEntityModel { | ||
id?: string; // Unique identifier | ||
|
||
readonly createdAt?: Date; | ||
readonly updatedAt?: Date; | ||
readonly createdAt?: Date; // Date when the record was created | ||
readonly updatedAt?: Date; // Date when the record was last updated | ||
|
||
isActive?: boolean; // Indicates if the record is currently active | ||
isArchived?: boolean; // Indicates if the record is archived | ||
} | ||
|
||
// Common properties for entities associated with a tenant | ||
export interface IBasePerTenantEntityModel extends IBaseEntityModel { | ||
tenantId?: string; | ||
tenant?: ITenant; | ||
tenantId?: ITenant['id']; // Identifier of the associated tenant | ||
tenant?: ITenant; // Reference to the associated tenant | ||
} | ||
|
||
export interface IBasePerTenantAndOrganizationEntityModel | ||
extends IBasePerTenantEntityModel { | ||
organizationId?: string; | ||
organization?: IOrganization; | ||
// Common properties for entities associated with both tenant and organization | ||
export interface IBasePerTenantAndOrganizationEntityModel extends IBasePerTenantEntityModel { | ||
organizationId?: IOrganization['id']; // Identifier of the associated organization | ||
organization?: IOrganization; // Reference to the associated organization | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 24 additions & 20 deletions
44
packages/core/src/database/migrations/1643809486960-MigrateEmailTemplatesData.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,32 @@ | ||
import { MigrationInterface, QueryRunner, SelectQueryBuilder } from "typeorm"; | ||
import { createDefaultEmailTemplates } from "./../../email-template/email-template.seed"; | ||
import { EmailTemplate } from "./../../core/entities/internal"; | ||
import { MigrationInterface, QueryRunner } from "typeorm"; | ||
import * as chalk from 'chalk'; | ||
import { EmailTemplateEnum } from "@gauzy/contracts"; | ||
import { EmailTemplateUtils } from "email-template/utils"; | ||
|
||
export class MigrateEmailTemplatesData1643809486960 implements MigrationInterface { | ||
|
||
name = 'MigrateEmailTemplatesData1643809486960'; | ||
|
||
/** | ||
* Up Migration | ||
* | ||
* @param queryRunner | ||
*/ | ||
public async up(queryRunner: QueryRunner): Promise<any> { | ||
/** | ||
* Removed default gauzy email templates, again seed them with new one | ||
*/ | ||
const query = queryRunner.connection.createQueryBuilder(EmailTemplate, 'email_template'); | ||
query.where((qb: SelectQueryBuilder<EmailTemplate>) => { | ||
qb.andWhere(`"${qb.alias}"."organizationId" IS NULL`); | ||
qb.andWhere(`"${qb.alias}"."tenantId" IS NULL`); | ||
}); | ||
const emailTemplates = await query.getMany(); | ||
await queryRunner.connection.getRepository(EmailTemplate).remove(emailTemplates); | ||
|
||
/** | ||
* Reseed all new default email templates | ||
*/ | ||
await createDefaultEmailTemplates(queryRunner.connection); | ||
console.log(chalk.yellow(`MigrateEmailTemplatesData1643809486960 start running!`)); | ||
const templates = Object.values(EmailTemplateEnum); | ||
await Promise.all( | ||
templates.map( | ||
async (template: EmailTemplateEnum) => { | ||
try { | ||
await EmailTemplateUtils.migrateEmailTemplates(queryRunner, template); | ||
} catch (error) { | ||
console.log(`Error while migrating missing email templates for ${template}`, error); | ||
} | ||
} | ||
) | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<any> {} | ||
} | ||
public async down(queryRunner: QueryRunner): Promise<any> { } | ||
} |
Oops, something went wrong.