Skip to content

Commit

Permalink
hide location addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKarow committed Mar 11, 2024
1 parent 453ea3a commit e82245a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
62 changes: 62 additions & 0 deletions packages/db/prisma/data-migrations/2024-03-11_hide-locations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { z } from 'zod'

import { 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'
/** Define the job metadata here. */
const jobDef: JobDef = {
jobId: '2024-03-11_hide-locations',
title: 'hide locations',
createdBy: 'Joe Karow',
/** Optional: Longer description for the job */
description: undefined,
}

const DeactivateIdsSchema = z.array(z.string())
/**
* Job export - this variable MUST be UNIQUE
*/
export const job20240311_hide_locations = {
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 locations to hide from datastore`)
const hideLocationSlugs = await downloadFromDatastore(
'migrations/2024-03-11_hide-locations/hideLocations.json',
log
).then((data) => DeactivateIdsSchema.parse(data))
const hideLocations = await prisma.orgLocation.updateMany({
where: {
organization: {
slug: { in: hideLocationSlugs },
},
},
data: {
notVisitable: true,
},
})

log(`Updated ${hideLocations.count} location records`)

/**
* 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 @@ -7,4 +7,5 @@ export * from './2024-02-19_attach-orphan-text'
export * from './2024-02-20_appsheet-load/index'
export * from './2024-02-23_add-missing-website'
export * from './2024-03-08_update-alerts-and-org-urls/index'
export * from './2024-03-11_hide-locations'
// codegen:end

0 comments on commit e82245a

Please sign in to comment.