|
| 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-03-05_update-attribute-values-lang-inter', |
| 7 | + title: 'change the name values for All Languages', |
| 8 | + createdBy: 'Diana Garbarino', |
| 9 | + /** Optional: Longer description for the job */ |
| 10 | + description: 'change the name values for All Languages', |
| 11 | +} |
| 12 | +/** |
| 13 | + * Job export - this variable MUST be UNIQUE |
| 14 | + */ |
| 15 | +export const job20250305_update_attribute_values_lang_inter = { |
| 16 | + title: `[${jobDef.jobId}] ${jobDef.title}`, |
| 17 | + task: async (ctx, task) => { |
| 18 | + const { createLogger, formatMessage, jobPostRunner, prisma } = ctx |
| 19 | + /** Create logging instance */ |
| 20 | + createLogger(task, jobDef.jobId) |
| 21 | + const log = (...args: Parameters<typeof formatMessage>) => (task.output = formatMessage(...args)) |
| 22 | + |
| 23 | + // Variables for the update |
| 24 | + const key = 'lang.all-languages-by-interpreter' |
| 25 | + const ns = 'attribute' |
| 26 | + const newTextValue = 'Language assistance available. Contact for more information.' |
| 27 | + // Perform the update |
| 28 | + const update1 = await prisma.translationKey.update({ |
| 29 | + where: { ns_key: { key, ns } }, |
| 30 | + data: { text: newTextValue }, |
| 31 | + }) |
| 32 | + |
| 33 | + log(`Updated translationKey: ${update1.key} with new text: "${update1.text}"`) |
| 34 | + |
| 35 | + const update2 = await prisma.attribute.updateMany({ |
| 36 | + where: { tsKey: key, tsNs: ns }, |
| 37 | + data: { name: newTextValue }, |
| 38 | + }) |
| 39 | + |
| 40 | + log(`Updated ${update2.count} attributes with new name: "${newTextValue}"`) |
| 41 | + |
| 42 | + /** |
| 43 | + * DO NOT REMOVE BELOW |
| 44 | + * |
| 45 | + * This writes a record to the DB to register that this migration has run successfully. |
| 46 | + */ |
| 47 | + await jobPostRunner(jobDef) |
| 48 | + }, |
| 49 | + def: jobDef, |
| 50 | +} satisfies MigrationJob |
0 commit comments