-
-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ add indicator shortName to catalogPath in variables table (#2845)
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
db/migration/1698087308654-AddIndicatorShortNameToCatalogPath.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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm" | ||
|
||
export class AddIndicatorShortNameToCatalogPath1698087308654 | ||
implements MigrationInterface | ||
{ | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`UPDATE variables | ||
SET catalogPath = CONCAT(catalogPath, '#', shortName) | ||
WHERE catalogPath not like '%#%'; | ||
` | ||
) | ||
// change it from text to varchar for more efficient indexing, make it as long as possible | ||
// to fit into index | ||
await queryRunner.query( | ||
`ALTER TABLE variables | ||
MODIFY catalogPath VARCHAR(767) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_cs; | ||
` | ||
) | ||
await queryRunner.query( | ||
`ALTER TABLE variables | ||
ADD UNIQUE INDEX idx_catalogPath (catalogPath); | ||
` | ||
) | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
ALTER TABLE variables | ||
DROP INDEX idx_catalogPath | ||
`) | ||
await queryRunner.query( | ||
`UPDATE variables | ||
SET catalogPath = SUBSTRING_INDEX(catalogPath, '#', 1) | ||
WHERE catalogPath LIKE '%#%'; | ||
` | ||
) | ||
await queryRunner.query( | ||
`ALTER TABLE variables | ||
MODIFY catalogPath text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_as_cs; | ||
` | ||
) | ||
} | ||
} |