Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Make sure the tenant connection is not used for moving tables #265

Open
wants to merge 2 commits into
base: 2.x
Choose a base branch
from

Conversation

ArlonAntonius
Copy link
Member

Fixes #239

Short explanation:
In order to move the tables of the tenant to the right database (if the database was updated), we would instantiate a temporary connection on the specified TenantConnectionName. This would override the current tenant connection. Then we would empty that connection as we want to make sure we do not leave the connection open as it would form a security risk. Resulting in there not being a Tenant Connection anymore.

This fix simply uses a completely random connection name.

@codecov
Copy link

codecov bot commented Oct 30, 2022

Codecov Report

Merging #265 (f410748) into 2.x (4d06a38) will decrease coverage by 0.12%.
The diff coverage is 100.00%.

@@             Coverage Diff              @@
##                2.x     #265      +/-   ##
============================================
- Coverage     98.97%   98.84%   -0.13%     
  Complexity      290      290              
============================================
  Files            98       98              
  Lines           777      778       +1     
============================================
  Hits            769      769              
- Misses            8        9       +1     

Comment on lines +139 to +147
$tempConnectionName = Str::random(16);

/** @var ResolvesConnections $resolver */
$resolver = resolve(ResolvesConnections::class);
$resolver($tempTenant, Tenancy::getTenantConnectionName());
$resolver($tempTenant, $tempConnectionName);

$tables = Tenancy::getTenantConnection()->getDoctrineSchemaManager()->listTableNames();
$tables = DB::connection($tempConnectionName)->getDoctrineSchemaManager()->listTableNames();

$resolver(null, Tenancy::getTenantConnectionName());
$resolver(null, $tempConnectionName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please simplify this variable into $connection? It is obvious with the Str::random that this concerns a random connection name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tenant connection is set to null after tenant model is updated in the database
2 participants