Merge branch 'main' into piyush/enterprise-license-check

This commit is contained in:
pandeymangg
2024-05-06 17:20:49 +05:30
4 changed files with 67 additions and 4 deletions

View File

@@ -0,0 +1,51 @@
// migration script to add empty strings to welcome card headline in default language, if it does not exist
// WelcomeCard.headline = {} -> WelcomeCard.headline = {"default":""}
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
async function main() {
await prisma.$transaction(
async (tx) => {
const surveys = await tx.survey.findMany({
select: {
id: true,
welcomeCard: true,
},
});
if (surveys.length === 0) {
// stop the migration if there are no surveys
console.log("Stopping migration, no surveys found");
return;
}
let count = 0;
for (const survey of surveys) {
const updatedSurvey = structuredClone(survey) as any;
if (
updatedSurvey.welcomeCard &&
updatedSurvey.welcomeCard.headline &&
Object.keys(updatedSurvey.welcomeCard.headline).length === 0
) {
updatedSurvey.welcomeCard.headline["default"] = "";
count++;
await tx.survey.update({
where: { id: survey.id },
data: { ...updatedSurvey },
});
}
}
console.log(count, "surveys transformed");
},
{
timeout: 50000,
}
);
}
main()
.catch(async (e) => {
console.error(e);
process.exit(1);
})
.finally(async () => await prisma.$disconnect());

View File

@@ -20,9 +20,10 @@ async function main() {
if (!surveys) {
// stop the migration if there are no surveys
console.log("No survey found");
return;
}
console.log("Translating surveys");
for (const survey of surveys) {
if (survey.questions.length > 0 && typeof survey.questions[0].headline === "string") {
const translatedSurvey = translateSurvey(survey, []);
@@ -34,6 +35,7 @@ async function main() {
});
}
}
console.log("Survey translation completed");
// Add language attributeClass
const environments = await tx.environment.findMany({
@@ -44,10 +46,12 @@ async function main() {
});
if (!environments) {
console.log("No environments found");
// stop the migration if there are no environments
return;
}
console.log("Adding language attribute class");
for (const environment of environments) {
const languageAttributeClass = environment.attributeClasses.find((attributeClass) => {
return attributeClass.name === "language";
@@ -82,6 +86,7 @@ async function main() {
});
}
}
console.log("Adding language attribute class finished");
},
{
timeout: 50000,

View File

@@ -55,8 +55,8 @@ export const createI18nString = (text: string | TI18nString, languages: string[]
return i18nString;
} else {
// It's a regular string, so create a new i18n object
const i18nString: any = {
["default"]: text as string, // Type assertion to assure TypeScript `text` is a string
const i18nString: TI18nString = {
["default"]: text, // Type assertion to assure TypeScript `text` is a string
};
// Initialize all provided languages with empty strings
@@ -228,6 +228,12 @@ const translateQuestion = (
languages
);
}
const range = question.range;
if (typeof range === "string") {
const parsedRange = parseInt(range);
// @ts-expect-error
clonedQuestion.range = parsedRange;
}
return ZSurveyRatingQuestion.parse(clonedQuestion);
case "fileUpload":

View File

@@ -30,7 +30,8 @@
"data-migration:mls": "ts-node ./data-migrations/20240318050527_add_languages_and_survey_languages/data-migration.ts",
"data-migration:mls-fix": "ts-node ./data-migrations/20240318050527_add_languages_and_survey_languages/data-migration-fix.ts",
"data-migration:mls-range-fix": "ts-node ./data-migrations/20240318050527_add_languages_and_survey_languages/data-migration-range-fix.ts",
"data-migration:userId": "ts-node ./data-migrations/20240408123456_userid_migration/data-migration.ts"
"data-migration:userId": "ts-node ./data-migrations/20240408123456_userid_migration/data-migration.ts",
"data-migration:mls-welcomeCard-fix": "ts-node ./data-migrations/20240318050527_add_languages_and_survey_languages/data-migration-welcomeCard-fix.ts"
},
"dependencies": {
"@prisma/client": "^5.13.0",