test: refactor dbtestutil to record database creation (#19843)

relates to https://github.com/coder/internal/issues/927

Refactors dbtestutil to use a `Broker` struct to create test databases. Additionally uses a `coder_testing` database to record test databases that are created and when they are dropped.

This is in preparation for the PR above this in the stack which adds a "cleaner" subprocess that cleans out any databases that were left when the test process ends.
This commit is contained in:
Spike Curtis
2025-09-22 15:13:26 +04:00
committed by GitHub
parent e13fcaf865
commit 596fdcba81
3 changed files with 270 additions and 148 deletions
@@ -0,0 +1,8 @@
CREATE TABLE IF NOT EXISTS test_databases (
name text PRIMARY KEY,
created_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
dropped_at timestamp with time zone, -- null means it hasn't been dropped
process_uuid uuid NOT NULL
);
CREATE INDEX IF NOT EXISTS test_databases_process_uuid ON test_databases (process_uuid, dropped_at);