fix: Soft delete existing associations of soft deleted users

This commit is contained in:
Faruk AYDIN
2023-08-24 13:51:46 +02:00
committed by Ali BARIN
parent 129e6d60e5
commit d5e4a1b1ad

View File

@@ -0,0 +1,35 @@
import { Knex } from 'knex';
export async function up(knex: Knex): Promise<void> {
const users = await knex('users').whereNotNull('deleted_at');
const userIds = users.map((user) => user.id);
const flows = await knex('flows').whereIn('user_id', userIds);
const flowIds = flows.map((flow) => flow.id);
const executions = await knex('executions').whereIn('flow_id', flowIds);
const executionIds = executions.map((execution) => execution.id);
await knex('execution_steps').whereIn('execution_id', executionIds).update({
deleted_at: knex.fn.now(),
});
await knex('executions').whereIn('id', executionIds).update({
deleted_at: knex.fn.now(),
});
await knex('steps').whereIn('flow_id', flowIds).update({
deleted_at: knex.fn.now(),
});
await knex('flows').whereIn('id', flowIds).update({
deleted_at: knex.fn.now(),
});
await knex('connections').whereIn('user_id', userIds).update({
deleted_at: knex.fn.now(),
});
}
export async function down(): Promise<void> {
// void
}