fix: Add missing indices on sqlite (#6673)
* fix: enforce tag name uniqueness on sqlite * rename migration and add other missing indices * add tags tests
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import type { IrreversibleMigration, MigrationContext } from '@db/types';
|
||||
|
||||
export class FixMissingIndicesFromStringIdMigration1690000000020 implements IrreversibleMigration {
|
||||
async up({ queryRunner, tablePrefix }: MigrationContext): Promise<void> {
|
||||
const toMerge = (await queryRunner.query(
|
||||
`SELECT id, name, COUNT(*) c FROM ${tablePrefix}tag_entity GROUP BY name HAVING c > 1`,
|
||||
)) as Array<{ id: string; name: string }>;
|
||||
|
||||
for (const m of toMerge) {
|
||||
const tags = (await queryRunner.query(
|
||||
`SELECT id FROM ${tablePrefix}tag_entity WHERE name = ?`,
|
||||
[m.name],
|
||||
)) as Array<{ id: string }>;
|
||||
for (const t of tags) {
|
||||
if (t.id === m.id) {
|
||||
continue;
|
||||
}
|
||||
await queryRunner.query(
|
||||
`UPDATE ${tablePrefix}workflows_tags SET tagId = ? WHERE tagId = ?`,
|
||||
[m.id, t.id],
|
||||
);
|
||||
await queryRunner.query(`DELETE FROM ${tablePrefix}tag_entity WHERE id = ?`, [t.id]);
|
||||
}
|
||||
}
|
||||
|
||||
await queryRunner.query(
|
||||
`CREATE UNIQUE INDEX "IDX_${tablePrefix}8f949d7a3a984759044054e89b" ON "${tablePrefix}tag_entity" ("name") `,
|
||||
);
|
||||
|
||||
await queryRunner.query(
|
||||
`CREATE INDEX 'IDX_${tablePrefix}b94b45ce2c73ce46c54f20b5f9' ON '${tablePrefix}execution_entity' ('waitTill', 'id');`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE INDEX 'IDX_${tablePrefix}81fc04c8a17de15835713505e4' ON '${tablePrefix}execution_entity' ('workflowId', 'id');`,
|
||||
);
|
||||
await queryRunner.query(
|
||||
`CREATE INDEX 'IDX_${tablePrefix}8b6f3f9ae234f137d707b98f3bf43584' ON '${tablePrefix}execution_entity' ('status', 'workflowId');`,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,7 @@ import { AddUserActivatedProperty1681134145996 } from './1681134145996-AddUserAc
|
||||
import { MigrateIntegerKeysToString1690000000002 } from './1690000000002-MigrateIntegerKeysToString';
|
||||
import { SeparateExecutionData1690000000010 } from './1690000000010-SeparateExecutionData';
|
||||
import { RemoveSkipOwnerSetup1681134145997 } from './1681134145997-RemoveSkipOwnerSetup';
|
||||
import { FixMissingIndicesFromStringIdMigration1690000000020 } from './1690000000020-FixMissingIndicesFromStringIdMigration';
|
||||
|
||||
const sqliteMigrations: Migration[] = [
|
||||
InitialMigration1588102412422,
|
||||
@@ -79,6 +80,7 @@ const sqliteMigrations: Migration[] = [
|
||||
MigrateIntegerKeysToString1690000000002,
|
||||
SeparateExecutionData1690000000010,
|
||||
RemoveSkipOwnerSetup1681134145997,
|
||||
FixMissingIndicesFromStringIdMigration1690000000020,
|
||||
];
|
||||
|
||||
export { sqliteMigrations };
|
||||
|
||||
Reference in New Issue
Block a user