From 805d56fc080b6965520e01fddd3fb42134bbba0e Mon Sep 17 00:00:00 2001 From: Daniel Bachler Date: Tue, 5 Mar 2024 14:38:11 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9D=20remove=20obsolete=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/model/Origin.ts | 26 ----------- db/model/Pageview.ts | 20 -------- db/model/Source.ts | 10 ---- db/model/Variable.ts | 108 +------------------------------------------ 4 files changed, 1 insertion(+), 163 deletions(-) delete mode 100644 db/model/Origin.ts diff --git a/db/model/Origin.ts b/db/model/Origin.ts deleted file mode 100644 index 448ec86cf74..00000000000 --- a/db/model/Origin.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { Entity, PrimaryGeneratedColumn, Column, BaseEntity } from "typeorm" - -@Entity("origins") -export class Origin extends BaseEntity { - @PrimaryGeneratedColumn() id!: number - @Column({ type: "varchar", nullable: true }) title!: string | null - @Column({ type: "varchar", nullable: true }) titleSnapshot!: string | null - @Column({ type: "text", nullable: true }) description!: string | null - @Column({ type: "text", nullable: true }) descriptionSnapshot!: - | string - | null - @Column({ type: "varchar", nullable: true }) producer!: string | null - @Column({ type: "varchar", nullable: true }) attribution!: string | null - @Column({ type: "varchar", nullable: true }) attributionShort!: - | string - | null - @Column({ type: "text", nullable: true }) citationFull!: string | null - @Column({ type: "text", nullable: true }) urlMain!: string | null - @Column({ type: "text", nullable: true }) urlDownload!: string | null - @Column({ type: "date", nullable: true }) dateAccessed!: Date | null - @Column({ type: "varchar", nullable: true }) datePublished!: string | null - @Column({ type: "varchar", nullable: true }) versionProducer!: string | null - // Note: there is an N:M relationship between origins and variables but - // because variables is not a typeORM class but a knew class we don't - // expose it here. -} diff --git a/db/model/Pageview.ts b/db/model/Pageview.ts index d2a1d92f9b9..ac3ffa22ecb 100644 --- a/db/model/Pageview.ts +++ b/db/model/Pageview.ts @@ -1,30 +1,10 @@ import { keyBy } from "lodash" -import { Entity, Column, BaseEntity } from "typeorm" -import { RawPageview } from "@ourworldindata/utils" import * as db from "../db.js" import { DbPlainAnalyticsPageview, AnalyticsPageviewsTableName, } from "@ourworldindata/types" -@Entity("analytics_pageviews") -export class Pageview extends BaseEntity implements RawPageview { - /** The last day with pageview data that is included in the sum */ - @Column({ primary: true }) day!: Date - /** - * The _absolute_ URL of the page, e.g. `https://ourworldindata.org/grapher/life-expectancy`. - * Does not include any query parameters. - * Usually does not include a trailing slash, except for the homepage (`/`) and 404s. - */ - @Column({ primary: true }) url!: string - /** Sum of pageviews over the last 7 days. */ - @Column() views_7d!: number - /** Sum of pageviews over the last 14 days. */ - @Column() views_14d!: number - /** Sum of pageviews over the last 365 days. */ - @Column() views_365d!: number -} - export async function getAnalyticsPageviewsByUrlObj( knex: db.KnexReadonlyTransaction ): Promise<{ diff --git a/db/model/Source.ts b/db/model/Source.ts index 7c58b3d83d0..0f099ddb0fb 100644 --- a/db/model/Source.ts +++ b/db/model/Source.ts @@ -1,4 +1,3 @@ -import { Entity, PrimaryGeneratedColumn, Column, BaseEntity } from "typeorm" import { DbEnrichedSource, DbRawSource, @@ -6,15 +5,6 @@ import { parseSourcesRow, } from "@ourworldindata/types" import { KnexReadonlyTransaction } from "../db.js" - -@Entity("sources") -export class Source extends BaseEntity { - @PrimaryGeneratedColumn() id!: number - @Column() datasetId!: number - @Column() name!: string - @Column({ default: "{}", type: "json" }) description!: any -} - export async function getSourceById( knex: KnexReadonlyTransaction, sourceId: number diff --git a/db/model/Variable.ts b/db/model/Variable.ts index 06a8da01728..5ebb8ddab73 100644 --- a/db/model/Variable.ts +++ b/db/model/Variable.ts @@ -21,118 +21,12 @@ import { OwidVariableId, ChartTypeName, DimensionProperty, - OwidLicense, GrapherInterface, - OwidProcessingLevel, DbRawVariable, } from "@ourworldindata/types" import { knexRaw, knexRawFirst } from "../db.js" -export interface VariableRow { - id: number - name: string - shortName?: string - code: string | null - unit: string - shortUnit: string | null - description: string | null - createdAt: Date - updatedAt: Date - datasetId: number - sourceId: number - display: OwidVariableDisplayConfigInterface - coverage?: string - timespan?: string - columnOrder?: number - catalogPath?: string - dimensions?: Dimensions - schemaVersion?: number - processingLevel?: OwidProcessingLevel - titlePublic?: string - titleVariant?: string - attributionShort?: string - citationInline?: string - descriptionShort?: string - descriptionFromProducer?: string - descriptionKey?: string[] // this is json in the db but by convention it is always a list of strings - descriptionProcessing?: string - licenses?: OwidLicense[] - grapherConfigAdmin?: GrapherInterface - grapherConfigETL?: GrapherInterface - license?: OwidLicense - updatePeriodDays?: number - datasetVersion?: string - version?: string - - // missing here but existsin the DB: - // originalMetadata -} - -interface Dimensions { - originalName: string - originalShortName: string - filters: { - name: string - value: string - }[] -} - -export type UnparsedVariableRow = Omit< - VariableRow, - | "display" - | "descriptionKey" - | "grapherConfigAdmin" - | "grapherConfigETL" - | "license" - | "licenses" -> & { - display: string - descriptionKey?: string - grapherConfigAdmin?: string - grapherConfigETL?: string - license?: string - licenses?: string -} - -export type VariableQueryRow = Readonly< - Omit & { - display: string - datasetName: string - nonRedistributable: number - sourceName: string - sourceDescription: string - dimensions: string - } -> - -export type Field = keyof VariableRow - -export function parseVariableRows( - plainRows: UnparsedVariableRow[] -): VariableRow[] { - const parsedRows: VariableRow[] = [] - for (const plainRow of plainRows) { - const row = { - ...plainRow, - display: plainRow.display - ? JSON.parse(plainRow.display) - : undefined, - descriptionKey: plainRow.descriptionKey - ? JSON.parse(plainRow.descriptionKey) - : [], - grapherConfigAdmin: plainRow.grapherConfigAdmin - ? JSON.parse(plainRow.grapherConfigAdmin) - : [], - grapherConfigETL: plainRow.grapherConfigETL - ? JSON.parse(plainRow.grapherConfigETL) - : [], - licenses: plainRow.licenses ? JSON.parse(plainRow.licenses) : [], - license: plainRow.license ? JSON.parse(plainRow.license) : [], - } - parsedRows.push(row) - } - return parsedRows -} +//export type Field = keyof VariableRow export async function getMergedGrapherConfigForVariable( variableId: number,