#!/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(); }