The "Creating MySQL database" is logged from the \Stancl\Tenancy\TenantDatabaseManagers\MySQLDatabaseManager::createDatabase()
method:
public function createDatabase(TenantWithDatabase $tenant): bool
{
$database = $tenant->database()->getName();
$charset = $this->database()->getConfig('charset');
$collation = $this->database()->getConfig('collation');
Log::debug('Creating MySQL database');
return $this->database()->statement("CREATE DATABASE `{$database}` CHARACTER SET `$charset` COLLATE `$collation`");
}
The "New PDO Connection" is logged from the \Illuminate\Database\Connectors\Connector::createPdoConnection()
method:
protected function createPdoConnection($dsn, $username, $password, $options)
{
Log::debug('New PDO Connection', [
'dsn' => $dsn,
'username' => $username,
'password' => $password,
'options' => $options
]);
try {
return new PDO($dsn, $username, $password, $options);
} catch (\Throwable $e) {
Log::debug('Connection failed');
throw $e;
}
}
The "JOB: DeleteDatabase, DATABASE: testing_t_3fc6ae2d-296d-4d08-8098-262a1a6cefc6" is from the \Stancl\Tenancy\Jobs\DeleteDatabase::handle()
method:
public function handle()
{
event(new DeletingDatabase($this->tenant));
Log::debug("JOB: DeleteDatabase, DATABASE: {$this->tenant->tenancy_db_name}");
$this->tenant->database()->manager()->deleteDatabase($this->tenant);
event(new DatabaseDeleted($this->tenant));
}
This is a workaround for an issue with creating MySQL users/password per tenant database in tests, ideally it shouldn't have to be done this way but I have not been able to find a way to get tests to RELIABLY pass using separate users. Not being able to mimick important production pieces like this in tests is a problem, but unsure how to resolve.
See my relevant StackOverflow question here: https://stackoverflow.com/posts/77744498/edit