Skip to content

Commit

Permalink
stats-updater: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bperel committed Aug 20, 2024
1 parent 2b92718 commit a496a13
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 25 deletions.
1 change: 0 additions & 1 deletion apps/stats-updater/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 2 additions & 0 deletions apps/stats-updater/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 16 additions & 24 deletions apps/stats-updater/index.ts
Original file line number Diff line number Diff line change
@@ -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 [
Expand All @@ -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",
Expand All @@ -48,7 +40,6 @@ const tables = [
"utilisateurs_publications_suggerees",
];


let connection: PoolConnection;

const pool = createPool({
Expand Down Expand Up @@ -207,15 +198,16 @@ 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)
SET utilisateurs_publications_suggerees.publicationcode = i.publicationcode
, 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`);

Expand Down

0 comments on commit a496a13

Please sign in to comment.