Skip to content

Commit 45137b5

Browse files
authored
Merge pull request #31774 from nextcloud/backport/31737/stable23
[stable23] Wrap oauth2 migrations inside conditions
2 parents afc93af + 0ce1d89 commit 45137b5

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

lib/private/Repair/Owncloud/MigrateOauthTables.php

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,34 @@ public function run(IOutput $output) {
5555
$output->info("Update the oauth2_access_tokens table schema.");
5656
$schema = new SchemaWrapper($this->db);
5757
$table = $schema->getTable('oauth2_access_tokens');
58-
$table->addColumn('hashed_code', 'string', [
59-
'notnull' => true,
60-
'length' => 128,
61-
]);
62-
$table->addColumn('encrypted_token', 'string', [
63-
'notnull' => true,
64-
'length' => 786,
65-
]);
66-
$table->addUniqueIndex(['hashed_code'], 'oauth2_access_hash_idx');
67-
$table->addIndex(['client_id'], 'oauth2_access_client_id_idx');
68-
58+
if (!$table->hasColumn('hashed_code')) {
59+
$table->addColumn('hashed_code', 'string', [
60+
'notnull' => true,
61+
'length' => 128,
62+
]);
63+
}
64+
if (!$table->hasColumn('encrypted_token')) {
65+
$table->addColumn('encrypted_token', 'string', [
66+
'notnull' => true,
67+
'length' => 786,
68+
]);
69+
}
70+
if (!$table->hasIndex('oauth2_access_hash_idx')) {
71+
$table->addUniqueIndex(['hashed_code'], 'oauth2_access_hash_idx');
72+
}
73+
if (!$table->hasIndex('oauth2_access_client_id_idx')) {
74+
$table->addIndex(['client_id'], 'oauth2_access_client_id_idx');
75+
}
6976

7077
$output->info("Update the oauth2_clients table schema.");
7178
$schema = new SchemaWrapper($this->db);
7279
$table = $schema->getTable('oauth2_clients');
73-
$table->getColumn('name')->setLength(64);
74-
$table->dropColumn('allow_subdomains');
80+
if ($table->getColumn('name')->getLength() !== 64) {
81+
$table->getColumn('name')->setLength(64);
82+
}
83+
if ($table->hasColumn('allow_subdomains')) {
84+
$table->dropColumn('allow_subdomains');
85+
}
7586

7687
if (!$schema->getTable('oauth2_clients')->hasColumn('client_identifier')) {
7788
$table->addColumn('client_identifier', 'string', [

0 commit comments

Comments
 (0)