@@ -43,6 +43,8 @@ class Version1130Date20211102154716 extends SimpleMigrationStep {
4343 private $ dbc ;
4444 /** @var LoggerInterface */
4545 private $ logger ;
46+ /** @var string[] */
47+ private $ hashColumnAddedToTables = [];
4648
4749 public function __construct (IDBConnection $ dbc , LoggerInterface $ logger ) {
4850 $ this ->dbc = $ dbc ;
@@ -89,6 +91,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
8991 'length ' => 64 ,
9092 ]);
9193 $ changeSchema = true ;
94+ $ this ->hashColumnAddedToTables [] = $ tableName ;
9295 }
9396 $ column = $ table ->getColumn ('ldap_dn ' );
9497 if ($ tableName === 'ldap_user_mapping ' ) {
@@ -109,7 +112,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
109112 $ table ->addUniqueIndex (['directory_uuid ' ], 'ldap_user_directory_uuid ' );
110113 $ changeSchema = true ;
111114 }
112- } else if (!$ schema ->hasTable ('ldap_group_mapping_backup ' )) {
115+ } elseif (!$ schema ->hasTable ('ldap_group_mapping_backup ' )) {
113116 // We need to copy the table twice to be able to change primary key, prepare the backup table
114117 $ table2 = $ schema ->createTable ('ldap_group_mapping_backup ' );
115118 $ table2 ->addColumn ('ldap_dn ' , Types::STRING , [
@@ -177,9 +180,16 @@ protected function handleDNHashes(string $table): void {
177180
178181 protected function getSelectQuery (string $ table ): IQueryBuilder {
179182 $ qb = $ this ->dbc ->getQueryBuilder ();
180- $ qb ->select ('owncloud_name ' , 'ldap_dn ' , 'ldap_dn_hash ' )
181- ->from ($ table )
182- ->where ($ qb ->expr ()->isNull ('ldap_dn_hash ' ));
183+ $ qb ->select ('owncloud_name ' , 'ldap_dn ' )
184+ ->from ($ table );
185+
186+ // when added we may run into risk that it's read from a DB node
187+ // where the column is not present. Then the where clause is also
188+ // not necessary since all rows qualify.
189+ if (!in_array ($ table , $ this ->hashColumnAddedToTables , true )) {
190+ $ qb ->where ($ qb ->expr ()->isNull ('ldap_dn_hash ' ));
191+ }
192+
183193 return $ qb ;
184194 }
185195
@@ -260,7 +270,7 @@ protected function getNextcloudIdsByUuid(string $table, string $uuid): array {
260270 * @return Generator<string>
261271 * @throws \OCP\DB\Exception
262272 */
263- protected function getDuplicatedUuids (string $ table ): Generator {
273+ protected function getDuplicatedUuids (string $ table ): Generator {
264274 $ select = $ this ->dbc ->getQueryBuilder ();
265275 $ select ->select ('directory_uuid ' )
266276 ->from ($ table )
0 commit comments