Skip to content

Commit

Permalink
🔨 migrate slope chart configs
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Dec 11, 2024
1 parent 4e3bf99 commit a587120
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 a587120

Please sign in to comment.