3636use Doctrine \DBAL \Platforms \PostgreSQL94Platform ;
3737use OC \DB \Connection ;
3838use OC \DB \SchemaWrapper ;
39- use OC \Core \Command \Db \DryRunConnectionDecorator ;
4039use OCP \IDBConnection ;
4140use Symfony \Component \Console \Command \Command ;
4241use Symfony \Component \Console \Input \InputOption ;
@@ -58,17 +57,13 @@ class AddMissingIndices extends Command {
5857 /** @var Connection */
5958 private $ connection ;
6059
61- /** @var Connection */
62- private $ wrapperConnection ;
63-
6460 /** @var EventDispatcherInterface */
6561 private $ dispatcher ;
6662
6763 public function __construct (Connection $ connection , EventDispatcherInterface $ dispatcher ) {
6864 parent ::__construct ();
6965
7066 $ this ->connection = $ connection ;
71- $ this ->wrapperConnection = $ connection ;
7267 $ this ->dispatcher = $ dispatcher ;
7368 }
7469
@@ -80,11 +75,7 @@ protected function configure() {
8075 }
8176
8277 protected function execute (InputInterface $ input , OutputInterface $ output ): int {
83- if ($ input ->getOption ('dry-run ' )) {
84- $ this ->connection = new DryRunConnectionDecorator ($ this ->connection , $ output );
85- }
86-
87- $ this ->addCoreIndexes ($ output );
78+ $ this ->addCoreIndexes ($ output , $ input ->getOption ('dry-run ' ));
8879
8980 // Dispatch event so apps can also update indexes if needed
9081 $ event = new GenericEvent ($ output );
@@ -96,44 +87,57 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9687 * add missing indices to the share table
9788 *
9889 * @param OutputInterface $output
90+ * @param bool $dryRun If true, will return the sql queries instead of running them.
9991 * @throws \Doctrine\DBAL\Schema\SchemaException
10092 */
101- private function addCoreIndexes (OutputInterface $ output ) {
93+ private function addCoreIndexes (OutputInterface $ output, bool $ dryRun ) {
10294 $ output ->writeln ('<info>Check indices of the share table.</info> ' );
10395
104- $ schema = new SchemaWrapper ($ this ->wrapperConnection );
96+ $ schema = new SchemaWrapper ($ this ->connection );
10597 $ updated = false ;
10698
10799 if ($ schema ->hasTable ('share ' )) {
108100 $ table = $ schema ->getTable ('share ' );
109101 if (!$ table ->hasIndex ('share_with_index ' )) {
110102 $ output ->writeln ('<info>Adding additional share_with index to the share table, this can take some time...</info> ' );
111103 $ table ->addIndex (['share_with ' ], 'share_with_index ' );
112- $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema ());
104+ $ sqlQueries = $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema (), $ dryRun );
105+ if ($ dryRun && $ sqlQueries !== null ) {
106+ $ output ->writeln ($ sqlQueries );
107+ }
113108 $ updated = true ;
114109 $ output ->writeln ('<info>Share table updated successfully.</info> ' );
115110 }
116111
117112 if (!$ table ->hasIndex ('parent_index ' )) {
118113 $ output ->writeln ('<info>Adding additional parent index to the share table, this can take some time...</info> ' );
119114 $ table ->addIndex (['parent ' ], 'parent_index ' );
120- $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema ());
115+ $ sqlQueries = $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema (), $ dryRun );
116+ if ($ dryRun && $ sqlQueries !== null ) {
117+ $ output ->writeln ($ sqlQueries );
118+ }
121119 $ updated = true ;
122120 $ output ->writeln ('<info>Share table updated successfully.</info> ' );
123121 }
124122
125123 if (!$ table ->hasIndex ('owner_index ' )) {
126124 $ output ->writeln ('<info>Adding additional owner index to the share table, this can take some time...</info> ' );
127125 $ table ->addIndex (['uid_owner ' ], 'owner_index ' );
128- $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema ());
126+ $ sqlQueries = $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema (), $ dryRun );
127+ if ($ dryRun && $ sqlQueries !== null ) {
128+ $ output ->writeln ($ sqlQueries );
129+ }
129130 $ updated = true ;
130131 $ output ->writeln ('<info>Share table updated successfully.</info> ' );
131132 }
132133
133134 if (!$ table ->hasIndex ('initiator_index ' )) {
134135 $ output ->writeln ('<info>Adding additional initiator index to the share table, this can take some time...</info> ' );
135136 $ table ->addIndex (['uid_initiator ' ], 'initiator_index ' );
136- $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema ());
137+ $ sqlQueries = $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema (), $ dryRun );
138+ if ($ dryRun && $ sqlQueries !== null ) {
139+ $ output ->writeln ($ sqlQueries );
140+ }
137141 $ updated = true ;
138142 $ output ->writeln ('<info>Share table updated successfully.</info> ' );
139143 }
@@ -145,28 +149,40 @@ private function addCoreIndexes(OutputInterface $output) {
145149 if (!$ table ->hasIndex ('fs_mtime ' )) {
146150 $ output ->writeln ('<info>Adding additional mtime index to the filecache table, this can take some time...</info> ' );
147151 $ table ->addIndex (['mtime ' ], 'fs_mtime ' );
148- $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema ());
152+ $ sqlQueries = $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema (), $ dryRun );
153+ if ($ dryRun && $ sqlQueries !== null ) {
154+ $ output ->writeln ($ sqlQueries );
155+ }
149156 $ updated = true ;
150157 $ output ->writeln ('<info>Filecache table updated successfully.</info> ' );
151158 }
152159 if (!$ table ->hasIndex ('fs_size ' )) {
153160 $ output ->writeln ('<info>Adding additional size index to the filecache table, this can take some time...</info> ' );
154161 $ table ->addIndex (['size ' ], 'fs_size ' );
155- $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema ());
162+ $ sqlQueries = $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema (), $ dryRun );
163+ if ($ dryRun && $ sqlQueries !== null ) {
164+ $ output ->writeln ($ sqlQueries );
165+ }
156166 $ updated = true ;
157167 $ output ->writeln ('<info>Filecache table updated successfully.</info> ' );
158168 }
159169 if (!$ table ->hasIndex ('fs_id_storage_size ' )) {
160170 $ output ->writeln ('<info>Adding additional size index to the filecache table, this can take some time...</info> ' );
161171 $ table ->addIndex (['fileid ' , 'storage ' , 'size ' ], 'fs_id_storage_size ' );
162- $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema ());
172+ $ sqlQueries = $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema (), $ dryRun );
173+ if ($ dryRun && $ sqlQueries !== null ) {
174+ $ output ->writeln ($ sqlQueries );
175+ }
163176 $ updated = true ;
164177 $ output ->writeln ('<info>Filecache table updated successfully.</info> ' );
165178 }
166179 if (!$ table ->hasIndex ('fs_storage_path_prefix ' ) && !$ schema ->getDatabasePlatform () instanceof PostgreSQL94Platform) {
167180 $ output ->writeln ('<info>Adding additional path index to the filecache table, this can take some time...</info> ' );
168181 $ table ->addIndex (['storage ' , 'path ' ], 'fs_storage_path_prefix ' , [], ['lengths ' => [null , 64 ]]);
169- $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema ());
182+ $ sqlQueries = $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema (), $ dryRun );
183+ if ($ dryRun && $ sqlQueries !== null ) {
184+ $ output ->writeln ($ sqlQueries );
185+ }
170186 $ updated = true ;
171187 $ output ->writeln ('<info>Filecache table updated successfully.</info> ' );
172188 }
@@ -178,7 +194,10 @@ private function addCoreIndexes(OutputInterface $output) {
178194 if (!$ table ->hasIndex ('twofactor_providers_uid ' )) {
179195 $ output ->writeln ('<info>Adding additional twofactor_providers_uid index to the twofactor_providers table, this can take some time...</info> ' );
180196 $ table ->addIndex (['uid ' ], 'twofactor_providers_uid ' );
181- $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema ());
197+ $ sqlQueries = $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema (), $ dryRun );
198+ if ($ dryRun && $ sqlQueries !== null ) {
199+ $ output ->writeln ($ sqlQueries );
200+ }
182201 $ updated = true ;
183202 $ output ->writeln ('<info>Twofactor_providers table updated successfully.</info> ' );
184203 }
@@ -202,7 +221,10 @@ private function addCoreIndexes(OutputInterface $output) {
202221 $ table ->addUniqueIndex (['poll_token ' ], 'poll_token ' );
203222 $ table ->addUniqueIndex (['login_token ' ], 'login_token ' );
204223 $ table ->addIndex (['timestamp ' ], 'timestamp ' );
205- $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema ());
224+ $ sqlQueries = $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema (), $ dryRun );
225+ if ($ dryRun && $ sqlQueries !== null ) {
226+ $ output ->writeln ($ sqlQueries );
227+ }
206228 $ updated = true ;
207229 $ output ->writeln ('<info>login_flow_v2 table updated successfully.</info> ' );
208230 }
@@ -221,7 +243,10 @@ private function addCoreIndexes(OutputInterface $output) {
221243 }
222244
223245 $ table ->addUniqueIndex (['version ' ], 'version ' );
224- $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema ());
246+ $ sqlQueries = $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema (), $ dryRun );
247+ if ($ dryRun && $ sqlQueries !== null ) {
248+ $ output ->writeln ($ sqlQueries );
249+ }
225250 $ updated = true ;
226251 $ output ->writeln ('<info>whats_new table updated successfully.</info> ' );
227252 }
@@ -241,7 +266,10 @@ private function addCoreIndexes(OutputInterface $output) {
241266 }
242267 }
243268
244- $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema ());
269+ $ sqlQueries = $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema (), $ dryRun );
270+ if ($ dryRun && $ sqlQueries !== null ) {
271+ $ output ->writeln ($ sqlQueries );
272+ }
245273 $ cardsUpdated = true ;
246274 }
247275
@@ -255,7 +283,10 @@ private function addCoreIndexes(OutputInterface $output) {
255283 }
256284
257285 $ table ->addIndex (['addressbookid ' ], 'cards_abid ' );
258- $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema ());
286+ $ sqlQueries = $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema (), $ dryRun );
287+ if ($ dryRun && $ sqlQueries !== null ) {
288+ $ output ->writeln ($ sqlQueries );
289+ }
259290 $ cardsUpdated = true ;
260291 }
261292
@@ -269,7 +300,10 @@ private function addCoreIndexes(OutputInterface $output) {
269300 }
270301
271302 $ table ->addIndex (['addressbookid ' , 'uri ' ], 'cards_abiduri ' );
272- $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema ());
303+ $ sqlQueries = $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema (), $ dryRun );
304+ if ($ dryRun && $ sqlQueries !== null ) {
305+ $ output ->writeln ($ sqlQueries );
306+ }
273307 $ cardsUpdated = true ;
274308 }
275309
@@ -292,7 +326,10 @@ private function addCoreIndexes(OutputInterface $output) {
292326 }
293327
294328 $ table ->addIndex (['addressbookid ' ], 'cards_prop_abid ' );
295- $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema ());
329+ $ sqlQueries = $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema (), $ dryRun );
330+ if ($ dryRun && $ sqlQueries !== null ) {
331+ $ output ->writeln ($ sqlQueries );
332+ }
296333 $ updated = true ;
297334 $ output ->writeln ('<info>cards_properties table updated successfully.</info> ' );
298335 }
@@ -305,7 +342,10 @@ private function addCoreIndexes(OutputInterface $output) {
305342 $ output ->writeln ('<info>Adding calendarobject_calid_index index to the calendarobjects_props table, this can take some time...</info> ' );
306343
307344 $ table ->addIndex (['calendarid ' , 'calendartype ' ], 'calendarobject_calid_index ' );
308- $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema ());
345+ $ sqlQueries = $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema (), $ dryRun );
346+ if ($ dryRun && $ sqlQueries !== null ) {
347+ $ output ->writeln ($ sqlQueries );
348+ }
309349 $ updated = true ;
310350 $ output ->writeln ('<info>calendarobjects_props table updated successfully.</info> ' );
311351 }
@@ -318,7 +358,10 @@ private function addCoreIndexes(OutputInterface $output) {
318358 $ output ->writeln ('<info>Adding schedulobj_principuri_index index to the schedulingobjects table, this can take some time...</info> ' );
319359
320360 $ table ->addIndex (['principaluri ' ], 'schedulobj_principuri_index ' );
321- $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema ());
361+ $ sqlQueries = $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema (), $ dryRun );
362+ if ($ dryRun && $ sqlQueries !== null ) {
363+ $ output ->writeln ($ sqlQueries );
364+ }
322365 $ updated = true ;
323366 $ output ->writeln ('<info>schedulingobjects table updated successfully.</info> ' );
324367 }
@@ -333,14 +376,20 @@ private function addCoreIndexes(OutputInterface $output) {
333376 $ output ->writeln ('<info>Adding properties_path_index index to the oc_properties table, this can take some time...</info> ' );
334377
335378 $ table ->addIndex (['userid ' , 'propertypath ' ], 'properties_path_index ' );
336- $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema ());
379+ $ sqlQueries = $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema (), $ dryRun );
380+ if ($ dryRun && $ sqlQueries !== null ) {
381+ $ output ->writeln ($ sqlQueries );
382+ }
337383 $ propertiesUpdated = true ;
338384 }
339385 if (!$ table ->hasIndex ('properties_pathonly_index ' )) {
340386 $ output ->writeln ('<info>Adding properties_pathonly_index index to the oc_properties table, this can take some time...</info> ' );
341387
342388 $ table ->addIndex (['propertypath ' ], 'properties_pathonly_index ' );
343- $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema ());
389+ $ sqlQueries = $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema (), $ dryRun );
390+ if ($ dryRun && $ sqlQueries !== null ) {
391+ $ output ->writeln ($ sqlQueries );
392+ }
344393 $ propertiesUpdated = true ;
345394 }
346395
@@ -357,7 +406,10 @@ private function addCoreIndexes(OutputInterface $output) {
357406 $ output ->writeln ('<info>Adding job_lastcheck_reserved index to the oc_jobs table, this can take some time...</info> ' );
358407
359408 $ table ->addIndex (['last_checked ' , 'reserved_at ' ], 'job_lastcheck_reserved ' );
360- $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema ());
409+ $ sqlQueries = $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema (), $ dryRun );
410+ if ($ dryRun && $ sqlQueries !== null ) {
411+ $ output ->writeln ($ sqlQueries );
412+ }
361413 $ updated = true ;
362414 $ output ->writeln ('<info>oc_properties table updated successfully.</info> ' );
363415 }
@@ -370,7 +422,10 @@ private function addCoreIndexes(OutputInterface $output) {
370422 $ output ->writeln ('<info>Adding direct_edit_timestamp index to the oc_direct_edit table, this can take some time...</info> ' );
371423
372424 $ table ->addIndex (['timestamp ' ], 'direct_edit_timestamp ' );
373- $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema ());
425+ $ sqlQueries = $ this ->connection ->migrateToSchema ($ schema ->getWrappedSchema (), $ dryRun );
426+ if ($ dryRun && $ sqlQueries !== null ) {
427+ $ output ->writeln ($ sqlQueries );
428+ }
374429 $ updated = true ;
375430 $ output ->writeln ('<info>oc_direct_edit table updated successfully.</info> ' );
376431 }
0 commit comments