Skip to content

Commit

Permalink
Merge pull request #3419 from owid/remove-available-entities-config
Browse files Browse the repository at this point in the history
chore: remove `$.data.availableEntities` from configs and schema
  • Loading branch information
marcelgerber authored Apr 8, 2024
2 parents 60a6f8e + c49358e commit 3531a62
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 24 deletions.
5 changes: 0 additions & 5 deletions adminSiteClient/ChartEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,6 @@ export class ChartEditor {
if (!currentGrapherObject.slug)
currentGrapherObject.slug = grapher.displaySlug

// We need to save availableEntities for Algolia search. Todo: remove.
const availableEntities = grapher.table.availableEntityNames
if (availableEntities.length)
(currentGrapherObject as any).data = { availableEntities }

const targetUrl = isNewGrapher
? "/api/charts"
: `/api/charts/${grapher.id}`
Expand Down
2 changes: 1 addition & 1 deletion adminSiteClient/GrapherConfigGridEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ export class GrapherConfigGridEditor extends React.Component<GrapherConfigGridEd

async getFieldDefinitions() {
const json = await fetch(
"https://files.ourworldindata.org/schemas/grapher-schema.003.json"
"https://files.ourworldindata.org/schemas/grapher-schema.004.json"
).then((response) => response.json())
const fieldDescriptions = extractFieldDescriptionsFromSchema(json)
runInAction(() => {
Expand Down
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
}
}
5 changes: 0 additions & 5 deletions devTools/schemaProcessor/columns.json
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,6 @@
"default": true,
"editor": "checkbox"
},
{
"type": "array",
"pointer": "/data/availableEntities",
"editor": "primitiveListEditor"
},
{
"type": "boolean",
"pointer": "/hideLegend",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const GRAPHER_SETTINGS_DRAWER_ID = "grapher-settings-drawer"
export const GRAPHER_IS_IN_IFRAME_CLASS = "IsInIframe"

export const DEFAULT_GRAPHER_CONFIG_SCHEMA =
"https://files.ourworldindata.org/schemas/grapher-schema.003.json"
"https://files.ourworldindata.org/schemas/grapher-schema.004.json"

export const DEFAULT_GRAPHER_ENTITY_TYPE = "country or region"
export const DEFAULT_GRAPHER_ENTITY_TYPE_PLURAL = "countries and regions"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$schema: "http://json-schema.org/draft-07/schema#"
$id: "https://files.ourworldindata.org/schemas/grapher-schema.003.json"
$id: "https://files.ourworldindata.org/schemas/grapher-schema.004.json"
$defs:
axis:
type: object
Expand Down Expand Up @@ -201,7 +201,7 @@ properties:
type: string
description: Url of the concrete schema version to use to validate this document
format: uri
default: "https://files.ourworldindata.org/schemas/grapher-schema.003.json"
default: "https://files.ourworldindata.org/schemas/grapher-schema.004.json"
id:
type: integer
description: Internal DB id. Useful internally for OWID but not required if just using grapher directly.
Expand Down Expand Up @@ -305,16 +305,6 @@ properties:
type: boolean
default: true
description: Whether to show the (non-map) chart tab
data:
type: object
description: Obsolete name - used only to store the available entities
properties:
availableEntities:
type: array
description: List of available entities
items:
type: string
additionalProperties: false
hideLegend:
type: boolean
default: false
Expand Down

0 comments on commit 3531a62

Please sign in to comment.