-
-
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.
🔨 (grapher) let charts inherit defaults
- Loading branch information
1 parent
be4487e
commit 77a6539
Showing
25 changed files
with
856 additions
and
91 deletions.
There are no files selected for viewing
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
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
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
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
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
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,59 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm" | ||
import { diffGrapherConfigs, mergeGrapherConfigs } from "@ourworldindata/utils" | ||
import { defaultGrapherConfig } from "@ourworldindata/grapher" | ||
|
||
export class MakeChartsInheritDefaults1720600092980 | ||
implements MigrationInterface | ||
{ | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
const charts = (await queryRunner.query( | ||
`-- sql | ||
SELECT id, patch as config FROM chart_configs | ||
` | ||
)) as { id: string; config: string }[] | ||
|
||
for (const chart of charts) { | ||
const originalConfig = JSON.parse(chart.config) | ||
|
||
// if the schema version is missing, assume it's the latest | ||
if (!originalConfig["$schema"]) { | ||
originalConfig["$schema"] = defaultGrapherConfig["$schema"] | ||
} | ||
|
||
const patchConfig = diffGrapherConfigs( | ||
originalConfig, | ||
defaultGrapherConfig | ||
) | ||
const fullConfig = mergeGrapherConfigs( | ||
defaultGrapherConfig, | ||
patchConfig | ||
) | ||
|
||
await queryRunner.query( | ||
`-- sql | ||
UPDATE chart_configs | ||
SET | ||
patch = ?, | ||
full = ? | ||
WHERE id = ? | ||
`, | ||
[ | ||
JSON.stringify(patchConfig), | ||
JSON.stringify(fullConfig), | ||
chart.id, | ||
] | ||
) | ||
} | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
// we can't recover the original configs, | ||
// but the patched one is the next best thing | ||
await queryRunner.query( | ||
`-- sql | ||
UPDATE chart_configs | ||
SET full = patch | ||
` | ||
) | ||
} | ||
} |
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
Oops, something went wrong.