diff --git a/adminSiteServer/apiRouter.ts b/adminSiteServer/apiRouter.ts index b89ff4f585d..402b48434e4 100644 --- a/adminSiteServer/apiRouter.ts +++ b/adminSiteServer/apiRouter.ts @@ -14,7 +14,7 @@ import { } from "../settings/serverSettings.js" import { expectInt, isValidSlug } from "../serverUtils/serverUtil.js" import { OldChart, Chart, getGrapherById } from "../db/model/Chart.js" -import { Request, Response, CurrentUser } from "./authentication.js" +import { Request, CurrentUser } from "./authentication.js" import { getMergedGrapherConfigForVariable, fetchS3MetadataByPath, @@ -36,7 +36,6 @@ import { OwidGdocPostInterface, parseIntOrUndefined, parseToOperation, - DbEnrichedPost, DbRawPostWithGdocPublishStatus, SuggestedChartRevisionStatus, variableAnnotationAllowedColumnNamesAndTypes, @@ -60,7 +59,6 @@ import { DbRawVariable, DbRawOrigin, parseOriginsRow, - AnalyticsPageviewsTableName, PostsTableName, DbRawPost, } from "@ourworldindata/types" @@ -102,11 +100,9 @@ import { Link } from "../db/model/Link.js" import { In } from "typeorm" import { logErrorAndMaybeSendToBugsnag } from "../serverUtils/errorLog.js" import { GdocFactory } from "../db/model/Gdoc/GdocFactory.js" -import { Knex } from "knex" import { getRouteWithROTransaction, deleteRouteWithRWTransaction, - patchRouteWithRWTransaction, putRouteWithRWTransaction, postRouteWithRWTransaction, } from "./routerHelpers.js" diff --git a/adminSiteServer/gitDataExport.ts b/adminSiteServer/gitDataExport.ts index f2e066d0b2a..f14fcd6643d 100644 --- a/adminSiteServer/gitDataExport.ts +++ b/adminSiteServer/gitDataExport.ts @@ -16,7 +16,6 @@ import filenamify from "filenamify" import { execFormatted } from "../db/execWrapper.js" import { JsonError } from "@ourworldindata/utils" import { DbPlainDataset } from "@ourworldindata/types" -import { Knex } from "knex" import { getSourcesForDataset } from "../db/model/Source.js" const datasetToReadme = async ( diff --git a/adminSiteServer/routerHelpers.tsx b/adminSiteServer/routerHelpers.tsx index 073e82a1bfb..65537eac6f0 100644 --- a/adminSiteServer/routerHelpers.tsx +++ b/adminSiteServer/routerHelpers.tsx @@ -1,5 +1,5 @@ import { FunctionalRouter } from "./FunctionalRouter.js" -import { IRouter, Request, Response, Router } from "express" +import { Request, Response } from "express" import * as db from "../db/db.js" export function getRouteWithROTransaction( router: FunctionalRouter, diff --git a/baker/DeployUtils.ts b/baker/DeployUtils.ts index aad882b1811..b7e2df21bb7 100644 --- a/baker/DeployUtils.ts +++ b/baker/DeployUtils.ts @@ -11,7 +11,6 @@ import { import { SiteBaker } from "../baker/SiteBaker.js" import { WebClient } from "@slack/web-api" import { DeployChange, DeployMetadata } from "@ourworldindata/utils" -import { Knex } from "knex" import { KnexReadonlyTransaction } from "../db/db.js" const deployQueueServer = new DeployQueueServer() diff --git a/baker/ExplorerBaker.tsx b/baker/ExplorerBaker.tsx index fe487a21ae4..9268476eabc 100644 --- a/baker/ExplorerBaker.tsx +++ b/baker/ExplorerBaker.tsx @@ -5,7 +5,6 @@ import { explorerUrlMigrationsById } from "../explorer/urlMigrations/ExplorerUrl import { ExplorerAdminServer } from "../explorerAdminServer/ExplorerAdminServer.js" import { explorerRedirectTable } from "../explorerAdminServer/ExplorerRedirects.js" import { renderExplorerPage } from "./siteRenderers.js" -import { Knex } from "knex" import * as db from "../db/db.js" export const bakeAllPublishedExplorers = async ( diff --git a/baker/GrapherBaker.tsx b/baker/GrapherBaker.tsx index 967eeb5ceb6..ca4e10f716d 100644 --- a/baker/GrapherBaker.tsx +++ b/baker/GrapherBaker.tsx @@ -58,7 +58,6 @@ import { parseFaqs } from "../db/model/Gdoc/rawToEnriched.js" import { GdocPost } from "../db/model/Gdoc/GdocPost.js" import { getShortPageCitation } from "../site/gdocs/utils.js" import { getSlugForTopicTag, getTagToSlugMap } from "./GrapherBakingUtils.js" -import { Knex } from "knex" import { knexRaw } from "../db/db.js" import { getRelatedChartsForVariable } from "../db/model/Chart.js" import pMap from "p-map" diff --git a/baker/SiteBaker.tsx b/baker/SiteBaker.tsx index b4d57c11fca..ac9646371d0 100644 --- a/baker/SiteBaker.tsx +++ b/baker/SiteBaker.tsx @@ -103,7 +103,6 @@ import { getVariableMetadata, getVariableOfDatapageIfApplicable, } from "../db/model/Variable.js" -import { Knex } from "knex" type PrefetchedAttachments = { linkedDocuments: Record diff --git a/baker/algolia/indexChartsToAlgolia.ts b/baker/algolia/indexChartsToAlgolia.ts index 67dbade7f24..37c5225b946 100644 --- a/baker/algolia/indexChartsToAlgolia.ts +++ b/baker/algolia/indexChartsToAlgolia.ts @@ -8,7 +8,6 @@ import { MarkdownTextWrap } from "@ourworldindata/components" import { getAnalyticsPageviewsByUrlObj } from "../../db/model/Pageview.js" import { Link } from "../../db/model/Link.js" import { getRelatedArticles } from "../../db/model/Post.js" -import { Knex } from "knex" const computeScore = (record: Omit): number => { const { numRelatedArticles, views_7d } = record diff --git a/baker/algolia/indexExplorersToAlgolia.ts b/baker/algolia/indexExplorersToAlgolia.ts index 675a22bbdbc..3dde2b93ab9 100644 --- a/baker/algolia/indexExplorersToAlgolia.ts +++ b/baker/algolia/indexExplorersToAlgolia.ts @@ -13,7 +13,6 @@ import { getAnalyticsPageviewsByUrlObj } from "../../db/model/Pageview.js" import { chunkParagraphs } from "../chunk.js" import { SearchIndexName } from "../../site/search/searchTypes.js" import { Chart } from "../../db/model/Chart.js" -import { Knex } from "knex" type ExplorerBlockColumns = { type: "columns" diff --git a/baker/algolia/indexToAlgolia.tsx b/baker/algolia/indexToAlgolia.tsx index 787495f3585..4e841ed6612 100644 --- a/baker/algolia/indexToAlgolia.tsx +++ b/baker/algolia/indexToAlgolia.tsx @@ -31,7 +31,6 @@ import { getPostTags, getPostsFromSnapshots, } from "../../db/model/Post.js" -import { Knex } from "knex" interface TypeAndImportance { type: PageType diff --git a/baker/countryProfiles.tsx b/baker/countryProfiles.tsx index 9f54b872d7d..f0993c4b966 100644 --- a/baker/countryProfiles.tsx +++ b/baker/countryProfiles.tsx @@ -18,7 +18,6 @@ import { countries, getCountryBySlug, JsonError } from "@ourworldindata/utils" import { renderToHtmlPage } from "./siteRenderers.js" import { dataAsDF } from "../db/model/Variable.js" import pl from "nodejs-polars" -import knex from "knex" export const countriesIndexPage = (baseUrl: string) => renderToHtmlPage( diff --git a/baker/formatWordpressPost.tsx b/baker/formatWordpressPost.tsx index 2412f69e105..ed1261bc5a6 100644 --- a/baker/formatWordpressPost.tsx +++ b/baker/formatWordpressPost.tsx @@ -59,7 +59,6 @@ import { renderKeyInsights, renderProminentLinks } from "./siteRenderers.js" import { KEY_INSIGHTS_CLASS_NAME } from "../site/blocks/KeyInsights.js" import { RELATED_CHARTS_CLASS_NAME } from "../site/blocks/RelatedCharts.js" import { logErrorAndMaybeSendToBugsnag } from "../serverUtils/errorLog.js" -import { Knex } from "knex" import { KnexReadonlyTransaction } from "../db/db.js" const initMathJax = () => { diff --git a/baker/postUpdatedHook.ts b/baker/postUpdatedHook.ts index 321b8eb48fe..6cf528882f4 100644 --- a/baker/postUpdatedHook.ts +++ b/baker/postUpdatedHook.ts @@ -23,7 +23,6 @@ import { getPostLinksBySourceId, insertManyPostLinks, } from "../db/model/PostLink.js" -import { Knex } from "knex" const argv = parseArgs(process.argv.slice(2)) const zeroDateString = "0000-00-00 00:00:00" diff --git a/baker/redirects.test.ts b/baker/redirects.test.ts index 6b2985e5c6e..20b1a3bf828 100644 --- a/baker/redirects.test.ts +++ b/baker/redirects.test.ts @@ -4,8 +4,7 @@ import * as redirects from "./redirects.js" import { resolveInternalRedirect } from "./redirects.js" import { jest } from "@jest/globals" -import { Knex } from "knex" -import { KnexReadonlyTransaction, knexReadonlyTransaction } from "../db/db.js" +import { KnexReadonlyTransaction } from "../db/db.js" type ArrayForMap = [string, string][] @@ -18,8 +17,6 @@ const getFormattedUrl = (url: string): Url => { return Url.fromURL(formatUrls(url)) } -const knex: Knex = {} as Knex - it("resolves pathnames", async () => { const src = "/hello" const target = "/world" diff --git a/baker/redirects.ts b/baker/redirects.ts index 221de9684a1..cce1a66df56 100644 --- a/baker/redirects.ts +++ b/baker/redirects.ts @@ -4,7 +4,6 @@ import { isCanonicalInternalUrl } from "./formatting.js" import { resolveExplorerRedirect } from "./replaceExplorerRedirects.js" import { logErrorAndMaybeSendToBugsnag } from "../serverUtils/errorLog.js" import { getRedirectsFromDb } from "../db/model/Redirect.js" -import { Knex } from "knex" export const getRedirects = async (knex: db.KnexReadonlyTransaction) => { const staticRedirects = [ diff --git a/baker/siteRenderers.test.ts b/baker/siteRenderers.test.ts index 2bda1698615..d6bbd0dce56 100755 --- a/baker/siteRenderers.test.ts +++ b/baker/siteRenderers.test.ts @@ -3,7 +3,6 @@ import {} from "../site/blocks/ProminentLink.js" import { renderExplorerPage } from "./siteRenderers.js" import { ExplorerProgram } from "../explorer/ExplorerProgram.js" -import { Knex } from "knex" import { KnexReadonlyTransaction } from "../db/db.js" // Note: renderProminentLinks() tests are now e2e (see kitchenSink.js) diff --git a/baker/siteRenderers.tsx b/baker/siteRenderers.tsx index daf0e3040a1..012fbf6551d 100644 --- a/baker/siteRenderers.tsx +++ b/baker/siteRenderers.tsx @@ -90,7 +90,6 @@ import { GdocPost } from "../db/model/Gdoc/GdocPost.js" import { logErrorAndMaybeSendToBugsnag } from "../serverUtils/errorLog.js" import { GdocFactory } from "../db/model/Gdoc/GdocFactory.js" import { SiteNavigationStatic } from "../site/SiteNavigation.js" -import { Knex } from "knex" export const renderToHtmlPage = (element: any) => `${ReactDOMServer.renderToStaticMarkup(element)}` diff --git a/baker/sitemap.ts b/baker/sitemap.ts index 73f82a121ad..eb375ffd2ab 100644 --- a/baker/sitemap.ts +++ b/baker/sitemap.ts @@ -13,7 +13,6 @@ import { EXPLORERS_ROUTE_FOLDER } from "../explorer/ExplorerConstants.js" import { ExplorerProgram } from "../explorer/ExplorerProgram.js" import { GdocPost } from "../db/model/Gdoc/GdocPost.js" import { getPostsFromSnapshots } from "../db/model/Post.js" -import { Knex } from "knex" import { calculateDataInsightIndexPageCount } from "../db/model/Gdoc/gdocUtils.js" interface SitemapUrl { diff --git a/db/model/Chart.ts b/db/model/Chart.ts index ffa938ca437..923b3077353 100644 --- a/db/model/Chart.ts +++ b/db/model/Chart.ts @@ -30,7 +30,6 @@ import { BAKED_BASE_URL, OPENAI_API_KEY, } from "../../settings/serverSettings.js" -import { Knex } from "knex" // XXX hardcoded filtering to public parent tags export const PUBLIC_TAG_PARENT_IDS = [ @@ -261,11 +260,6 @@ WHERE c.config -> "$.isPublished" = true } } -interface ChartRow { - id: number - config: any -} - // TODO integrate this old logic with typeorm export class OldChart { static listFields = ` diff --git a/db/model/Dataset.ts b/db/model/Dataset.ts index 2ab79fffa65..68110afcab6 100644 --- a/db/model/Dataset.ts +++ b/db/model/Dataset.ts @@ -22,7 +22,6 @@ import { VariablesTableName, DbRawVariable, } from "@ourworldindata/types" -import { Knex } from "knex" @Entity("datasets") @Unique(["name", "namespace"]) diff --git a/db/model/Pageview.ts b/db/model/Pageview.ts index c288d605530..d2a1d92f9b9 100644 --- a/db/model/Pageview.ts +++ b/db/model/Pageview.ts @@ -2,7 +2,6 @@ import { keyBy } from "lodash" import { Entity, Column, BaseEntity } from "typeorm" import { RawPageview } from "@ourworldindata/utils" import * as db from "../db.js" -import { Knex } from "knex" import { DbPlainAnalyticsPageview, AnalyticsPageviewsTableName, diff --git a/db/model/Post.ts b/db/model/Post.ts index a3c749e17db..8fead14f150 100644 --- a/db/model/Post.ts +++ b/db/model/Post.ts @@ -29,7 +29,6 @@ import { GdocPost } from "./Gdoc/GdocPost.js" import { SiteNavigationStatic } from "../../site/SiteNavigation.js" import { decodeHTML } from "entities" import { RelatedResearchQueryResult } from "../wpdb" -import { number } from "prop-types" export const postsTable = "posts" diff --git a/db/model/PostLink.ts b/db/model/PostLink.ts index b3dc226ac30..57a56a9c855 100644 --- a/db/model/PostLink.ts +++ b/db/model/PostLink.ts @@ -6,7 +6,6 @@ import { Url, } from "@ourworldindata/utils" import { getLinkType, getUrlTarget } from "@ourworldindata/components" -import { Knex } from "knex" import { KnexReadWriteTransaction, KnexReadonlyTransaction } from "../db.js" export function postLinkCreateFromUrl({ url, diff --git a/db/model/Redirect.ts b/db/model/Redirect.ts index bff3693f7cd..d0c60439bfe 100644 --- a/db/model/Redirect.ts +++ b/db/model/Redirect.ts @@ -1,4 +1,3 @@ -import { Knex } from "knex" import { DbPlainRedirect } from "@ourworldindata/types" import * as db from "../db" diff --git a/db/model/Source.ts b/db/model/Source.ts index 9d06bf94693..7c58b3d83d0 100644 --- a/db/model/Source.ts +++ b/db/model/Source.ts @@ -1,5 +1,4 @@ import { Entity, PrimaryGeneratedColumn, Column, BaseEntity } from "typeorm" -import { Knex } from "knex" import { DbEnrichedSource, DbRawSource, diff --git a/db/model/User.ts b/db/model/User.ts index db4d552f896..8901c31d2f0 100644 --- a/db/model/User.ts +++ b/db/model/User.ts @@ -15,7 +15,6 @@ import { DbInsertUser, UsersTableName, } from "@ourworldindata/types" -import { Knex } from "knex" import { KnexReadWriteTransaction, KnexReadonlyTransaction } from "../db.js" @Entity("users") diff --git a/db/model/Variable.ts b/db/model/Variable.ts index db9e38eeaa5..06a8da01728 100644 --- a/db/model/Variable.ts +++ b/db/model/Variable.ts @@ -26,7 +26,6 @@ import { OwidProcessingLevel, DbRawVariable, } from "@ourworldindata/types" -import { Knex } from "knex/types" import { knexRaw, knexRawFirst } from "../db.js" export interface VariableRow { diff --git a/db/refreshPageviewsFromDatasette.ts b/db/refreshPageviewsFromDatasette.ts index a015bc48eef..cb32bd7a824 100644 --- a/db/refreshPageviewsFromDatasette.ts +++ b/db/refreshPageviewsFromDatasette.ts @@ -4,7 +4,6 @@ import Papa from "papaparse" import * as db from "./db.js" import { DbPlainAnalyticsPageview } from "@ourworldindata/types" import { omitUndefinedValues } from "@ourworldindata/utils" -import { Knex } from "knex" const analyticsPageviewsColumnNames: Array = [ "day", diff --git a/db/syncPostsToGrapher.ts b/db/syncPostsToGrapher.ts index 54fc9585b5b..3cc1390ea44 100644 --- a/db/syncPostsToGrapher.ts +++ b/db/syncPostsToGrapher.ts @@ -23,7 +23,6 @@ import { } from "./model/PostLink.js" import { renderTablePress } from "../site/Tablepress.js" import pMap from "p-map" -import { Knex } from "knex" const zeroDateString = "0000-00-00 00:00:00" @@ -333,9 +332,7 @@ const syncPostsToGrapher = async ( ) const doesExistInWordpress = keyBy(rows, "ID") - const existsInGrapher = await select("id").from( - knex.from(postsTable) - ) + const existsInGrapher = await select("id").from(knex.from(postsTable)) const doesExistInGrapher = keyBy(existsInGrapher, "id") const toDelete = existsInGrapher @@ -408,19 +405,18 @@ const syncPostsToGrapher = async ( linksToDelete.push(...linksToModify.linksToDelete) } - - if (toDelete.length) - await knex.whereIn("id", toDelete).delete().from(postsTable) - - for (const row of toInsert) { - const rowForDb = serializePostRow(row) - if (doesExistInGrapher[row.id]) - await knex - .update(rowForDb) - .where("id", "=", rowForDb.id) - .into(postsTable) - else await knex.insert(rowForDb).into(postsTable) - } + if (toDelete.length) + await knex.whereIn("id", toDelete).delete().from(postsTable) + + for (const row of toInsert) { + const rowForDb = serializePostRow(row) + if (doesExistInGrapher[row.id]) + await knex + .update(rowForDb) + .where("id", "=", rowForDb.id) + .into(postsTable) + else await knex.insert(rowForDb).into(postsTable) + } // TODO: unify our DB access and then do everything in one transaction if (linksToAdd.length) {