Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: alert messages #939

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const getAlerts = async ({ input }: TRPCHandlerParams<TGetAlertsSchema>)
select: {
supplement: {
select: { text: { select: { tsKey: { select: { key: true, ns: true, text: true } } } } },
where: { active: true },
},
attribute: { select: { tag: true, icon: true } },
},
Expand Down
77 changes: 77 additions & 0 deletions packages/db/prisma/data-migrations/2023-12-05_alert-messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { type Prisma, prisma } from '~db/client'
import { downloadFromDatastore, formatMessage } from '~db/prisma/common'
import { type MigrationJob } from '~db/prisma/dataMigrationRunner'
import { createLogger, type JobDef, jobPostRunner } from '~db/prisma/jobPreRun'

type Data = {
translationKey: Prisma.TranslationKeyCreateManyInput[]
freeText: Prisma.FreeTextCreateManyInput[]
organizationAttribute: Prisma.OrganizationAttributeCreateManyInput[]
attributeSupplement: Prisma.AttributeSupplementCreateManyInput[]
deactivateOld: Prisma.AttributeSupplementUpdateManyArgs
reactivateAttrib: Prisma.OrganizationAttributeUpdateManyArgs
}

/** Define the job metadata here. */
const jobDef: JobDef = {
jobId: '2023-12-05_alert-messages',
title: 'alert messages',
createdBy: 'Joe Karow',
/** Optional: Longer description for the job */
description: undefined,
}
/**
* Job export - this variable MUST be UNIQUE
*/
export const job20231205_alert_messages = {
title: `[${jobDef.jobId}] ${jobDef.title}`,
task: async (_ctx, task) => {
/** 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/`
*/

// Do stuff
log(`Downloading data from datastore`)
const data = (await downloadFromDatastore(`migrations/${jobDef.jobId}/data.json`, log)) as Data
const translationKey = await prisma.translationKey.createMany({
data: data.translationKey,
skipDuplicates: true,
})
log(`Created ${translationKey.count} translation keys`)
const freeText = await prisma.freeText.createMany({
data: data.freeText,
skipDuplicates: true,
})
log(`Created ${freeText.count} freetext records`)
const organizationAttribute = await prisma.organizationAttribute.createMany({
data: data.organizationAttribute,
skipDuplicates: true,
})
log(`Created ${organizationAttribute.count} organization attribute records`)
const attributeSupplements = await prisma.attributeSupplement.createMany({
data: data.attributeSupplement,
skipDuplicates: true,
})
log(`Created ${attributeSupplements.count} attribute supplement records`)

const deactivatedAlerts = await prisma.attributeSupplement.updateMany(data.deactivateOld)
log(`Deactivated alerts: ${deactivatedAlerts.count}`)

const reactivatedAttrib = await prisma.organizationAttribute.updateMany(data.reactivateAttrib)
log(`Reactivated attributes: ${reactivatedAttrib.count}`)
/**
* DO NOT REMOVE BELOW
*
* This writes a record to the DB to register that this migration has run successfully.
*/
await jobPostRunner(jobDef)
},
def: jobDef,
} satisfies MigrationJob
1 change: 1 addition & 0 deletions packages/db/prisma/data-migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ export * from './2023-11-20_fix-listing'
export * from './2023-11-21_add-missing-phones/index'
export * from './2023-11-22_ad-hoc-updates/index'
export * from './2023-11-22_update-alert-messages/index'
export * from './2023-12-05_alert-messages'
// codegen:end
Loading