mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
fix(database): consistent deleted at bewteen users and user contacts
This commit is contained in:
parent
e00fe51017
commit
4a27fa07f0
26
database/migrations/0055-consistent_deleted_users.ts
Normal file
26
database/migrations/0055-consistent_deleted_users.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/* MIGRATION TO soft delete user contacts of soft deleted users */
|
||||||
|
|
||||||
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
|
||||||
|
export async function upgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||||
|
const contactsToFix = await queryFn(`
|
||||||
|
SELECT user_contacts.id, users.deleted_at
|
||||||
|
FROM user_contacts JOIN users ON users.email_id = user_contacts.id
|
||||||
|
WHERE user_contacts.deleted_at IS NULL
|
||||||
|
AND user_id IN (SELECT id FROM users WHERE deleted_at IS NOT NULL);`)
|
||||||
|
|
||||||
|
for (let i = 0; i < contactsToFix.length; i++) {
|
||||||
|
const deletedAt = new Date(contactsToFix[i].deleted_at)
|
||||||
|
.toISOString()
|
||||||
|
.slice(0, 19)
|
||||||
|
.replace('T', ' ')
|
||||||
|
|
||||||
|
await queryFn(`
|
||||||
|
UPDATE user_contacts SET deleted_at = '${deletedAt}' WHERE id = ${contactsToFix[i].id};`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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