Skip to content

Commit

Permalink
feat(db): (ECB-63)[https://inreach.atlassian.net/browse/ECB-63]: upda…
Browse files Browse the repository at this point in the history
…te link for anti-trans map (#1441)

<!--- Please provide a general summary of your changes in the title
above -->

# Pull Request type

<!-- Please try to limit your pull request to one type; submit multiple
pull requests if needed. -->

Please check the type of change your PR introduces:

- [ ] Bugfix
- [x] Feature
- [ ] Code style update (formatting, renaming)
- [ ] Refactoring (no functional changes, no API changes)
- [ ] Build-related changes
- [ ] Documentation content changes
- [ ] Other (please describe):

## What is the current behavior?

<!-- Please describe the current behavior that you are modifying, or
link to a relevant issue. -->

Issue Number: N/A

## What is the new behavior?

<!-- Please describe the behavior or changes that are being added by
this PR. -->

-
-
-

## Does this introduce a breaking change?

- [ ] Yes
- [ ] No

<!-- If this does introduce a breaking change, please describe the
impact and migration path for existing applications below. -->

## Other information

<!-- Any other information that is important to this PR, such as
screenshots of how the component looks before and after the change. -->
  • Loading branch information
trigal2012 authored Dec 23, 2024
2 parents a6da901 + 7c23e69 commit c56f243
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions packages/db/prisma/data-migrations/2024-12-22_update-alert-link.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,51 @@
import { generateNestedFreeText } from '~db/lib/generateFreeText'
import { type MigrationJob } from '~db/prisma/dataMigrationRunner'
import { type JobDef } from '~db/prisma/jobPreRun'

/** Define the job metadata here. */
const jobDef: JobDef = {
jobId: '2024-12-22_update-alert-link',
title: 'Update alert link',
title: 'Search page alert',
createdBy: 'Diana Garbarino',
/** Optional: Longer description for the job */
description: 'This migration script updates the alert text with a new link.',
description: undefined,
}

/**
* Job export - this variable MUST be UNIQUE
*/
export const job20241222_update_alert_link = {
title: `[${jobDef.jobId}] ${jobDef.title}`,
task: async (ctx, task) => {
const { createLogger, jobPostRunner, prisma, formatMessage } = ctx
const { createLogger, downloadFromDatastore, generateId, formatMessage, jobPostRunner, prisma } = ctx
/** Create logging instance */
createLogger(task, jobDef.jobId)
const log = (...args: Parameters<typeof formatMessage>) => (task.output = formatMessage(...args))
/**
* Start defining your data migration from here.
*
* To log output, use `task.output = 'Message to log'`
*
* This will be written to `stdout` and to a log file in `/prisma/migration-logs/`
*/

// Log that the script has started
log('Starting to update the alert link.')
// Do stuff

// Define the alertId you wish to update
const alertId = 'alrt_01J1D1GAT5G5S6QNMCND5PMDAX'

// Fetch the existing alert record
const existingAlert = await prisma.locationAlert.findUnique({
where: { id: alertId },
})

if (!existingAlert) {
log(`Alert with ID ${alertId} not found.`)
return
}

// Update the 'text' field with a new link
const updatedAlert = await prisma.locationAlert.update({
where: { id: alertId },
const newAlert = await prisma.locationAlert.create({
data: {
id: alertId,
level: 'WARN_PRIMARY',
text: generateNestedFreeText({
type: 'locationAlert',
freeTextId: existingAlert.text.freeTextId, // Retain the same freeTextId to avoid changing other content
freeTextId: 'ftxt_01J1D1GVD7X1VBKZMPJ8AKYYMB',
itemId: alertId,
text: 'This <Link href="https://www.newlink.com">new anti-trans legislative risk map</Link> shows updated risk information.',
text: 'This <Link href=https://www.erininthemorning.com/p/post-election-2024-anti-trans-risk”>anti-trans legislative risk map</Link> shows the 2-year risk for anti-trans laws in all 50 states and D.C.',
}),
country: { connect: { cca2: 'US' } },
},
})

log(`Updated alert ${updatedAlert.id} with new link`)
log(`Created alert ${newAlert.id}`)

/**
* DO NOT REMOVE BELOW
Expand Down

0 comments on commit c56f243

Please sign in to comment.