3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-11 20:55:01 +00:00

feat: upgrade to TypeORM 0.3

This commit is contained in:
Dragory 2023-07-01 12:17:45 +00:00
parent 8cee4ec1e4
commit 761ff27771
No known key found for this signature in database
57 changed files with 412 additions and 325 deletions

View file

@ -1,13 +1,13 @@
import moment from "moment-timezone";
import { getRepository, In } from "typeorm";
import { In } from "typeorm";
import { DBDateFormat } from "../../utils";
import { connection } from "../db";
import { dataSource } from "../dataSource";
import { Config } from "../entities/Config";
const CLEAN_PER_LOOP = 50;
export async function cleanupConfigs() {
const configRepository = getRepository(Config);
const configRepository = dataSource.getRepository(Config);
// FIXME: The query below doesn't work on MySQL 8.0. Pending an update.
return;
@ -18,7 +18,7 @@ export async function cleanupConfigs() {
// >1 month old: 1 config retained per month
const oneMonthCutoff = moment.utc().subtract(30, "days").format(DBDateFormat);
do {
rows = await connection.query(
rows = await dataSource.query(
`
WITH _configs
AS (
@ -56,7 +56,7 @@ export async function cleanupConfigs() {
// >2 weeks old: 1 config retained per day
const twoWeekCutoff = moment.utc().subtract(2, "weeks").format(DBDateFormat);
do {
rows = await connection.query(
rows = await dataSource.query(
`
WITH _configs
AS (

View file

@ -1,7 +1,7 @@
import moment from "moment-timezone";
import { getRepository, In } from "typeorm";
import { In } from "typeorm";
import { DAYS, DBDateFormat, MINUTES, SECONDS, sleep } from "../../utils";
import { connection } from "../db";
import { dataSource } from "../dataSource";
import { SavedMessage } from "../entities/SavedMessage";
/**
@ -16,7 +16,7 @@ const CLEAN_PER_LOOP = 100;
export async function cleanupMessages(): Promise<number> {
let cleaned = 0;
const messagesRepository = getRepository(SavedMessage);
const messagesRepository = dataSource.getRepository(SavedMessage);
const deletedAtThreshold = moment.utc().subtract(DELETED_MESSAGE_RETENTION_PERIOD, "ms").format(DBDateFormat);
const postedAtThreshold = moment.utc().subtract(RETENTION_PERIOD, "ms").format(DBDateFormat);
@ -27,7 +27,7 @@ export async function cleanupMessages(): Promise<number> {
// when a message was being inserted at the same time
let ids: string[];
do {
const deletedMessageRows = await connection.query(
const deletedMessageRows = await dataSource.query(
`
SELECT id
FROM messages
@ -40,7 +40,7 @@ export async function cleanupMessages(): Promise<number> {
[deletedAtThreshold],
);
const oldPostedRows = await connection.query(
const oldPostedRows = await dataSource.query(
`
SELECT id
FROM messages
@ -53,7 +53,7 @@ export async function cleanupMessages(): Promise<number> {
[postedAtThreshold],
);
const oldBotPostedRows = await connection.query(
const oldBotPostedRows = await dataSource.query(
`
SELECT id
FROM messages

View file

@ -1,7 +1,7 @@
import moment from "moment-timezone";
import { getRepository, In } from "typeorm";
import { In } from "typeorm";
import { DAYS, DBDateFormat } from "../../utils";
import { connection } from "../db";
import { dataSource } from "../dataSource";
import { NicknameHistoryEntry } from "../entities/NicknameHistoryEntry";
export const NICKNAME_RETENTION_PERIOD = 30 * DAYS;
@ -10,13 +10,13 @@ const CLEAN_PER_LOOP = 500;
export async function cleanupNicknames(): Promise<number> {
let cleaned = 0;
const nicknameHistoryRepository = getRepository(NicknameHistoryEntry);
const nicknameHistoryRepository = dataSource.getRepository(NicknameHistoryEntry);
const dateThreshold = moment.utc().subtract(NICKNAME_RETENTION_PERIOD, "ms").format(DBDateFormat);
// Clean old nicknames (NICKNAME_RETENTION_PERIOD)
let rows;
do {
rows = await connection.query(
rows = await dataSource.query(
`
SELECT id
FROM nickname_history

View file

@ -1,7 +1,7 @@
import moment from "moment-timezone";
import { getRepository, In } from "typeorm";
import { In } from "typeorm";
import { DAYS, DBDateFormat } from "../../utils";
import { connection } from "../db";
import { dataSource } from "../dataSource";
import { UsernameHistoryEntry } from "../entities/UsernameHistoryEntry";
export const USERNAME_RETENTION_PERIOD = 30 * DAYS;
@ -10,13 +10,13 @@ const CLEAN_PER_LOOP = 500;
export async function cleanupUsernames(): Promise<number> {
let cleaned = 0;
const usernameHistoryRepository = getRepository(UsernameHistoryEntry);
const usernameHistoryRepository = dataSource.getRepository(UsernameHistoryEntry);
const dateThreshold = moment.utc().subtract(USERNAME_RETENTION_PERIOD, "ms").format(DBDateFormat);
// Clean old usernames (USERNAME_RETENTION_PERIOD)
let rows;
do {
rows = await connection.query(
rows = await dataSource.query(
`
SELECT id
FROM username_history