feat: added timeout function to migration

This commit is contained in:
=
2025-07-23 14:31:54 +05:30
parent 53bec6bc3e
commit dfecaae560
@@ -269,7 +269,14 @@ const kickOutSshProject = async (knex: Knex, oldProjectId: string) => {
}; };
const BATCH_SIZE = 1000; const BATCH_SIZE = 1000;
const MIGRATION_TIMEOUT = 30 * 60 * 1000; // 30 minutes
export async function up(knex: Knex): Promise<void> { export async function up(knex: Knex): Promise<void> {
const result = await knex.raw("SHOW statement_timeout");
const originalTimeout = result.rows[0].statement_timeout;
try {
await knex.raw(`SET statement_timeout = ${MIGRATION_TIMEOUT}`);
const hasTemplateTypeColumn = await knex.schema.hasColumn(TableName.ProjectTemplates, "type"); const hasTemplateTypeColumn = await knex.schema.hasColumn(TableName.ProjectTemplates, "type");
if (hasTemplateTypeColumn) { if (hasTemplateTypeColumn) {
await knex(TableName.ProjectTemplates).whereNull("type").update({ await knex(TableName.ProjectTemplates).whereNull("type").update({
@@ -315,6 +322,9 @@ export async function up(knex: Knex): Promise<void> {
} }
} while (projectsToBeSplit.length > 0); } while (projectsToBeSplit.length > 0);
} }
} finally {
await knex.raw(`SET statement_timeout = '${originalTimeout}'`);
}
} }
export async function down(knex: Knex): Promise<void> { export async function down(knex: Knex): Promise<void> {