-- DEBT: AEG-X-004 regression (2026-08-07) — see docs/CURRENT/CATALOGS/WBS_PROGRESS_TRACKER.csv row AEG-X-004
--   and CURRENT_ROADMAP.md "알려진 문서 정합성 문제" #2.
--
-- Symptom: 12 DbUpMigrationTests (Migration0008/0009/0010/0032) fail locally with
--   Postgres 42501 "must be owner of database kartsell_migration_test" — the `kartsell`
--   DB user can no longer DROP+CREATE that database, which the fresh/upgrade/re-run
--   rehearsal requires.
--
-- Run this as a Postgres superuser (or the role that currently owns kartsell_migration_test)
-- against the target server, NOT as the `kartsell` application user (it cannot grant itself
-- ownership of a database it does not already own).
--
-- Usage:
--   psql -h <host> -p 5432 -U <superuser> -d postgres -f scripts/dba/grant-migration-test-db-ownership.sql

ALTER DATABASE kartsell_migration_test OWNER TO kartsell;

-- If the database does not exist yet on this server, create it first, then re-run the ALTER
-- above (CREATE DATABASE already makes the creating role the owner, so the ALTER becomes a
-- no-op in that case):
--   CREATE DATABASE kartsell_migration_test OWNER kartsell;

-- Verify:
--   SELECT datname, pg_catalog.pg_get_userbyid(datdba) AS owner
--   FROM pg_database WHERE datname = 'kartsell_migration_test';
-- Expected: owner = kartsell

-- After this grant, re-run the isolated rehearsal to confirm:
--   dotnet test --filter "FullyQualifiedName~DbUpMigrationTests" -c Release
--   dotnet test --filter "FullyQualifiedName~DbUpRecoveryTests" -c Release
