diff --git a/apps/stats-updater/Dockerfile b/apps/stats-updater/Dockerfile index 3f7802fc6..13b57772a 100644 --- a/apps/stats-updater/Dockerfile +++ b/apps/stats-updater/Dockerfile @@ -10,5 +10,4 @@ COPY packages/prisma-schemas/client_dm/ /client_dm COPY packages/prisma-schemas/client_dm_stats/ /client_dm_stats COPY packages/prisma-schemas/schemas/dm_stats/migrations/0_init/migration.sql /dm-stats-ddl.sql -EXPOSE 3000 ENTRYPOINT ["bun", "bundle.mjs"] \ No newline at end of file diff --git a/apps/stats-updater/docker-compose.yml b/apps/stats-updater/docker-compose.yml index 62c030764..50dab333e 100644 --- a/apps/stats-updater/docker-compose.yml +++ b/apps/stats-updater/docker-compose.yml @@ -4,6 +4,8 @@ services: image: ghcr.io/bperel/stats-updater env_file: - ./.env.prod.local + environment: + - DATABASE_URL_DM_STATS="${DATABASE_URL_DM_STATS}_new" networks: - dm-server_db-network - ducksmanager_dm-network diff --git a/apps/stats-updater/index.ts b/apps/stats-updater/index.ts index 68a148ac2..866625ed4 100644 --- a/apps/stats-updater/index.ts +++ b/apps/stats-updater/index.ts @@ -1,13 +1,23 @@ #!/usr/bin/env bun -import "~prisma-schemas/util/groupBy"; import * as dotenv from "dotenv"; import { readFileSync } from "fs"; -import { PoolConnection } from "mariadb"; +import type { PoolConnection } from "mariadb"; import { createPool } from "mariadb"; - import * as process from "process"; +import { + type inducks_issue, + type inducks_storyjob, + type inducks_storyversion, + Prisma, +} from "~prisma-schemas/schemas/coa"; +import { prismaClient as prismaCoa } from "~prisma-schemas/schemas/coa/client"; +import type { authorUser } from "~prisma-schemas/schemas/dm"; +import { prismaClient as prismaDm } from "~prisma-schemas/schemas/dm/client"; +import type { authorStory } from "~prisma-schemas/schemas/dm_stats"; +import { prismaClient as prismaDmStats } from "~prisma-schemas/schemas/dm_stats/client"; + dotenv.config(); for (const envKey of [ @@ -22,24 +32,6 @@ for (const envKey of [ } } -process.env.DATABASE_URL_DM_STATS = process.env.DATABASE_URL_DM_STATS!.replace( - "dm_stats", - "dm_stats_new", -); - -import { prismaClient as prismaDm } from "~prisma-schemas/schemas/dm/client" -import { prismaClient as prismaCoa } from "~prisma-schemas/schemas/coa/client" -import { prismaClient as prismaDmStats } from "~prisma-schemas/schemas/dm_stats/client" - -import { - type inducks_issue, - type inducks_storyjob, - type inducks_storyversion, - Prisma, -} from "~prisma-schemas/schemas/coa"; -import type { authorUser } from "~prisma-schemas/schemas/dm"; -import type { authorStory } from "~prisma-schemas/schemas/dm_stats"; - const tables = [ "auteurs_histoires", "histoires_publications", @@ -48,7 +40,6 @@ const tables = [ "utilisateurs_publications_suggerees", ]; - let connection: PoolConnection; const pool = createPool({ @@ -207,7 +198,9 @@ connect().then(async () => { await prismaDmStats.$executeRaw`OPTIMIZE TABLE utilisateurs_publications_suggerees`; - console.log("Adding oldestdate; adding publicationcode and issuenumber for WTD < 3"); + console.log( + "Adding oldestdate; adding publicationcode and issuenumber for WTD < 3", + ); await runQuery(` UPDATE ${dbName}_new.utilisateurs_publications_suggerees JOIN coa.inducks_issue i using (issuecode) @@ -215,7 +208,6 @@ connect().then(async () => { , utilisateurs_publications_suggerees.issuenumber = i.issuenumber , utilisateurs_publications_suggerees.oldestdate = i.oldestdate`); - await runQuery(`DROP DATABASE IF EXISTS ${dbName}_old`); await runQuery(`CREATE DATABASE ${dbName}_old`);