-
-
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.
migrate(entities): drop
$.data.availableEntities
and $.data
from …
…chart configs
- Loading branch information
1 parent
1776721
commit 240aa18
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
db/migration/1711580214803-RemoveAvailableEntitiesFromChartConfigs.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,40 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm" | ||
|
||
export class RemoveAvailableEntitiesFromChartConfigs1711580214803 | ||
implements MigrationInterface | ||
{ | ||
// Removes `$.data.availableEntities` from chart configs | ||
// In doing that, we can also remove the whole `$.data` object, because it is not used anymore | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
const configColumns = [ | ||
{ table: "charts", column: "config" }, | ||
{ table: "chart_revisions", column: "config" }, | ||
{ table: "suggested_chart_revisions", column: "suggestedConfig" }, | ||
{ table: "variables", column: "grapherConfigAdmin" }, | ||
{ table: "variables", column: "grapherConfigETL" }, | ||
] | ||
|
||
for (const { table, column } of configColumns) { | ||
await queryRunner.query( | ||
`-- sql | ||
UPDATE ?? | ||
SET ?? = JSON_REMOVE(??, "$.data") | ||
WHERE JSON_CONTAINS_PATH(??, "one", "$.data") | ||
`, | ||
[table, column, column, column] | ||
) | ||
|
||
// Update schema version to 004 | ||
await queryRunner.query( | ||
`--sql | ||
UPDATE ?? | ||
SET ?? = JSON_SET(??, "$.$schema", "https://files.ourworldindata.org/schemas/grapher-schema.004.json")`, | ||
[table, column, column] | ||
) | ||
} | ||
} | ||
|
||
public async down(): Promise<void> { | ||
return | ||
} | ||
} |