Skip to content

Commit

Permalink
stats-updater: Fix Dockerfile
Browse files Browse the repository at this point in the history
bperel committed Aug 18, 2024
1 parent 02d4e1e commit a9df2e9
Showing 5 changed files with 29 additions and 44 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/deploy-stats-updater.yml
Original file line number Diff line number Diff line change
@@ -46,11 +46,11 @@ jobs:
fingerprint: ${{ secrets.PRODUCTION_SSH_FINGERPRINT }}
username: ${{ secrets.PRODUCTION_SSH_USER }}
key: ${{ secrets.PRODUCTION_SSH_KEY }}
source: /home/bperel/workspace/DucksManager2/packages/api/.env.prod.local
target: .env
source: /home/bperel/workspace/DucksManager2/apps/stats-updater/.env.prod.local
target: apps/stats-updater/.env

- name: Build stats-updater bundle
run: . .env && DATABASE_URL_DM_STATS=$DATABASE_URL_DM_STATS pnpm build:stats-updater
run: pnpm build:stats-updater

- name: Build and push stats-updater
uses: docker/build-push-action@v5
2 changes: 2 additions & 0 deletions apps/stats-updater/.env
Original file line number Diff line number Diff line change
@@ -6,4 +6,6 @@ MYSQL_DM_DATABASE=dm
MYSQL_DM_STATS_DATABASE=dm_stats
MYSQL_COA_DATABASE=coa

DATABASE_URL_COA=mysql://root:changeme@localhost:64999/coa
DATABASE_URL_DM=mysql://root:changeme@localhost:64999/dm
DATABASE_URL_DM_STATS=mysql://root:changeme@localhost:64999/dm_stats
9 changes: 0 additions & 9 deletions apps/stats-updater/.env.prod

This file was deleted.

6 changes: 1 addition & 5 deletions apps/stats-updater/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -3,11 +3,7 @@ services:
init: true
image: ghcr.io/bperel/stats-updater
env_file:
- ../../packages/api/.env.prod.local
environment:
MYSQL_DM_STATS_DATABASE: dm_stats
MYSQL_HOST: db
MYSQL_PORT: 3306
- ./.env.prod.local
networks:
- dm-server_db-network
- ducksmanager_dm-network
50 changes: 23 additions & 27 deletions apps/stats-updater/index.ts
Original file line number Diff line number Diff line change
@@ -2,6 +2,16 @@

import "~prisma-schemas/util/groupBy";

const originalConnectionString = process.env.DATABASE_URL_DM_STATS!;
process.env.DATABASE_URL_DM_STATS = originalConnectionString.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,
@@ -26,21 +36,7 @@ db.connect().then(async () => {
await db.runQuery(`DROP DATABASE IF EXISTS ${dbName}_new`);
await db.runQuery(`CREATE DATABASE ${dbName}_new`);

const originalConnectionString = process.env.DATABASE_URL_DM_STATS!;

process.env.DATABASE_URL_DM_STATS = originalConnectionString.replace(
"dm_stats",
"dm_stats_new",
);
const prismaDmStatsNew = (
await import("~prisma-schemas/schemas/dm_stats/client")
).prismaClient;

const prismaDm = (await import("~prisma-schemas/schemas/dm/client"))
.prismaClient;

const prismaCoa = (await import("~prisma-schemas/schemas/coa/client"))
.prismaClient;

await db.runMigrations();

@@ -56,11 +52,11 @@ db.connect().then(async () => {
(userId) => parseInt(userId),
);

await prismaDmStatsNew.authorUser.createMany({
await prismaDmStats.authorUser.createMany({
data: authorUsers.map(({ id: _id, ...rest }) => rest),
});

await prismaDmStatsNew.issueSimple.createMany({
await prismaDmStats.issueSimple.createMany({
data: await prismaDm.issue.findMany({
distinct: ["issuecode", "userId"],
select: {
@@ -79,7 +75,7 @@ db.connect().then(async () => {
});

console.log("Creating storyIssue entries");
await prismaDmStatsNew.storyIssue.createMany({
await prismaDmStats.storyIssue.createMany({
data: await prismaCoa.$queryRaw<
(Pick<inducks_storyversion, "storycode"> &
Pick<inducks_issue, "issuecode" | "oldestdate">)[]
@@ -95,10 +91,10 @@ db.connect().then(async () => {
and sv.storycode != ''`,
});

await prismaDmStatsNew.$executeRaw`OPTIMIZE TABLE histoires_publications`;
await prismaDmStats.$executeRaw`OPTIMIZE TABLE histoires_publications`;

console.log("Creating authorStory entries");
await prismaDmStatsNew.authorStory.createMany({
await prismaDmStats.authorStory.createMany({
data: await prismaCoa.$queryRaw<
(Pick<inducks_storyjob, "personcode"> &
Pick<inducks_storyversion, "storycode">)[]
@@ -112,11 +108,11 @@ db.connect().then(async () => {
and sj.personcode in (${Prisma.join(personcodes)})`,
});

await prismaDmStatsNew.$executeRaw`OPTIMIZE TABLE auteurs_histoires`;
await prismaDmStats.$executeRaw`OPTIMIZE TABLE auteurs_histoires`;

console.log("Creating missingStoryForUser entries");
await prismaDmStatsNew.missingStoryForUser.createMany({
data: await prismaDmStatsNew.$queryRaw<
await prismaDmStats.missingStoryForUser.createMany({
data: await prismaDmStats.$queryRaw<
(Pick<authorUser, "userId"> &
Pick<authorStory, "personcode" | "storycode">)[]
>`
@@ -138,10 +134,10 @@ db.connect().then(async () => {
a_h.storycode`,
});

await prismaDmStatsNew.$executeRaw`OPTIMIZE TABLE utilisateurs_histoires_manquantes`;
await prismaDmStats.$executeRaw`OPTIMIZE TABLE utilisateurs_histoires_manquantes`;

console.log("Creating missingIssueForUser entries");
await prismaDmStatsNew.$executeRaw`
await prismaDmStats.$executeRaw`
insert into utilisateurs_publications_manquantes(ID_User, personcode, storycode, issuecode, oldestdate, Notation)
select distinct u_h_m.ID_User AS userId,
u_h_m.personcode,
@@ -153,16 +149,16 @@ db.connect().then(async () => {
inner join histoires_publications h_p using (storycode)
inner join auteurs_pseudos a_p on a_p.ID_User = u_h_m.ID_User and u_h_m.personcode = a_p.NomAuteurAbrege`;

await prismaDmStatsNew.$executeRaw`OPTIMIZE TABLE utilisateurs_publications_manquantes`;
await prismaDmStats.$executeRaw`OPTIMIZE TABLE utilisateurs_publications_manquantes`;

console.log("Creating suggestedIssueForUser entries");
await prismaDmStatsNew.$executeRaw`
await prismaDmStats.$executeRaw`
insert into utilisateurs_publications_suggerees(ID_User, issuecode, oldestdate, Score)
select ID_User AS userId, issuecode, oldestdate, sum(Notation) AS score
from utilisateurs_publications_manquantes
group by ID_User, issuecode, oldestdate`;

await prismaDmStatsNew.$executeRaw`OPTIMIZE TABLE utilisateurs_publications_suggerees`;
await prismaDmStats.$executeRaw`OPTIMIZE TABLE utilisateurs_publications_suggerees`;

console.log("Adding publicationcode and issuenumber for WTD < 3");
await db.runQuery(`

0 comments on commit a9df2e9

Please sign in to comment.