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

[stable23] be conservative when reading from fresh created column #31442

Merged
merged 2 commits into from
Mar 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions apps/user_ldap/lib/Migration/Version1130Date20211102154716.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class Version1130Date20211102154716 extends SimpleMigrationStep {
private $dbc;
/** @var LoggerInterface */
private $logger;
/** @var string[] */
private $hashColumnAddedToTables = [];

public function __construct(IDBConnection $dbc, LoggerInterface $logger) {
$this->dbc = $dbc;
Expand Down Expand Up @@ -89,6 +91,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
'length' => 64,
]);
$changeSchema = true;
$this->hashColumnAddedToTables[] = $tableName;
}
$column = $table->getColumn('ldap_dn');
if ($tableName === 'ldap_user_mapping') {
Expand All @@ -109,7 +112,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
$table->addUniqueIndex(['directory_uuid'], 'ldap_user_directory_uuid');
$changeSchema = true;
}
} else if (!$schema->hasTable('ldap_group_mapping_backup')) {
} elseif (!$schema->hasTable('ldap_group_mapping_backup')) {
// We need to copy the table twice to be able to change primary key, prepare the backup table
$table2 = $schema->createTable('ldap_group_mapping_backup');
$table2->addColumn('ldap_dn', Types::STRING, [
Expand Down Expand Up @@ -177,9 +180,16 @@ protected function handleDNHashes(string $table): void {

protected function getSelectQuery(string $table): IQueryBuilder {
$qb = $this->dbc->getQueryBuilder();
$qb->select('owncloud_name', 'ldap_dn', 'ldap_dn_hash')
->from($table)
->where($qb->expr()->isNull('ldap_dn_hash'));
$qb->select('owncloud_name', 'ldap_dn')
->from($table);

// when added we may run into risk that it's read from a DB node
// where the column is not present. Then the where clause is also
// not necessary since all rows qualify.
if (!in_array($table, $this->hashColumnAddedToTables, true)) {
$qb->where($qb->expr()->isNull('ldap_dn_hash'));
}

return $qb;
}

Expand Down Expand Up @@ -260,7 +270,7 @@ protected function getNextcloudIdsByUuid(string $table, string $uuid): array {
* @return Generator<string>
* @throws \OCP\DB\Exception
*/
protected function getDuplicatedUuids(string $table): Generator{
protected function getDuplicatedUuids(string $table): Generator {
$select = $this->dbc->getQueryBuilder();
$select->select('directory_uuid')
->from($table)
Expand Down