mirror of
https://github.com/coder/coder.git
synced 2026-06-03 13:08:25 +00:00
af3ff825a1
Adds columns to track package and test name to test_databases table, and populates them as databases are created using the Broker. In order to seamlessly work with existing `coder_database` databases with the old schema, the SQL that creates the table and columns is additive and idempotent, so we run it every time we initialize the Broker (once per test binary execution). We include a transaction level advisorly lock to prevent deadlocks before attempting to alter the schema. I was seeing deadlocks without this.
19 lines
747 B
SQL
19 lines
747 B
SQL
BEGIN TRANSACTION;
|
|
SELECT pg_advisory_xact_lock(7283699);
|
|
|
|
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);
|
|
|
|
ALTER TABLE test_databases ADD COLUMN IF NOT EXISTS test_name text;
|
|
COMMENT ON COLUMN test_databases.test_name IS 'Name of the test that created the database';
|
|
ALTER TABLE test_databases ADD COLUMN IF NOT EXISTS test_package text;
|
|
COMMENT ON COLUMN test_databases.test_package IS 'Package of the test that created the database';
|
|
|
|
COMMIT;
|