import pkg from 'pg';
const { Client } = pkg;
const client = new Client({
host: 'localhost',
port: 5433,
database: 'pg-litefarm',
user: 'postgres',
password: 'postgres',
});
// Supported ID list based on frontend saga support
const SUPPORTED_IDS = [5, 6, 8, 9, 11, 17, 18, 19, 20, 21];
console.log('Starting Cleanup of Unsupported Tasks...');
await client.connect();
// 1. Count tasks to be deleted
const countRes = await client.query(
`SELECT count(*) as count FROM task WHERE task_type_id != ALL($1::int[]) AND deleted = false`,
[SUPPORTED_IDS]
);
console.log(`Found ${countRes.rows[0].count} unsupported tasks active.`);
if (parseInt(countRes.rows[0].count) > 0) {
// 2. Soft delete them
const updateRes = await client.query(
`UPDATE task SET deleted = true WHERE task_type_id != ALL($1::int[]) AND deleted = false RETURNING task_id`,
[SUPPORTED_IDS]
);
console.log(`Successfully soft-deleted ${updateRes.rowCount} tasks.`);
} else {
console.log("No active unsupported tasks found.");
}
await client.end();