|
| 1 | +import { type MigrationJob } from '~db/prisma/dataMigrationRunner' |
| 2 | +import { type JobDef } from '~db/prisma/jobPreRun' |
| 3 | + |
| 4 | +/** Define the job metadata here. */ |
| 5 | +const jobDef: JobDef = { |
| 6 | + jobId: '2025-02-01_update-org-socialmedia-website-published', |
| 7 | + title: 'Set published to false for Twitter/X URLs in OrgSocialMedia and OrgWebsite', |
| 8 | + createdBy: 'Diana Garbarino', |
| 9 | + description: |
| 10 | + 'Find all orgs with URLs starting with http(s)://twitter.com/ or http(s)://x.com/ and set published to false.', |
| 11 | +} |
| 12 | + |
| 13 | +/** |
| 14 | + * Job export - this variable MUST be UNIQUE |
| 15 | + */ |
| 16 | +export const job20250201_update_org_socialmedia_website_published = { |
| 17 | + title: `[${jobDef.jobId}] ${jobDef.title}`, |
| 18 | + task: async (ctx, task) => { |
| 19 | + const { createLogger, formatMessage, jobPostRunner, prisma } = ctx |
| 20 | + /** Create logging instance */ |
| 21 | + createLogger(task, jobDef.jobId) |
| 22 | + const log = (...args: Parameters<typeof formatMessage>) => (task.output = formatMessage(...args)) |
| 23 | + |
| 24 | + // Define conditions for both http and https URLs |
| 25 | + const urlConditions = [ |
| 26 | + { url: { startsWith: 'https://twitter.com/' } }, |
| 27 | + { url: { startsWith: 'http://twitter.com/' } }, |
| 28 | + { url: { startsWith: 'https://x.com/' } }, |
| 29 | + { url: { startsWith: 'http://x.com/' } }, |
| 30 | + ] |
| 31 | + |
| 32 | + // Update OrgSocialMedia table |
| 33 | + const socialMediaUpdate = await prisma.orgSocialMedia.updateMany({ |
| 34 | + where: { OR: urlConditions }, |
| 35 | + data: { published: false }, |
| 36 | + }) |
| 37 | + |
| 38 | + // Update OrgWebsite table |
| 39 | + const websiteUpdate = await prisma.orgWebsite.updateMany({ |
| 40 | + where: { OR: urlConditions }, |
| 41 | + data: { published: false }, |
| 42 | + }) |
| 43 | + |
| 44 | + log(`Updated ${socialMediaUpdate.count} records in OrgSocialMedia to set published = false.`) |
| 45 | + log(`Updated ${websiteUpdate.count} records in OrgWebsite to set published = false.`) |
| 46 | + |
| 47 | + /** |
| 48 | + * DO NOT REMOVE BELOW |
| 49 | + * |
| 50 | + * This writes a record to the DB to register that this migration has run successfully. |
| 51 | + */ |
| 52 | + await jobPostRunner(jobDef) |
| 53 | + }, |
| 54 | + def: jobDef, |
| 55 | +} satisfies MigrationJob |
0 commit comments