integratedhub/tests/integration/cleanup-auth-callback-records.ts
2026-02-14 02:20:19 +00:00

50 lines
1.0 KiB
TypeScript
Executable File

#!/usr/bin/env -S deno run -A
import { load } from "$std/dotenv/mod.ts";
import { Pool } from "pg";
await load({ export: true, allowEmptyValues: true });
const connectionString = Deno.env.get("POSTGRES_OPTIONS")?.replace(
"postgresql://",
"postgres://",
);
if (!connectionString) {
Deno.exit(0);
}
const pool = new Pool({ connectionString });
const client = await pool.connect();
try {
await client.query("BEGIN");
await client.query(`
DELETE FROM public.state_keys
WHERE state_id IN (
SELECT state_id
FROM public.user_tokens
WHERE user_id LIKE 'oauth-regression-%'
)
`);
await client.query(`
DELETE FROM public.user_tokens
WHERE user_id LIKE 'oauth-regression-%'
`);
await client.query(`
DELETE FROM public.users
WHERE id LIKE 'oauth-regression-%'
`);
await client.query("COMMIT");
} catch (error) {
await client.query("ROLLBACK");
console.error("Failed to clean integration test records:", error);
Deno.exit(1);
} finally {
client.release();
await pool.end();
}