mirror of
https://github.com/ToolJet/ToolJet
synced 2026-04-22 05:57:20 +00:00
* working on app name unique migrationworking on app name unique migration * Added checks and conditions * change: remove staring and ending spaces * fix: error management * fix: regex * working on app name generation * app name:fixing bugs * app name: fixing and refactoring code * app name: fixed test cases * updated app name constraints and default name * fix: apps.e2e tests case * fix: added app name to the prompt * added app input tooltip * removed unwanted code * added tooltip close code * fixed auto generated name issue * merging develop * code refactoring --------- Co-authored-by: gsmithun4 <gsmithun4@gmail.com>
38 lines
1.6 KiB
TypeScript
38 lines
1.6 KiB
TypeScript
import { App } from 'src/entities/app.entity';
|
|
import { Organization } from 'src/entities/organization.entity';
|
|
import { DataBaseConstraints } from 'src/helpers/db_constraints.constants';
|
|
import { MigrationInterface, QueryRunner, TableUnique, EntityManager } from 'typeorm';
|
|
|
|
export class AddUniqueConstraintToAppName1684145489093 implements MigrationInterface {
|
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
const entityManager = queryRunner.manager;
|
|
await this.migrateAppNames(entityManager);
|
|
await queryRunner.createUniqueConstraint(
|
|
'apps',
|
|
new TableUnique({
|
|
name: DataBaseConstraints.APP_NAME_UNIQUE,
|
|
columnNames: ['name', 'organization_id'],
|
|
})
|
|
);
|
|
}
|
|
|
|
public async migrateAppNames(entityManager: EntityManager) {
|
|
const workspaces = await entityManager.find(Organization);
|
|
for (const workspace of workspaces) {
|
|
const { id: organizationId } = workspace;
|
|
const apps = await entityManager.query(
|
|
'select sub_query.name from (select count(*) as name_count, name from apps where organization_id=$1 group by name) sub_query where name_count > 1 ',
|
|
[organizationId]
|
|
);
|
|
for (const app of apps) {
|
|
const { name } = app;
|
|
const sameApps = await entityManager.find(App, { where: { name, organizationId } });
|
|
for (const appToChange of sameApps.slice(1)) {
|
|
await entityManager.update(App, { id: appToChange.id }, { name: `${appToChange.name} ${Date.now()}` });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public async down(queryRunner: QueryRunner): Promise<void> {}
|
|
}
|