migrate home-communityUuid for local users

This commit is contained in:
Claus-Peter Huebner 2023-10-10 23:49:30 +02:00
parent 9baa94e148
commit 4f3bb51b02

View File

@ -19,6 +19,14 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
await queryFn(
'ALTER TABLE `users` ADD CONSTRAINT alias_key UNIQUE KEY (`alias`, `community_uuid`);',
)
// read the community uuid of the homeCommunity
const result = await queryFn(`SELECT c.community_uuid from communities as c WHERE c.foreign = 0`)
// and if uuid exists enter the home_community_uuid for all local users
if (result && result[0]) {
await queryFn(
`UPDATE users as u SET u.community_uuid = "${result[0].community_uuid}" WHERE u.foreign = 0 AND u.community_uuid IS NULL`,
)
}
}
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {