Skip to content

Commit

Permalink
🔨 migrate slope chart configs (#4275)
Browse files Browse the repository at this point in the history
Slope chart migrations that go hand in hand with the new designs.

Will be shipped earlier so that configs in R2 are already updated once the new code is deployed.
  • Loading branch information
sophiamersmann authored Dec 11, 2024
1 parent 53f83dc commit 8124296
Show file tree
Hide file tree
Showing 4 changed files with 655 additions and 10 deletions.
32 changes: 32 additions & 0 deletions db/migration/1733850063207-RemoveColorDimensionFromSlopeCharts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { MigrationInterface, QueryRunner } from "typeorm"

export class RemoveColorDimensionFromSlopeCharts1733850063207
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
// remove color dimension for all slope charts
// the y-dimension always comes first and the color dimension second,
// so it's safe to keep the first dimension only
await queryRunner.query(`
-- sql
UPDATE chart_configs
SET
patch = JSON_REPLACE(patch, '$.dimensions', JSON_ARRAY(patch -> '$.dimensions[0]')),
full = JSON_REPLACE(full, '$.dimensions', JSON_ARRAY(full -> '$.dimensions[0]'))
WHERE
chartType = 'SlopeChart'
`)

// remove the color dimension for slope charts from the chart_dimensions table
await queryRunner.query(`
-- sql
DELETE cd FROM chart_dimensions cd
JOIN charts c ON c.id = cd.chartId
JOIN chart_configs cc ON c.configId = cc.id
WHERE cc.chartType = 'SlopeChart' AND cd.property = 'color'
`)
}

// eslint-disable-next-line @typescript-eslint/no-empty-function
public async down(): Promise<void> {}
}
Loading

0 comments on commit 8124296

Please sign in to comment.