From f3b3781208e1f7f3a725b0b862c2bd7c15a5b9ea Mon Sep 17 00:00:00 2001 From: "InReach [bot]" <108850934+InReach-svc@users.noreply.github.com> Date: Wed, 29 Jan 2025 04:24:20 +0000 Subject: [PATCH] chore: lint & format Signed-off-by: InReach [bot] <108850934+InReach-svc@users.noreply.github.com> --- .../!YYYY_MM_DD_new-job-template.ts | 188 +++++++++-------- .../2025_01_28_cm2m6ae8l0000aik98z887ke6.ts | 189 +++++++++--------- .../2025_01_28_cm38fiob100004uvyp2v1yqbl.ts | 186 +++++++++-------- prisma/jobPreRun.ts | 94 +++++---- 4 files changed, 322 insertions(+), 335 deletions(-) diff --git a/prisma/data-migrations/!YYYY_MM_DD_new-job-template.ts b/prisma/data-migrations/!YYYY_MM_DD_new-job-template.ts index 8dfba0a8..5c0014b3 100644 --- a/prisma/data-migrations/!YYYY_MM_DD_new-job-template.ts +++ b/prisma/data-migrations/!YYYY_MM_DD_new-job-template.ts @@ -12,13 +12,13 @@ import { createId } from '@paralleldrive/cuid2' import { PrismaClient } from '@prisma/client' -import path from 'path'; +import path from 'path' import { type ListrJob } from '~db/dataMigrationRunner' import { type JobDef, jobPostRunner, jobPreRunner } from '~db/jobPreRun' -/** don't change this value, but DO make the filename unique **/ -const filename = path.basename(__filename, '.ts'); // Get the filename without the extension +/** Don't change this value, but DO make the filename unique * */ +const filename = path.basename(__filename, '.ts') // Get the filename without the extension /** Define the job metadata here. */ const storyId = 'cm2m6aeaa0001aik97j6vdsms' // Replace with actual ID if the story already exists in the story table @@ -27,12 +27,12 @@ const description = `update story for ${storySubmissionId}` //optional, replace const createdBy = 'Diana Garbarino' // Replace with actual user // Translated value from the new_submission file in CrowdIn - response1 -const response1ES = 'Siempre hubo algo dentro de mí que no podía alcanzar o descifrar, lo cual tiene sentido si uno lo ve en retrospectiva porque una vez que llegué a reconocer las distintas formas de identidad fuera de mi hogar, se me abrió un mundo de oportunidades. Mi perspectiva cambió y me volví mucho más optimista y, mientras me empecé a sentir más cómode, sentí esa pasión innata de ser parte de una comunidad, de algo más grande que yo misme. Allí fue cuando supe que estaba destinade a vivir mi vida de manera auténtica como un hombre trans y encontrar gente como yo, a la que pueda apoyar y acompañar y ocupar el espacio que merezco.' +const response1ES = + 'Siempre hubo algo dentro de mí que no podía alcanzar o descifrar, lo cual tiene sentido si uno lo ve en retrospectiva porque una vez que llegué a reconocer las distintas formas de identidad fuera de mi hogar, se me abrió un mundo de oportunidades. Mi perspectiva cambió y me volví mucho más optimista y, mientras me empecé a sentir más cómode, sentí esa pasión innata de ser parte de una comunidad, de algo más grande que yo misme. Allí fue cuando supe que estaba destinade a vivir mi vida de manera auténtica como un hombre trans y encontrar gente como yo, a la que pueda apoyar y acompañar y ocupar el espacio que merezco.' // Translated value from the new_submission file in CrowdIn - response2 const response2ES = 'Planned Parenthood, THEM, HRC, ACLU, etc.' - /** Nothing below this line needs to be touched. */ const jobDef: JobDef = { jobId: filename, @@ -60,7 +60,7 @@ export const jobId = { * * This ensures that jobs are only run once */ - console.log('Starting jobPreRunner...'); + console.log('Starting jobPreRunner...') if (await jobPreRunner(jobDef, task)) { return task.skip(`${jobDef.storySubmissionId} - Migration has already been run.`) } @@ -73,9 +73,9 @@ export const jobId = { } // Get the StorySubmission entry by ID - console.log('Fetching StorySubmission for ID:', storySubmissionId); + console.log('Fetching StorySubmission for ID:', storySubmissionId) const prisma = new PrismaClient() // Fresh Prisma client instance - let storySubmission = null; + let storySubmission = null try { storySubmission = await prisma.storySubmission.findUnique({ @@ -107,94 +107,93 @@ export const jobId = { console.log('response1EN:', response1EN) console.log('response2EN:', response2EN) -// Get Pronouns only if pronounValues is not empty -let pronouns = [] - -if (pronounValues.length > 0) { - try { - pronouns = await prisma.pronouns.findMany({ - where: { tag: { in: pronounValues } }, - }) - console.log('Found pronouns:', pronouns) // Log the pronouns after the query - } catch (error) { - console.error('Error fetching pronouns:', error) - } -} else { - console.log('No pronouns to search for (pronounValues is empty).') -} + // Get Pronouns only if pronounValues is not empty + let pronouns = [] + + if (pronounValues.length > 0) { + try { + pronouns = await prisma.pronouns.findMany({ + where: { tag: { in: pronounValues } }, + }) + console.log('Found pronouns:', pronouns) // Log the pronouns after the query + } catch (error) { + console.error('Error fetching pronouns:', error) + } + } else { + console.log('No pronouns to search for (pronounValues is empty).') + } -// If no pronouns were found, log a message -if (pronouns.length === 0 && pronounValues.length > 0) { - console.log(`No matching Pronouns found for values '${pronounValues.join(', ')}'.`) - return -} + // If no pronouns were found, log a message + if (pronouns.length === 0 && pronounValues.length > 0) { + console.log(`No matching Pronouns found for values '${pronounValues.join(', ')}'.`) + return + } // If updating an existing story -if (storyId) { - // Log before updating the story - console.log('Updating story with the following data:'); - console.log(`Story ID: ${storyId}`); - console.log(`Response1ES: ${response1ES}`); - console.log(`Response2ES: ${response2ES}`); - console.log(`Categories: ${JSON.stringify(categories)}`); - const pronounIds = pronouns.map((pronoun) => pronoun.id); -console.log('Resolved Pronoun IDs:', pronounIds); // Log only IDs - - try { - // Update the existing story - await prisma.story.update({ - where: { id: storyId }, - data: { - response1ES, - response2ES, - }, - }); - - console.log(`Story with ID '${storyId}' updated successfully.`); - } catch (error) { - console.error('Error updating story:', error); - } -} else { - // Create a new story - const newStoryId = createId(); - - // Log before creating the new story - console.log('Creating new story with the following data:'); - console.log(`New Story ID: ${newStoryId}`); - console.log(`Name: ${responses.q4}`); - console.log(`Response1EN: ${response1EN}`); - console.log(`Response2EN: ${response2EN}`); - console.log(`Categories: ${JSON.stringify(categories)}`); - const pronounIds = pronouns.map((pronoun) => pronoun.id); -console.log('Resolved Pronoun IDs:', pronounIds); // Log only IDs - - try { - await prisma.story.create({ - data: { - id: newStoryId, - name: responses.q4, // Use q4 for the story name - response1EN, - response2EN, - published: true, - categories: { - create: categories.map((tag: string) => ({ - category: { connect: { tag } }, - })), - }, - pronouns: { - create: pronounIds.map((id) => ({ - pronoun: { connect: { id } }, - })), - }, - }, - }); - - console.log(`New story created with ID '${newStoryId}'.`); - } catch (error) { - console.error('Error creating new story:', error); - } -} - + if (storyId) { + // Log before updating the story + console.log('Updating story with the following data:') + console.log(`Story ID: ${storyId}`) + console.log(`Response1ES: ${response1ES}`) + console.log(`Response2ES: ${response2ES}`) + console.log(`Categories: ${JSON.stringify(categories)}`) + const pronounIds = pronouns.map((pronoun) => pronoun.id) + console.log('Resolved Pronoun IDs:', pronounIds) // Log only IDs + + try { + // Update the existing story + await prisma.story.update({ + where: { id: storyId }, + data: { + response1ES, + response2ES, + }, + }) + + console.log(`Story with ID '${storyId}' updated successfully.`) + } catch (error) { + console.error('Error updating story:', error) + } + } else { + // Create a new story + const newStoryId = createId() + + // Log before creating the new story + console.log('Creating new story with the following data:') + console.log(`New Story ID: ${newStoryId}`) + console.log(`Name: ${responses.q4}`) + console.log(`Response1EN: ${response1EN}`) + console.log(`Response2EN: ${response2EN}`) + console.log(`Categories: ${JSON.stringify(categories)}`) + const pronounIds = pronouns.map((pronoun) => pronoun.id) + console.log('Resolved Pronoun IDs:', pronounIds) // Log only IDs + + try { + await prisma.story.create({ + data: { + id: newStoryId, + name: responses.q4, // Use q4 for the story name + response1EN, + response2EN, + published: true, + categories: { + create: categories.map((tag: string) => ({ + category: { connect: { tag } }, + })), + }, + pronouns: { + create: pronounIds.map((id) => ({ + pronoun: { connect: { id } }, + })), + }, + }, + }) + + console.log(`New story created with ID '${newStoryId}'.`) + } catch (error) { + console.error('Error creating new story:', error) + } + } /** * DO NOT REMOVE BELOW @@ -202,7 +201,6 @@ console.log('Resolved Pronoun IDs:', pronounIds); // Log only IDs * This writes a record to the DB to register that this migration has run successfully. */ await jobPostRunner(jobDef, prisma) - await prisma.$disconnect(); // Disconnect when you're truly done - + await prisma.$disconnect() // Disconnect when you're truly done }, } satisfies ListrJob diff --git a/prisma/data-migrations/2025_01_28_cm2m6ae8l0000aik98z887ke6.ts b/prisma/data-migrations/2025_01_28_cm2m6ae8l0000aik98z887ke6.ts index 399a5370..5c0014b3 100644 --- a/prisma/data-migrations/2025_01_28_cm2m6ae8l0000aik98z887ke6.ts +++ b/prisma/data-migrations/2025_01_28_cm2m6ae8l0000aik98z887ke6.ts @@ -9,17 +9,16 @@ // save the file, push changes to github, then create a PR // create a migration file for each story to be added or updated - import { createId } from '@paralleldrive/cuid2' import { PrismaClient } from '@prisma/client' -import path from 'path'; +import path from 'path' import { type ListrJob } from '~db/dataMigrationRunner' import { type JobDef, jobPostRunner, jobPreRunner } from '~db/jobPreRun' -/** don't change this value, but DO make the filename unique **/ -const filename = path.basename(__filename, '.ts'); // Get the filename without the extension +/** Don't change this value, but DO make the filename unique * */ +const filename = path.basename(__filename, '.ts') // Get the filename without the extension /** Define the job metadata here. */ const storyId = 'cm2m6aeaa0001aik97j6vdsms' // Replace with actual ID if the story already exists in the story table @@ -28,12 +27,12 @@ const description = `update story for ${storySubmissionId}` //optional, replace const createdBy = 'Diana Garbarino' // Replace with actual user // Translated value from the new_submission file in CrowdIn - response1 -const response1ES = 'Siempre hubo algo dentro de mí que no podía alcanzar o descifrar, lo cual tiene sentido si uno lo ve en retrospectiva porque una vez que llegué a reconocer las distintas formas de identidad fuera de mi hogar, se me abrió un mundo de oportunidades. Mi perspectiva cambió y me volví mucho más optimista y, mientras me empecé a sentir más cómode, sentí esa pasión innata de ser parte de una comunidad, de algo más grande que yo misme. Allí fue cuando supe que estaba destinade a vivir mi vida de manera auténtica como un hombre trans y encontrar gente como yo, a la que pueda apoyar y acompañar y ocupar el espacio que merezco.' +const response1ES = + 'Siempre hubo algo dentro de mí que no podía alcanzar o descifrar, lo cual tiene sentido si uno lo ve en retrospectiva porque una vez que llegué a reconocer las distintas formas de identidad fuera de mi hogar, se me abrió un mundo de oportunidades. Mi perspectiva cambió y me volví mucho más optimista y, mientras me empecé a sentir más cómode, sentí esa pasión innata de ser parte de una comunidad, de algo más grande que yo misme. Allí fue cuando supe que estaba destinade a vivir mi vida de manera auténtica como un hombre trans y encontrar gente como yo, a la que pueda apoyar y acompañar y ocupar el espacio que merezco.' // Translated value from the new_submission file in CrowdIn - response2 const response2ES = 'Planned Parenthood, THEM, HRC, ACLU, etc.' - /** Nothing below this line needs to be touched. */ const jobDef: JobDef = { jobId: filename, @@ -61,7 +60,7 @@ export const jobId = { * * This ensures that jobs are only run once */ - console.log('Starting jobPreRunner...'); + console.log('Starting jobPreRunner...') if (await jobPreRunner(jobDef, task)) { return task.skip(`${jobDef.storySubmissionId} - Migration has already been run.`) } @@ -74,9 +73,9 @@ export const jobId = { } // Get the StorySubmission entry by ID - console.log('Fetching StorySubmission for ID:', storySubmissionId); + console.log('Fetching StorySubmission for ID:', storySubmissionId) const prisma = new PrismaClient() // Fresh Prisma client instance - let storySubmission = null; + let storySubmission = null try { storySubmission = await prisma.storySubmission.findUnique({ @@ -108,94 +107,93 @@ export const jobId = { console.log('response1EN:', response1EN) console.log('response2EN:', response2EN) -// Get Pronouns only if pronounValues is not empty -let pronouns = [] - -if (pronounValues.length > 0) { - try { - pronouns = await prisma.pronouns.findMany({ - where: { tag: { in: pronounValues } }, - }) - console.log('Found pronouns:', pronouns) // Log the pronouns after the query - } catch (error) { - console.error('Error fetching pronouns:', error) - } -} else { - console.log('No pronouns to search for (pronounValues is empty).') -} + // Get Pronouns only if pronounValues is not empty + let pronouns = [] + + if (pronounValues.length > 0) { + try { + pronouns = await prisma.pronouns.findMany({ + where: { tag: { in: pronounValues } }, + }) + console.log('Found pronouns:', pronouns) // Log the pronouns after the query + } catch (error) { + console.error('Error fetching pronouns:', error) + } + } else { + console.log('No pronouns to search for (pronounValues is empty).') + } -// If no pronouns were found, log a message -if (pronouns.length === 0 && pronounValues.length > 0) { - console.log(`No matching Pronouns found for values '${pronounValues.join(', ')}'.`) - return -} + // If no pronouns were found, log a message + if (pronouns.length === 0 && pronounValues.length > 0) { + console.log(`No matching Pronouns found for values '${pronounValues.join(', ')}'.`) + return + } // If updating an existing story -if (storyId) { - // Log before updating the story - console.log('Updating story with the following data:'); - console.log(`Story ID: ${storyId}`); - console.log(`Response1ES: ${response1ES}`); - console.log(`Response2ES: ${response2ES}`); - console.log(`Categories: ${JSON.stringify(categories)}`); - const pronounIds = pronouns.map((pronoun) => pronoun.id); -console.log('Resolved Pronoun IDs:', pronounIds); // Log only IDs - - try { - // Update the existing story - await prisma.story.update({ - where: { id: storyId }, - data: { - response1ES, - response2ES, - }, - }); - - console.log(`Story with ID '${storyId}' updated successfully.`); - } catch (error) { - console.error('Error updating story:', error); - } -} else { - // Create a new story - const newStoryId = createId(); - - // Log before creating the new story - console.log('Creating new story with the following data:'); - console.log(`New Story ID: ${newStoryId}`); - console.log(`Name: ${responses.q4}`); - console.log(`Response1EN: ${response1EN}`); - console.log(`Response2EN: ${response2EN}`); - console.log(`Categories: ${JSON.stringify(categories)}`); - const pronounIds = pronouns.map((pronoun) => pronoun.id); -console.log('Resolved Pronoun IDs:', pronounIds); // Log only IDs - - try { - await prisma.story.create({ - data: { - id: newStoryId, - name: responses.q4, // Use q4 for the story name - response1EN, - response2EN, - published: true, - categories: { - create: categories.map((tag: string) => ({ - category: { connect: { tag } }, - })), - }, - pronouns: { - create: pronounIds.map((id) => ({ - pronoun: { connect: { id } }, - })), - }, - }, - }); - - console.log(`New story created with ID '${newStoryId}'.`); - } catch (error) { - console.error('Error creating new story:', error); - } -} - + if (storyId) { + // Log before updating the story + console.log('Updating story with the following data:') + console.log(`Story ID: ${storyId}`) + console.log(`Response1ES: ${response1ES}`) + console.log(`Response2ES: ${response2ES}`) + console.log(`Categories: ${JSON.stringify(categories)}`) + const pronounIds = pronouns.map((pronoun) => pronoun.id) + console.log('Resolved Pronoun IDs:', pronounIds) // Log only IDs + + try { + // Update the existing story + await prisma.story.update({ + where: { id: storyId }, + data: { + response1ES, + response2ES, + }, + }) + + console.log(`Story with ID '${storyId}' updated successfully.`) + } catch (error) { + console.error('Error updating story:', error) + } + } else { + // Create a new story + const newStoryId = createId() + + // Log before creating the new story + console.log('Creating new story with the following data:') + console.log(`New Story ID: ${newStoryId}`) + console.log(`Name: ${responses.q4}`) + console.log(`Response1EN: ${response1EN}`) + console.log(`Response2EN: ${response2EN}`) + console.log(`Categories: ${JSON.stringify(categories)}`) + const pronounIds = pronouns.map((pronoun) => pronoun.id) + console.log('Resolved Pronoun IDs:', pronounIds) // Log only IDs + + try { + await prisma.story.create({ + data: { + id: newStoryId, + name: responses.q4, // Use q4 for the story name + response1EN, + response2EN, + published: true, + categories: { + create: categories.map((tag: string) => ({ + category: { connect: { tag } }, + })), + }, + pronouns: { + create: pronounIds.map((id) => ({ + pronoun: { connect: { id } }, + })), + }, + }, + }) + + console.log(`New story created with ID '${newStoryId}'.`) + } catch (error) { + console.error('Error creating new story:', error) + } + } /** * DO NOT REMOVE BELOW @@ -203,7 +201,6 @@ console.log('Resolved Pronoun IDs:', pronounIds); // Log only IDs * This writes a record to the DB to register that this migration has run successfully. */ await jobPostRunner(jobDef, prisma) - await prisma.$disconnect(); // Disconnect when you're truly done - + await prisma.$disconnect() // Disconnect when you're truly done }, } satisfies ListrJob diff --git a/prisma/data-migrations/2025_01_28_cm38fiob100004uvyp2v1yqbl.ts b/prisma/data-migrations/2025_01_28_cm38fiob100004uvyp2v1yqbl.ts index f270c2bb..23deb6a0 100644 --- a/prisma/data-migrations/2025_01_28_cm38fiob100004uvyp2v1yqbl.ts +++ b/prisma/data-migrations/2025_01_28_cm38fiob100004uvyp2v1yqbl.ts @@ -9,17 +9,16 @@ // save the file, push changes to github, then create a PR // create a migration file for each story to be added or updated - import { createId } from '@paralleldrive/cuid2' import { PrismaClient } from '@prisma/client' -import path from 'path'; +import path from 'path' import { type ListrJob } from '~db/dataMigrationRunner' import { type JobDef, jobPostRunner, jobPreRunner } from '~db/jobPreRun' -/** don't change this value, but DO make the filename unique **/ -const filename = path.basename(__filename, '.ts'); // Get the filename without the extension +/** Don't change this value, but DO make the filename unique * */ +const filename = path.basename(__filename, '.ts') // Get the filename without the extension /** Define the job metadata here. */ const storyId = 'cm38fiobr00014uvyzvrlr5nu' // Replace with actual ID if the story already exists in the story table @@ -44,7 +43,6 @@ Si la comunidad en persona no es viable o segura (por razones de discapacidad, r El armario puede ser más seguro, pero eso no evita que sea traicioneramente solitario al mismo tiempo. Encontrar una comunidad en línea puede ser como tener un pequeño trozo de Narnia al que escapar mientras nos sentamos entre las bolas de naftalina y el polvo que pasan sus días en el armario con nosotros. ` - /** Nothing below this line needs to be touched. */ const jobDef: JobDef = { jobId: filename, @@ -72,7 +70,7 @@ export const jobId = { * * This ensures that jobs are only run once */ - console.log('Starting jobPreRunner...'); + console.log('Starting jobPreRunner...') if (await jobPreRunner(jobDef, task)) { return task.skip(`${jobDef.storySubmissionId} - Migration has already been run.`) } @@ -85,9 +83,9 @@ export const jobId = { } // Get the StorySubmission entry by ID - console.log('Fetching StorySubmission for ID:', storySubmissionId); + console.log('Fetching StorySubmission for ID:', storySubmissionId) const prisma = new PrismaClient() // Fresh Prisma client instance - let storySubmission = null; + let storySubmission = null try { storySubmission = await prisma.storySubmission.findUnique({ @@ -119,94 +117,93 @@ export const jobId = { console.log('response1EN:', response1EN) console.log('response2EN:', response2EN) -// Get Pronouns only if pronounValues is not empty -let pronouns = [] - -if (pronounValues.length > 0) { - try { - pronouns = await prisma.pronouns.findMany({ - where: { tag: { in: pronounValues } }, - }) - console.log('Found pronouns:', pronouns) // Log the pronouns after the query - } catch (error) { - console.error('Error fetching pronouns:', error) - } -} else { - console.log('No pronouns to search for (pronounValues is empty).') -} + // Get Pronouns only if pronounValues is not empty + let pronouns = [] + + if (pronounValues.length > 0) { + try { + pronouns = await prisma.pronouns.findMany({ + where: { tag: { in: pronounValues } }, + }) + console.log('Found pronouns:', pronouns) // Log the pronouns after the query + } catch (error) { + console.error('Error fetching pronouns:', error) + } + } else { + console.log('No pronouns to search for (pronounValues is empty).') + } -// If no pronouns were found, log a message -if (pronouns.length === 0 && pronounValues.length > 0) { - console.log(`No matching Pronouns found for values '${pronounValues.join(', ')}'.`) - return -} + // If no pronouns were found, log a message + if (pronouns.length === 0 && pronounValues.length > 0) { + console.log(`No matching Pronouns found for values '${pronounValues.join(', ')}'.`) + return + } // If updating an existing story -if (storyId) { - // Log before updating the story - console.log('Updating story with the following data:'); - console.log(`Story ID: ${storyId}`); - console.log(`Response1ES: ${response1ES}`); - console.log(`Response2ES: ${response2ES}`); - console.log(`Categories: ${JSON.stringify(categories)}`); - const pronounIds = pronouns.map((pronoun) => pronoun.id); -console.log('Resolved Pronoun IDs:', pronounIds); // Log only IDs - - try { - // Update the existing story - await prisma.story.update({ - where: { id: storyId }, - data: { - response1ES, - response2ES, - }, - }); - - console.log(`Story with ID '${storyId}' updated successfully.`); - } catch (error) { - console.error('Error updating story:', error); - } -} else { - // Create a new story - const newStoryId = createId(); - - // Log before creating the new story - console.log('Creating new story with the following data:'); - console.log(`New Story ID: ${newStoryId}`); - console.log(`Name: ${responses.q4}`); - console.log(`Response1EN: ${response1EN}`); - console.log(`Response2EN: ${response2EN}`); - console.log(`Categories: ${JSON.stringify(categories)}`); - const pronounIds = pronouns.map((pronoun) => pronoun.id); -console.log('Resolved Pronoun IDs:', pronounIds); // Log only IDs - - try { - await prisma.story.create({ - data: { - id: newStoryId, - name: responses.q4, // Use q4 for the story name - response1EN, - response2EN, - published: true, - categories: { - create: categories.map((tag: string) => ({ - category: { connect: { tag } }, - })), - }, - pronouns: { - create: pronounIds.map((id) => ({ - pronoun: { connect: { id } }, - })), - }, - }, - }); - - console.log(`New story created with ID '${newStoryId}'.`); - } catch (error) { - console.error('Error creating new story:', error); - } -} - + if (storyId) { + // Log before updating the story + console.log('Updating story with the following data:') + console.log(`Story ID: ${storyId}`) + console.log(`Response1ES: ${response1ES}`) + console.log(`Response2ES: ${response2ES}`) + console.log(`Categories: ${JSON.stringify(categories)}`) + const pronounIds = pronouns.map((pronoun) => pronoun.id) + console.log('Resolved Pronoun IDs:', pronounIds) // Log only IDs + + try { + // Update the existing story + await prisma.story.update({ + where: { id: storyId }, + data: { + response1ES, + response2ES, + }, + }) + + console.log(`Story with ID '${storyId}' updated successfully.`) + } catch (error) { + console.error('Error updating story:', error) + } + } else { + // Create a new story + const newStoryId = createId() + + // Log before creating the new story + console.log('Creating new story with the following data:') + console.log(`New Story ID: ${newStoryId}`) + console.log(`Name: ${responses.q4}`) + console.log(`Response1EN: ${response1EN}`) + console.log(`Response2EN: ${response2EN}`) + console.log(`Categories: ${JSON.stringify(categories)}`) + const pronounIds = pronouns.map((pronoun) => pronoun.id) + console.log('Resolved Pronoun IDs:', pronounIds) // Log only IDs + + try { + await prisma.story.create({ + data: { + id: newStoryId, + name: responses.q4, // Use q4 for the story name + response1EN, + response2EN, + published: true, + categories: { + create: categories.map((tag: string) => ({ + category: { connect: { tag } }, + })), + }, + pronouns: { + create: pronounIds.map((id) => ({ + pronoun: { connect: { id } }, + })), + }, + }, + }) + + console.log(`New story created with ID '${newStoryId}'.`) + } catch (error) { + console.error('Error creating new story:', error) + } + } /** * DO NOT REMOVE BELOW @@ -214,7 +211,6 @@ console.log('Resolved Pronoun IDs:', pronounIds); // Log only IDs * This writes a record to the DB to register that this migration has run successfully. */ await jobPostRunner(jobDef, prisma) - await prisma.$disconnect(); // Disconnect when you're truly done - + await prisma.$disconnect() // Disconnect when you're truly done }, } satisfies ListrJob diff --git a/prisma/jobPreRun.ts b/prisma/jobPreRun.ts index 584d0f47..d2d63801 100644 --- a/prisma/jobPreRun.ts +++ b/prisma/jobPreRun.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ -import { PrismaClient } from '@prisma/client'; +import { PrismaClient } from '@prisma/client' import { ListrTaskEventType } from 'listr2' import { DateTime } from 'luxon' @@ -9,8 +9,7 @@ import path from 'path' import { type PassedTask } from './dataMigrationRunner' // import { prisma } from '~db/client' -const prisma = new PrismaClient(); - +const prisma = new PrismaClient() const getTimestamp = () => DateTime.now().toLocaleString(DateTime.TIME_24_WITH_SECONDS).replaceAll(':', '.') @@ -22,7 +21,7 @@ const logFile = (file: string, output: string) => { } export const createLogger = (task: PassedTask, jobId: string) => { - console.log('create logger'); + console.log('create logger') const timestamp = getTimestamp() const logFilename = `${jobId}_${timestamp}.log` task.task.on(ListrTaskEventType.OUTPUT, (output: string) => logFile(logFilename, output)) @@ -30,71 +29,68 @@ export const createLogger = (task: PassedTask, jobId: string) => { // Database connection test function const testDatabaseConnection = async () => { - try { - // Log the database connection string (excluding sensitive parts) - const connectionString = process.env.POSTGRES_PRISMA_URL; - - console.log('Testing database connection with connection string:', connectionString); - - await prisma.$queryRaw`SELECT 1` - console.log('Database connection successful') - } catch (err) { - console.error('Error connecting to the database:', err) - console.error('Error details:', JSON.stringify(err, null, 2)); // Detailed error log - throw new Error('Database connection failed') - } + try { + // Log the database connection string (excluding sensitive parts) + const connectionString = process.env.POSTGRES_PRISMA_URL + + console.log('Testing database connection with connection string:', connectionString) + + await prisma.$queryRaw`SELECT 1` + console.log('Database connection successful') + } catch (err) { + console.error('Error connecting to the database:', err) + console.error('Error details:', JSON.stringify(err, null, 2)) // Detailed error log + throw new Error('Database connection failed') + } } - export const jobPreRunner = async (jobDef: JobDef, task: PassedTask) => { try { - await testDatabaseConnection() + await testDatabaseConnection() - console.log('Checking if migration has already been run for jobId:', jobDef.jobId) // Log the jobId + console.log('Checking if migration has already been run for jobId:', jobDef.jobId) // Log the jobId const exists = await prisma.dataMigration.findUnique({ - where: { jobId: String(jobDef.jobId) }, // Ensure jobId is a string - select: { id: true }, - }) + where: { jobId: String(jobDef.jobId) }, // Ensure jobId is a string + select: { id: true }, + }) - if (exists?.id) { - console.log('Migration already exists with id:', exists.id) // Log the id if found - return true - } + if (exists?.id) { + console.log('Migration already exists with id:', exists.id) // Log the id if found + return true + } createLogger(task, jobDef.jobId) console.log(jobDef.jobId) - console.log('Migration not found. Proceeding with job.') - return false - } catch (err) { + console.log('Migration not found. Proceeding with job.') + return false + } catch (err) { console.error('Error in jobPreRunner:', err) // Log any error during the execution throw new Error('Error occurred in jobPreRunner, migration skipped.') - } + } } - export const jobPostRunner = async (jobDef: JobDef, prisma: PrismaClient) => { try { - // Construct the job ID correctly - const { jobId,title, createdBy, description } = jobDef; + // Construct the job ID correctly + const { jobId, title, createdBy, description } = jobDef - // Create the dataMigration entry with required fields - await prisma.dataMigration.create({ - data: { - jobId, + // Create the dataMigration entry with required fields + await prisma.dataMigration.create({ + data: { + jobId, title, description, - createdBy, - }, - }); - - console.log(`Job '${jobId}' recorded successfully.`); - - } catch (err) { - console.error('Error in jobPostRunner:', err); - throw err; - } -}; + createdBy, + }, + }) + + console.log(`Job '${jobId}' recorded successfully.`) + } catch (err) { + console.error('Error in jobPostRunner:', err) + throw err + } +} export interface JobDef { jobId: string