-
Notifications
You must be signed in to change notification settings - Fork 0
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
Refactor Cleanup class #47
Conversation
ondrajodas
commented
Feb 4, 2025
•
edited
Loading
edited
- Optimize code in Cleanup class: Add constants for frequently used strings, Simplify logic in getDataToRemove, Create switchRole method for better readability
- Add detailed logging: Info logs for main operations, Debug logs for detailed tracking
- Improve type safety: Fix type hints, Proper handling of null values
po incidentu kdy nám migrace smazala všechny usery (i ty co to smazat nemělo) jsem to přepsal tak aby to vzalo jen databázovou roli `tu najdu buď od databáze a nebo ze zadaného pole) a našlo to jen usery které ta role vlastní (WS users) + role která ta role vlastní (RO role, WS role) je to víc přímočarý a jednodušší a nemělo by se tak stt že to smaže něco co nemá... příklad výstupu:
|
dal jsem na review i TF, se kterým jsem ten tool dělal a byl i u toho incidentu :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Za mě ok, ale úplně se neorientuju, počkal bych ještě na @tomasfejfar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jako působí to, že to bude fungovat :) Akorát ten naming je teda 🙈
@@ -33,7 +37,14 @@ public function sourceAccount(): void | |||
$databaseRole = $this->sourceConnection->getOwnershipRoleOnDatabase($database); | |||
$projectUser = $this->getProjectUser($databaseRole); | |||
|
|||
$data = $this->getDataToRemove($this->sourceConnection, $databaseRole); | |||
$grantedOnDatabaseRole = $this->sourceConnection->fetchAll(sprintf( | |||
'SHOW GRANTS ON ROLE %s', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Myslel jsem, že jet o TO ROLE? ale funguje podle dokumentace oboje :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tohle teda vezme všechny granty, která má project role
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SHOW GRANTS ON ROLE KEBOOLA_123
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -33,7 +37,14 @@ public function sourceAccount(): void | |||
$databaseRole = $this->sourceConnection->getOwnershipRoleOnDatabase($database); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Owner DB je "project role".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
KEBOOLA_123
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jo je...jo je to role která vlastní databázi, ano projektová role no
'SHOW GRANTS ON ROLE %s', | ||
Helper::quoteIdentifier($databaseRole) | ||
)); | ||
assert(count($grantedOnDatabaseRole) === 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nrozumím proč je jen jeden ten grant. Může jich být imho klidně víc - třeba na ws usery, schemata, ws role, etc., ne?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jako je super, že je tu assert, ale nerozumím proč to funguje
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
funguje to protože - #47 (comment)
src/Cleanup.php
Outdated
); | ||
$this->destinationConnection->useRole($role['granted_by']); | ||
} | ||
$dataToRemove = $this->getDataToRemove($this->destinationConnection, $roleName, $mainRoleName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A co projektový user KEBOOLA_123?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jestli myslíš smazání ho tak se přidává v metodě "addProjectRoleAndUserToRemove"
src/Cleanup.php
Outdated
$sqls[] = sprintf('USE ROLE %s;', Helper::quoteIdentifier($currentRole)); | ||
// Drop users owned by roles | ||
if (!empty($dataToRemove['USER'])) { | ||
$this->logger->info(sprintf('Dropping %d users', count($dataToRemove['USER']))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tady bych zalogoval které přesně to dropuje, ne?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to samé - #47 (comment)
src/Cleanup.php
Outdated
$sqls[] = sprintf('DROP ROLE IF EXISTS %s;', Helper::quoteIdentifier($databaseRole)); | ||
// Drop roles | ||
if (!empty($dataToRemove['ROLE'])) { | ||
$this->logger->info(sprintf('Dropping %d roles', count($dataToRemove['ROLE']))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taky bych si myslel, že by tu mělo být které přesně
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no nevím jestli bych to tu měl vypsat 🤷♂️ seznam který chceme migrovat těch rolí a userů má několik stovek/tisíc
src/Cleanup.php
Outdated
@@ -297,36 +306,100 @@ public function postMigration(): void | |||
} | |||
} | |||
|
|||
private function getDataToRemove(Connection $connection, string $role): array | |||
private function getDataToRemove(Connection $connection, string $name, string $mainRoleName): array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tyjo, ten naming... $roleName, ne?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a getDataToRemoveForRole
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
naming zajišťoval cursor, tak jsem se svezl... přejmenuju
3af4bb3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Asi LGTM :)
@tomasfejfar sry ještě jednou.. on je tu dismiss když pošlu commit 🤦 |