temporary code (#12757)
In order to put back relations on track, we need to allow the preexisting indexes to be created in indexmetadata, but also to avoid failure when the migration runner will try to re-apply a pre-existing index
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
import { Injectable, Logger } from '@nestjs/common';
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
|
|
||||||
import { isDefined } from 'twenty-shared/utils';
|
import { isDefined } from 'twenty-shared/utils';
|
||||||
import { QueryRunner, Table, TableColumn, TableIndex } from 'typeorm';
|
import { QueryRunner, Table, TableColumn } from 'typeorm';
|
||||||
|
|
||||||
import { IndexType } from 'src/engine/metadata-modules/index-metadata/index-metadata.entity';
|
import { IndexType } from 'src/engine/metadata-modules/index-metadata/index-metadata.entity';
|
||||||
import {
|
import {
|
||||||
@ -208,18 +208,16 @@ export class WorkspaceMigrationRunnerService {
|
|||||||
const quotedColumns = index.columns.map((column) => `"${column}"`);
|
const quotedColumns = index.columns.map((column) => `"${column}"`);
|
||||||
|
|
||||||
await queryRunner.query(`
|
await queryRunner.query(`
|
||||||
CREATE INDEX "${index.name}" ON "${schemaName}"."${tableName}" USING ${index.type} (${quotedColumns.join(', ')})
|
CREATE INDEX IF NOT EXISTS "${index.name}" ON "${schemaName}"."${tableName}" USING ${index.type} (${quotedColumns.join(', ')})
|
||||||
`);
|
`);
|
||||||
} else {
|
} else {
|
||||||
await queryRunner.createIndex(
|
const quotedColumns = index.columns.map((column) => `"${column}"`);
|
||||||
`${schemaName}.${tableName}`,
|
const isUnique = index.isUnique ? 'UNIQUE' : '';
|
||||||
new TableIndex({
|
const whereClause = index.where ? `WHERE ${index.where}` : '';
|
||||||
name: index.name,
|
|
||||||
columnNames: index.columns,
|
await queryRunner.query(`
|
||||||
isUnique: index.isUnique,
|
CREATE ${isUnique} INDEX IF NOT EXISTS "${index.name}" ON "${schemaName}"."${tableName}" (${quotedColumns.join(', ')}) ${whereClause}
|
||||||
where: index.where ?? undefined,
|
`);
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Ignore error if index already exists
|
// Ignore error if index already exists
|
||||||
|
|||||||
Reference in New Issue
Block a user