mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge branch 'master' into semaphore
This commit is contained in:
commit
f741986b2b
@ -10,7 +10,7 @@ Decimal.set({
|
||||
})
|
||||
|
||||
const constants = {
|
||||
DB_VERSION: '0055-consistent_deleted_users',
|
||||
DB_VERSION: '0056-consistent_transactions_table',
|
||||
DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0
|
||||
LOG4JS_CONFIG: 'log4js-config.json',
|
||||
// default log level on production should be info
|
||||
|
||||
39
database/migrations/0056-consistent_transactions_table.ts
Normal file
39
database/migrations/0056-consistent_transactions_table.ts
Normal file
@ -0,0 +1,39 @@
|
||||
/* MIGRATION TO add users that have a transaction but do not exist */
|
||||
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { OkPacket } from 'mysql'
|
||||
|
||||
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
const missingUserIds = await queryFn(`
|
||||
SELECT user_id FROM transactions
|
||||
WHERE NOT EXISTS (SELECT id FROM users WHERE id = user_id) GROUP BY user_id;`)
|
||||
|
||||
for (let i = 0; i < missingUserIds.length; i++) {
|
||||
let gradidoId = ''
|
||||
let countIds: any[] = []
|
||||
do {
|
||||
gradidoId = uuidv4()
|
||||
countIds = await queryFn(
|
||||
`SELECT COUNT(*) FROM \`users\` WHERE \`gradido_id\` = "${gradidoId}"`,
|
||||
)
|
||||
} while (countIds[0] > 0)
|
||||
|
||||
const userContact = (await queryFn(`
|
||||
INSERT INTO user_contacts
|
||||
(type, user_id, email, email_checked, created_at, deleted_at)
|
||||
VALUES
|
||||
('EMAIL', ${missingUserIds[i].user_id}, 'deleted.user${missingUserIds[i].user_id}@gradido.net', 0, NOW(), NOW());`)) as unknown as OkPacket
|
||||
|
||||
await queryFn(`
|
||||
INSERT INTO users
|
||||
(id, gradido_id, email_id, first_name, last_name, deleted_at, password_encryption_type, created_at, language)
|
||||
VALUES
|
||||
(${missingUserIds[i].user_id}, '${gradidoId}', ${userContact.insertId}, 'DELETED', 'USER', NOW(), 0, NOW(), 'de');`)
|
||||
}
|
||||
}
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-empty-function */
|
||||
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
|
||||
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {}
|
||||
Loading…
x
Reference in New Issue
Block a user