-
Couldn't load subscription status.
- Fork 11.6k
Description
Laravel Version
11.34.2
PHP Version
8.3.14
Database Driver & Version
Postgres 17, using the postgres:17 docker image and psql extension from the 8.3 php docker image
Description
Using the DatabaseTruncation trait in a PostgreSQL database with multiple schemas will fail with the error relation "foo_in_other_schema" does not exist.
This is unexpected because the database connection is set to only use the public schema.
I was able to work around this issue with this code in the test which used DatabaseTruncation:
public $exceptTables = [];
protected function beforeTruncatingDatabase(): void
{
$tables = DB::select("SELECT table_name FROM information_schema.tables WHERE table_schema = 'other_schema'");
$this->exceptTables = array_map(fn($t) => $t->table_name, $tables);
}However, that resulted in the test running after the first one to fail because the old data was not properly cleaned up. The test uses RefreshDatabase. That required another workaround:
protected function beforeRefreshingDatabase()
{
$tables = DB::select("SELECT table_name, table_type FROM information_schema.tables WHERE table_schema = 'public'");
$tableList = implode(', ', array_map(fn($v) => $v->table_name, array_filter($tables, fn($v) => $v->table_type === 'BASE TABLE')));
DB::unprepared('TRUNCATE '.$tableList);
}Steps To Reproduce
Here's a repo with a minimal reproduction: https://github.com/kolaente/laravel-framework-issue-53745-reproduction
To see the error:
- clone the repo
- cd in the directory
- run
docker compose up -d - run
docker compose exec web php artisan migrateso that the tables exist - run
docker compose exec web php artisan test