mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-03-24 17:41:27 -04:00
Add 2026-03-08-migrate-avatar-url.ts
This commit is contained in:
38
backend/scripts/2026-03-08-migrate-avatar-url.ts
Normal file
38
backend/scripts/2026-03-08-migrate-avatar-url.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import {runScript} from './run-script'
|
||||
import {log} from 'shared/monitoring/log'
|
||||
import {bulkUpdate} from 'shared/supabase/utils'
|
||||
import {chunk} from 'lodash'
|
||||
import {removeUndefinedProps} from 'common/util/object'
|
||||
|
||||
runScript(async ({pg}) => {
|
||||
const users = await pg.manyOrNone(`
|
||||
select u.id, p.pinned_url
|
||||
from users u
|
||||
left join profiles p on p.user_id = u.id
|
||||
`)
|
||||
|
||||
log('Found', users.length, 'users to migrate')
|
||||
|
||||
const userUpdates: {id: string; avatar_url: string}[] = []
|
||||
|
||||
for (const {id, pinned_url} of users) {
|
||||
if (pinned_url) {
|
||||
userUpdates.push(
|
||||
removeUndefinedProps({
|
||||
id,
|
||||
avatar_url: pinned_url,
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
log(`Migrating ${userUpdates.length} users`)
|
||||
|
||||
let userCount = 0
|
||||
for (const batch of chunk(userUpdates, 100)) {
|
||||
await bulkUpdate(pg, 'users', ['id'], batch)
|
||||
log('Updated users', (userCount += batch.length))
|
||||
}
|
||||
|
||||
log('Migration complete')
|
||||
})
|
||||
@@ -19,6 +19,8 @@ export const runScript = async (
|
||||
|
||||
debug('[runScript] Running script...')
|
||||
await main({pg})
|
||||
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
export async function initEnvVariables() {
|
||||
|
||||
Reference in New Issue
Block a user