From 8756307172d45267dc4317094bbbd49a52a39485 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Sun, 7 Apr 2024 15:42:34 +0200 Subject: [PATCH] safer migrations Signed-off-by: Julien Veyssier --- .../Version000102Date20190907142139.php | 15 +++-- .../Version000103Date20190907163755.php | 20 ++++--- .../Version000106Date20191023153118.php | 30 ++++++---- .../Version000201Date20191223203543.php | 15 +++-- .../Version000202Date20191225201436.php | 15 +++-- .../Version000203Date20191227005654.php | 15 +++-- .../Version000204Date20191228201832.php | 15 +++-- .../Version000205Date20200102013739.php | 15 +++-- .../Version000301Date20200108160931.php | 12 ++-- .../Version000302Date20200110144741.php | 24 ++++---- .../Version000303Date20200201171814.php | 15 +++-- .../Version000303Date20200201172933.php | 7 ++- .../Version000304Date20200313092247.php | 15 +++-- .../Version000304Date20200313095955.php | 7 ++- .../Version000403Date20200231152118.php | 35 +++++++---- .../Version000403Date20200323173321.php | 17 ++++-- .../Version000404Date20200324145208.php | 3 +- .../Version000406Date20200417185442.php | 21 ++++--- .../Version000406Date20200426154317.php | 20 ++++--- .../Version000406Date20200426163311.php | 13 ++-- .../Version000408Date20200430162436.php | 32 +++++----- .../Version010105Date20201030132329.php | 32 +++++----- .../Version010203Date20201208131054.php | 22 +++---- .../Version010206Date20201223134353.php | 59 +++++++++---------- .../Version010301Date20210412152948.php | 32 ++++------ .../Version010309Date20210628143307.php | 5 +- .../Version010309Date20210714194120.php | 19 +++--- .../Version010314Date20210815170535.php | 37 ++++++------ .../Version010314Date20210828143421.php | 21 ++++--- .../Version010315Date20210830235504.php | 19 +++--- .../Version010403Date20211112141106.php | 1 + .../Version010403Date20211112144733.php | 2 + .../Version010511Date20231012151740.php | 2 + .../Version010512Date20231201151136.php | 2 + .../Version010514Date20231203164157.php | 1 + .../Version010600Date20240103034026.php | 5 +- 36 files changed, 348 insertions(+), 272 deletions(-) diff --git a/lib/Migration/Version000102Date20190907142139.php b/lib/Migration/Version000102Date20190907142139.php index 1021c4200..db16ac0b0 100644 --- a/lib/Migration/Version000102Date20190907142139.php +++ b/lib/Migration/Version000102Date20190907142139.php @@ -34,14 +34,17 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt if ($schema->hasTable('cospend_projects')) { $table = $schema->getTable('cospend_projects'); - $table->addColumn('autoexport', 'string', [ - 'notnull' => true, - 'length' => 1, - 'default' => 'n', - ]); + if (!$table->hasColumn('autoexport')) { + $table->addColumn('autoexport', 'string', [ + 'notnull' => true, + 'length' => 1, + 'default' => 'n', + ]); + return $schema; + } } - return $schema; + return null; } /** diff --git a/lib/Migration/Version000103Date20190907163755.php b/lib/Migration/Version000103Date20190907163755.php index e3fb9f129..f7b742f4d 100644 --- a/lib/Migration/Version000103Date20190907163755.php +++ b/lib/Migration/Version000103Date20190907163755.php @@ -52,14 +52,18 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt if ($schema->hasTable('cospend_bills')) { $table = $schema->getTable('cospend_bills'); - $table->addColumn('categoryid', 'integer', [ - 'notnull' => false, - 'length' => 255 - ]); - $table->addColumn('paymentmode', 'string', [ - 'notnull' => false, - 'length' => 1 - ]); + if (!$table->hasColumn('categoryid')) { + $table->addColumn('categoryid', 'integer', [ + 'notnull' => false, + 'length' => 255 + ]); + } + if (!$table->hasColumn('paymentmode')) { + $table->addColumn('paymentmode', 'string', [ + 'notnull' => false, + 'length' => 1 + ]); + } } return $schema; diff --git a/lib/Migration/Version000106Date20191023153118.php b/lib/Migration/Version000106Date20191023153118.php index 3c51b20f0..6c7343d40 100644 --- a/lib/Migration/Version000106Date20191023153118.php +++ b/lib/Migration/Version000106Date20191023153118.php @@ -35,26 +35,32 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt if ($schema->hasTable('cospend_projects')) { $table = $schema->getTable('cospend_projects'); - $table->addColumn('lastchanged', Types::INTEGER, [ - 'notnull' => true, - 'default' => 0, - ]); + if (!$table->hasColumn('lastchanged')) { + $table->addColumn('lastchanged', Types::INTEGER, [ + 'notnull' => true, + 'default' => 0, + ]); + } } if ($schema->hasTable('cospend_bills')) { $table = $schema->getTable('cospend_bills'); - $table->addColumn('lastchanged', Types::INTEGER, [ - 'notnull' => true, - 'default' => 0, - ]); + if (!$table->hasColumn('lastchanged')) { + $table->addColumn('lastchanged', Types::INTEGER, [ + 'notnull' => true, + 'default' => 0, + ]); + } } if ($schema->hasTable('cospend_members')) { $table = $schema->getTable('cospend_members'); - $table->addColumn('lastchanged', Types::INTEGER, [ - 'notnull' => true, - 'default' => 0, - ]); + if (!$table->hasColumn('lastchanged')) { + $table->addColumn('lastchanged', Types::INTEGER, [ + 'notnull' => true, + 'default' => 0, + ]); + } } return $schema; diff --git a/lib/Migration/Version000201Date20191223203543.php b/lib/Migration/Version000201Date20191223203543.php index 5873b5b6d..18ea82e85 100644 --- a/lib/Migration/Version000201Date20191223203543.php +++ b/lib/Migration/Version000201Date20191223203543.php @@ -34,14 +34,17 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt if ($schema->hasTable('cospend_members')) { $table = $schema->getTable('cospend_shares'); - $table->addColumn('permissions', 'string', [ - 'notnull' => true, - 'length' => 4, - 'default' => 'edc' - ]); + if (!$table->hasColumn('permissions')) { + $table->addColumn('permissions', 'string', [ + 'notnull' => true, + 'length' => 4, + 'default' => 'edc' + ]); + return $schema; + } } - return $schema; + return null; } /** diff --git a/lib/Migration/Version000202Date20191225201436.php b/lib/Migration/Version000202Date20191225201436.php index e2361c548..73095cd06 100644 --- a/lib/Migration/Version000202Date20191225201436.php +++ b/lib/Migration/Version000202Date20191225201436.php @@ -34,14 +34,17 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt if ($schema->hasTable('cospend_bills')) { $table = $schema->getTable('cospend_bills'); - $table->addColumn('repeatallactive', 'integer', [ - 'notnull' => true, - 'length' => 1, - 'default' => 0 - ]); + if (!$table->hasColumn('repeatallactive')) { + $table->addColumn('repeatallactive', 'integer', [ + 'notnull' => true, + 'length' => 1, + 'default' => 0 + ]); + return $schema; + } } - return $schema; + return null; } /** diff --git a/lib/Migration/Version000203Date20191227005654.php b/lib/Migration/Version000203Date20191227005654.php index be21257b5..db2a37a32 100644 --- a/lib/Migration/Version000203Date20191227005654.php +++ b/lib/Migration/Version000203Date20191227005654.php @@ -34,14 +34,17 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt if ($schema->hasTable('cospend_projects')) { $table = $schema->getTable('cospend_projects'); - $table->addColumn('guestpermissions', 'string', [ - 'notnull' => true, - 'length' => 4, - 'default' => 'edc' - ]); + if (!$table->hasColumn('guestpermissions')) { + $table->addColumn('guestpermissions', 'string', [ + 'notnull' => true, + 'length' => 4, + 'default' => 'edc' + ]); + return $schema; + } } - return $schema; + return null; } /** diff --git a/lib/Migration/Version000204Date20191228201832.php b/lib/Migration/Version000204Date20191228201832.php index 15e654e91..4b60052fc 100644 --- a/lib/Migration/Version000204Date20191228201832.php +++ b/lib/Migration/Version000204Date20191228201832.php @@ -34,14 +34,17 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt if ($schema->hasTable('cospend_bills')) { $table = $schema->getTable('cospend_bills'); - $table->addColumn('repeatuntil', 'string', [ - 'notnull' => false, - 'length' => 20, - 'default' => null - ]); + if (!$table->hasColumn('repeatuntil')) { + $table->addColumn('repeatuntil', 'string', [ + 'notnull' => false, + 'length' => 20, + 'default' => null + ]); + return $schema; + } } - return $schema; + return null; } /** diff --git a/lib/Migration/Version000205Date20200102013739.php b/lib/Migration/Version000205Date20200102013739.php index 03845b6bb..f84d7ec3f 100644 --- a/lib/Migration/Version000205Date20200102013739.php +++ b/lib/Migration/Version000205Date20200102013739.php @@ -34,14 +34,17 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt if ($schema->hasTable('cospend_members')) { $table = $schema->getTable('cospend_members'); - $table->addColumn('color', 'string', [ - 'notnull' => false, - 'length' => 10, - 'default' => null - ]); + if (!$table->hasColumn('color')) { + $table->addColumn('color', 'string', [ + 'notnull' => false, + 'length' => 10, + 'default' => null + ]); + return $schema; + } } - return $schema; + return null; } /** diff --git a/lib/Migration/Version000301Date20200108160931.php b/lib/Migration/Version000301Date20200108160931.php index 929154f07..ccef62103 100644 --- a/lib/Migration/Version000301Date20200108160931.php +++ b/lib/Migration/Version000301Date20200108160931.php @@ -56,11 +56,13 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt if ($schema->hasTable('cospend_projects')) { $table = $schema->getTable('cospend_projects'); - $table->addColumn('currencyname', 'string', [ - 'notnull' => false, - 'length' => 64, - 'default' => null - ]); + if (!$table->hasColumn('currencyname')) { + $table->addColumn('currencyname', 'string', [ + 'notnull' => false, + 'length' => 64, + 'default' => null + ]); + } } return $schema; diff --git a/lib/Migration/Version000302Date20200110144741.php b/lib/Migration/Version000302Date20200110144741.php index 996351cef..4a3bd789e 100644 --- a/lib/Migration/Version000302Date20200110144741.php +++ b/lib/Migration/Version000302Date20200110144741.php @@ -34,16 +34,20 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt if ($schema->hasTable('cospend_categories')) { $table = $schema->getTable('cospend_categories'); - $table->addColumn('icon', 'string', [ - 'notnull' => false, - 'length' => 3, - 'default' => null - ]); - $table->addColumn('color', 'string', [ - 'notnull' => false, - 'length' => 10, - 'default' => null - ]); + if (!$table->hasColumn('icon')) { + $table->addColumn('icon', 'string', [ + 'notnull' => false, + 'length' => 3, + 'default' => null + ]); + } + if (!$table->hasColumn('color')) { + $table->addColumn('color', 'string', [ + 'notnull' => false, + 'length' => 10, + 'default' => null + ]); + } } return $schema; diff --git a/lib/Migration/Version000303Date20200201171814.php b/lib/Migration/Version000303Date20200201171814.php index cf3174bb4..9f9ebe1c0 100644 --- a/lib/Migration/Version000303Date20200201171814.php +++ b/lib/Migration/Version000303Date20200201171814.php @@ -46,14 +46,17 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt if ($schema->hasTable('cospend_shares')) { $table = $schema->getTable('cospend_shares'); - $table->addColumn('type', 'string', [ - 'notnull' => true, - 'length' => 1, - 'default' => 'u' - ]); + if (!$table->hasColumn('type')) { + $table->addColumn('type', 'string', [ + 'notnull' => true, + 'length' => 1, + 'default' => 'u' + ]); + return $schema; + } } - return $schema; + return null; } /** diff --git a/lib/Migration/Version000303Date20200201172933.php b/lib/Migration/Version000303Date20200201172933.php index fc97587b9..c2a8178ec 100644 --- a/lib/Migration/Version000303Date20200201172933.php +++ b/lib/Migration/Version000303Date20200201172933.php @@ -34,10 +34,13 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt if ($schema->hasTable('cospend_shares')) { $table = $schema->getTable('cospend_shares'); - $table->dropColumn('isgroupshare'); + if ($table->hasColumn('isgroupshare')) { + $table->dropColumn('isgroupshare'); + return $schema; + } } - return $schema; + return null; } /** diff --git a/lib/Migration/Version000304Date20200313092247.php b/lib/Migration/Version000304Date20200313092247.php index e0d4e5b26..cd828ffd3 100644 --- a/lib/Migration/Version000304Date20200313092247.php +++ b/lib/Migration/Version000304Date20200313092247.php @@ -46,14 +46,17 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt if ($schema->hasTable('cospend_bills')) { $table = $schema->getTable('cospend_bills'); - $table->addColumn('timestamp', 'bigint', [ - 'notnull' => true, - 'length' => 10, - 'default' => 0 - ]); + if (!$table->hasColumn('timestamp')) { + $table->addColumn('timestamp', 'bigint', [ + 'notnull' => true, + 'length' => 10, + 'default' => 0 + ]); + return $schema; + } } - return $schema; + return null; } /** diff --git a/lib/Migration/Version000304Date20200313095955.php b/lib/Migration/Version000304Date20200313095955.php index 98ad0cd70..8e2b2882b 100644 --- a/lib/Migration/Version000304Date20200313095955.php +++ b/lib/Migration/Version000304Date20200313095955.php @@ -34,10 +34,13 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt if ($schema->hasTable('cospend_bills')) { $table = $schema->getTable('cospend_bills'); - $table->dropColumn('date'); + if ($table->hasColumn('date')) { + $table->dropColumn('date'); + return $schema; + } } - return $schema; + return null; } /** diff --git a/lib/Migration/Version000403Date20200231152118.php b/lib/Migration/Version000403Date20200231152118.php index 977539f03..6c94e77a5 100644 --- a/lib/Migration/Version000403Date20200231152118.php +++ b/lib/Migration/Version000403Date20200231152118.php @@ -43,18 +43,29 @@ public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); - $table = $schema->getTable('cospend_projects'); - $table->addColumn('guestaccesslevel', 'integer', [ - 'notnull' => true, - 'length' => 4, - 'default' => 2 - ]); - $table = $schema->getTable('cospend_shares'); - $table->addColumn('accesslevel', 'integer', [ - 'notnull' => true, - 'length' => 4, - 'default' => 2 - ]); + + if ($schema->hasTable('cospend_projects')) { + $table = $schema->getTable('cospend_projects'); + if (!$table->hasColumn('guestaccesslevel')) { + $table->addColumn('guestaccesslevel', 'integer', [ + 'notnull' => true, + 'length' => 4, + 'default' => 2 + ]); + } + } + + if ($schema->hasTable('cospend_shares')) { + $table = $schema->getTable('cospend_shares'); + if (!$table->hasColumn('accesslevel')) { + $table->addColumn('accesslevel', 'integer', [ + 'notnull' => true, + 'length' => 4, + 'default' => 2 + ]); + } + } + return $schema; } diff --git a/lib/Migration/Version000403Date20200323173321.php b/lib/Migration/Version000403Date20200323173321.php index 7a7791606..461b8b9df 100644 --- a/lib/Migration/Version000403Date20200323173321.php +++ b/lib/Migration/Version000403Date20200323173321.php @@ -32,10 +32,19 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); - $table = $schema->getTable('cospend_shares'); - $table->dropColumn('permissions'); - $table = $schema->getTable('cospend_projects'); - $table->dropColumn('guestpermissions'); + if ($schema->hasTable('cospend_shares')) { + $table = $schema->getTable('cospend_shares'); + if ($table->hasColumn('permissions')) { + $table->dropColumn('permissions'); + } + } + + if ($schema->hasTable('cospend_projects')) { + $table = $schema->getTable('cospend_projects'); + if ($table->hasColumn('guestpermissions')) { + $table->dropColumn('guestpermissions'); + } + } return $schema; } diff --git a/lib/Migration/Version000404Date20200324145208.php b/lib/Migration/Version000404Date20200324145208.php index d5a1d7528..774b3dbd6 100644 --- a/lib/Migration/Version000404Date20200324145208.php +++ b/lib/Migration/Version000404Date20200324145208.php @@ -34,9 +34,10 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt if ($schema->hasTable('cospend_ext_projects')) { $schema->dropTable('cospend_ext_projects'); + return $schema; } - return $schema; + return null; } /** diff --git a/lib/Migration/Version000406Date20200417185442.php b/lib/Migration/Version000406Date20200417185442.php index 5cb33c6fb..9384e38ea 100644 --- a/lib/Migration/Version000406Date20200417185442.php +++ b/lib/Migration/Version000406Date20200417185442.php @@ -32,14 +32,19 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); - $table = $schema->getTable('cospend_members'); - $table->addColumn('userid', 'string', [ - 'notnull' => false, - 'length' => 64, - 'default' => null - ]); - - return $schema; + if ($schema->hasTable('cospend_members')) { + $table = $schema->getTable('cospend_members'); + if (!$table->hasColumn('userid')) { + $table->addColumn('userid', 'string', [ + 'notnull' => false, + 'length' => 64, + 'default' => null + ]); + return $schema; + } + } + + return null; } /** diff --git a/lib/Migration/Version000406Date20200426154317.php b/lib/Migration/Version000406Date20200426154317.php index a7a1cefcc..1282e7d31 100644 --- a/lib/Migration/Version000406Date20200426154317.php +++ b/lib/Migration/Version000406Date20200426154317.php @@ -46,13 +46,19 @@ public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); - $table = $schema->getTable('cospend_categories'); - $table->addColumn('encoded_icon', 'string', [ - 'notnull' => false, - 'length' => 64, - 'default' => null - ]); - return $schema; + + if ($schema->hasTable('cospend_categories')) { + $table = $schema->getTable('cospend_categories'); + if (!$table->hasColumn('encoded_icon')) { + $table->addColumn('encoded_icon', 'string', [ + 'notnull' => false, + 'length' => 64, + 'default' => null + ]); + return $schema; + } + } + return null; } /** diff --git a/lib/Migration/Version000406Date20200426163311.php b/lib/Migration/Version000406Date20200426163311.php index e88ef113e..f516c1a23 100644 --- a/lib/Migration/Version000406Date20200426163311.php +++ b/lib/Migration/Version000406Date20200426163311.php @@ -32,10 +32,15 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); - $table = $schema->getTable('cospend_categories'); - $table->dropColumn('icon'); - - return $schema; + if ($schema->hasTable('cospend_categories')) { + $table = $schema->getTable('cospend_categories'); + if ($table->hasColumn('icon')) { + $table->dropColumn('icon'); + return $schema; + } + } + + return null; } /** diff --git a/lib/Migration/Version000408Date20200430162436.php b/lib/Migration/Version000408Date20200430162436.php index 08401f1c4..9adda7506 100644 --- a/lib/Migration/Version000408Date20200430162436.php +++ b/lib/Migration/Version000408Date20200430162436.php @@ -6,7 +6,6 @@ use Closure; use OCP\DB\ISchemaWrapper; -use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; @@ -15,16 +14,6 @@ */ class Version000408Date20200430162436 extends SimpleMigrationStep { - /** @var IDBConnection */ - private $connection; - - /** - * @param IDBConnection $connection - */ - public function __construct(IDBConnection $connection) { - $this->connection = $connection; - } - /** * @param IOutput $output * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` @@ -42,13 +31,20 @@ public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); - $table = $schema->getTable('cospend_bills'); - $table->addColumn('comment', 'string', [ - 'notnull' => false, - 'length' => 300, - 'default' => null - ]); - return $schema; + + if ($schema->hasTable('cospend_bills')) { + $table = $schema->getTable('cospend_bills'); + if (!$table->hasColumn('comment')) { + $table->addColumn('comment', 'string', [ + 'notnull' => false, + 'length' => 300, + 'default' => null + ]); + return $schema; + } + } + + return null; } /** diff --git a/lib/Migration/Version010105Date20201030132329.php b/lib/Migration/Version010105Date20201030132329.php index 324ffa517..c2f75b65c 100644 --- a/lib/Migration/Version010105Date20201030132329.php +++ b/lib/Migration/Version010105Date20201030132329.php @@ -6,7 +6,6 @@ use Closure; use OCP\DB\ISchemaWrapper; -use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; @@ -15,16 +14,6 @@ */ class Version010105Date20201030132329 extends SimpleMigrationStep { - /** @var IDBConnection */ - private $connection; - - /** - * @param IDBConnection $connection - */ - public function __construct(IDBConnection $connection) { - $this->connection = $connection; - } - /** * @param IOutput $output * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` @@ -42,13 +31,20 @@ public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); - $table = $schema->getTable('cospend_shares'); - $table->addColumn('manually_added', 'integer', [ - 'notnull' => true, - 'length' => 4, - 'default' => 1, - ]); - return $schema; + + if ($schema->hasTable('cospend_shares')) { + $table = $schema->getTable('cospend_shares'); + if (!$table->hasColumn('manually_added')) { + $table->addColumn('manually_added', 'integer', [ + 'notnull' => true, + 'length' => 4, + 'default' => 1, + ]); + return $schema; + } + } + + return null; } /** diff --git a/lib/Migration/Version010203Date20201208131054.php b/lib/Migration/Version010203Date20201208131054.php index b1eb541a7..81c1a1cda 100644 --- a/lib/Migration/Version010203Date20201208131054.php +++ b/lib/Migration/Version010203Date20201208131054.php @@ -6,7 +6,6 @@ use Closure; use OCP\DB\ISchemaWrapper; -use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; @@ -15,16 +14,6 @@ */ class Version010203Date20201208131054 extends SimpleMigrationStep { - /** @var IDBConnection */ - private $connection; - - /** - * @param IDBConnection $connection - */ - public function __construct(IDBConnection $connection) { - $this->connection = $connection; - } - /** * @param IOutput $output * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` @@ -42,9 +31,14 @@ public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); - $table = $schema->getTable('cospend_projects'); - $table->setPrimaryKey(['id']); - return $schema; + + if ($schema->hasTable('cospend_projects')) { + $table = $schema->getTable('cospend_projects'); + $table->setPrimaryKey(['id']); + return $schema; + } + + return null; } /** diff --git a/lib/Migration/Version010206Date20201223134353.php b/lib/Migration/Version010206Date20201223134353.php index 9b02141cb..cd7be1419 100644 --- a/lib/Migration/Version010206Date20201223134353.php +++ b/lib/Migration/Version010206Date20201223134353.php @@ -6,7 +6,6 @@ use Closure; use OCP\DB\ISchemaWrapper; -use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; @@ -15,16 +14,6 @@ */ class Version010206Date20201223134353 extends SimpleMigrationStep { - /** @var IDBConnection */ - private $connection; - - /** - * @param IDBConnection $connection - */ - public function __construct(IDBConnection $connection) { - $this->connection = $connection; - } - /** * @param IOutput $output * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` @@ -42,30 +31,36 @@ public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); - $table = $schema->getTable('cospend_projects'); - if (!$table->hasColumn('deletiondisabled')) { - $table->addColumn('deletiondisabled', 'integer', [ - 'notnull' => true, - 'length' => 4, - 'default' => 0, - ]); - } - if (!$table->hasColumn('categorysort')) { - $table->addColumn('categorysort', 'string', [ - 'notnull' => true, - 'length' => 1, - 'default' => 'a', - ]); + + if ($schema->hasTable('cospend_projects')) { + $table = $schema->getTable('cospend_projects'); + if (!$table->hasColumn('deletiondisabled')) { + $table->addColumn('deletiondisabled', 'integer', [ + 'notnull' => true, + 'length' => 4, + 'default' => 0, + ]); + } + if (!$table->hasColumn('categorysort')) { + $table->addColumn('categorysort', 'string', [ + 'notnull' => true, + 'length' => 1, + 'default' => 'a', + ]); + } } - $table = $schema->getTable('cospend_categories'); - if (!$table->hasColumn('order')) { - $table->addColumn('order', 'integer', [ - 'notnull' => true, - 'length' => 4, - 'default' => 0, - ]); + if ($schema->hasTable('cospend_categories')) { + $table = $schema->getTable('cospend_categories'); + if (!$table->hasColumn('order')) { + $table->addColumn('order', 'integer', [ + 'notnull' => true, + 'length' => 4, + 'default' => 0, + ]); + } } + return $schema; } diff --git a/lib/Migration/Version010301Date20210412152948.php b/lib/Migration/Version010301Date20210412152948.php index 9f8123653..92e3bec18 100644 --- a/lib/Migration/Version010301Date20210412152948.php +++ b/lib/Migration/Version010301Date20210412152948.php @@ -6,7 +6,6 @@ use Closure; use OCP\DB\ISchemaWrapper; -use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; @@ -15,16 +14,6 @@ */ class Version010301Date20210412152948 extends SimpleMigrationStep { - /** @var IDBConnection */ - private $connection; - - /** - * @param IDBConnection $connection - */ - public function __construct(IDBConnection $connection) { - $this->connection = $connection; - } - /** * @param IOutput $output * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` @@ -42,15 +31,20 @@ public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); - $table = $schema->getTable('cospend_bills'); - if (!$table->hasColumn('repeatfreq')) { - $table->addColumn('repeatfreq', 'integer', [ - 'notnull' => true, - 'length' => 4, - 'default' => 1, - ]); + + if ($schema->hasTable('cospend_bills')) { + $table = $schema->getTable('cospend_bills'); + if (!$table->hasColumn('repeatfreq')) { + $table->addColumn('repeatfreq', 'integer', [ + 'notnull' => true, + 'length' => 4, + 'default' => 1, + ]); + return $schema; + } } - return $schema; + + return null; } /** diff --git a/lib/Migration/Version010309Date20210628143307.php b/lib/Migration/Version010309Date20210628143307.php index 4e5d9e49c..4f1ba4739 100644 --- a/lib/Migration/Version010309Date20210628143307.php +++ b/lib/Migration/Version010309Date20210628143307.php @@ -8,7 +8,6 @@ use OCP\DB\ISchemaWrapper; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; -use OCP\IL10N; use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; @@ -19,14 +18,12 @@ class Version010309Date20210628143307 extends SimpleMigrationStep { /** @var IDBConnection */ private $connection; - private $trans; /** * @param IDBConnection $connection */ - public function __construct(IDBConnection $connection, IL10N $l10n) { + public function __construct(IDBConnection $connection) { $this->connection = $connection; - $this->trans = $l10n; } /** diff --git a/lib/Migration/Version010309Date20210714194120.php b/lib/Migration/Version010309Date20210714194120.php index 12d884533..02b1c5c46 100644 --- a/lib/Migration/Version010309Date20210714194120.php +++ b/lib/Migration/Version010309Date20210714194120.php @@ -35,14 +35,19 @@ public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); - $table = $schema->getTable('cospend_shares'); - if (!$table->hasColumn('label')) { - $table->addColumn('label', Types::STRING, [ - 'notnull' => false, - 'length' => 100, - ]); + + if ($schema->hasTable('cospend_shares')) { + $table = $schema->getTable('cospend_shares'); + if (!$table->hasColumn('label')) { + $table->addColumn('label', Types::STRING, [ + 'notnull' => false, + 'length' => 100, + ]); + return $schema; + } } - return $schema; + + return null; } /** diff --git a/lib/Migration/Version010314Date20210815170535.php b/lib/Migration/Version010314Date20210815170535.php index 54b4d2abc..ea88834d4 100644 --- a/lib/Migration/Version010314Date20210815170535.php +++ b/lib/Migration/Version010314Date20210815170535.php @@ -9,7 +9,6 @@ use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\Types; use OCP\IDBConnection; -use OCP\IL10N; use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; @@ -20,14 +19,12 @@ class Version010314Date20210815170535 extends SimpleMigrationStep { /** @var IDBConnection */ private $connection; - private $trans; /** * @param IDBConnection $connection */ - public function __construct(IDBConnection $connection, IL10N $l10n) { + public function __construct(IDBConnection $connection) { $this->connection = $connection; - $this->trans = $l10n; } /** @@ -81,22 +78,26 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt $table->setPrimaryKey(['id']); } - $table = $schema->getTable('cospend_bills'); - if (!$table->hasColumn('paymentmodeid')) { - $table->addColumn('paymentmodeid', Types::INTEGER, [ - 'notnull' => true, - 'length' => 4, - 'default' => 0, - ]); + if ($schema->hasTable('cospend_bills')) { + $table = $schema->getTable('cospend_bills'); + if (!$table->hasColumn('paymentmodeid')) { + $table->addColumn('paymentmodeid', Types::INTEGER, [ + 'notnull' => true, + 'length' => 4, + 'default' => 0, + ]); + } } - $table = $schema->getTable('cospend_projects'); - if (!$table->hasColumn('paymentmodesort')) { - $table->addColumn('paymentmodesort', Types::STRING, [ - 'notnull' => true, - 'length' => 1, - 'default' => 'a', - ]); + if ($schema->hasTable('cospend_projects')) { + $table = $schema->getTable('cospend_projects'); + if (!$table->hasColumn('paymentmodesort')) { + $table->addColumn('paymentmodesort', Types::STRING, [ + 'notnull' => true, + 'length' => 1, + 'default' => 'a', + ]); + } } return $schema; diff --git a/lib/Migration/Version010314Date20210828143421.php b/lib/Migration/Version010314Date20210828143421.php index 1fd9224d7..1fbe133bd 100644 --- a/lib/Migration/Version010314Date20210828143421.php +++ b/lib/Migration/Version010314Date20210828143421.php @@ -47,15 +47,20 @@ public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); - $table = $schema->getTable('cospend_paymentmodes'); - if (!$table->hasColumn('old_id')) { - $table->addColumn('old_id', Types::STRING, [ - 'notnull' => false, - 'length' => 1, - 'default' => null, - ]); + + if ($schema->hasTable('cospend_paymentmodes')) { + $table = $schema->getTable('cospend_paymentmodes'); + if (!$table->hasColumn('old_id')) { + $table->addColumn('old_id', Types::STRING, [ + 'notnull' => false, + 'length' => 1, + 'default' => null, + ]); + return $schema; + } } - return $schema; + + return null; } /** diff --git a/lib/Migration/Version010315Date20210830235504.php b/lib/Migration/Version010315Date20210830235504.php index db4ee7764..8345f7b11 100644 --- a/lib/Migration/Version010315Date20210830235504.php +++ b/lib/Migration/Version010315Date20210830235504.php @@ -32,14 +32,19 @@ public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); - $table = $schema->getTable('cospend_shares'); - if (!$table->hasColumn('password')) { - $table->addColumn('password', Types::STRING, [ - 'notnull' => false, - 'length' => 64, - ]); + + if ($schema->hasTable('cospend_shares')) { + $table = $schema->getTable('cospend_shares'); + if (!$table->hasColumn('password')) { + $table->addColumn('password', Types::STRING, [ + 'notnull' => false, + 'length' => 64, + ]); + return $schema; + } } - return $schema; + + return null; } /** diff --git a/lib/Migration/Version010403Date20211112141106.php b/lib/Migration/Version010403Date20211112141106.php index f8216ba10..8d7d02a7e 100644 --- a/lib/Migration/Version010403Date20211112141106.php +++ b/lib/Migration/Version010403Date20211112141106.php @@ -85,6 +85,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt ]); $table->setPrimaryKey(['id']); } + if (!$schema->hasTable('cospend_paymentmodes')) { if ($schema->hasTable('cospend_project_paymentmodes')) { $this->shouldCopyPaymentmodesData = true; diff --git a/lib/Migration/Version010403Date20211112144733.php b/lib/Migration/Version010403Date20211112144733.php index 8c8e23deb..420bae852 100644 --- a/lib/Migration/Version010403Date20211112144733.php +++ b/lib/Migration/Version010403Date20211112144733.php @@ -31,12 +31,14 @@ public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); + if ($schema->hasTable('cospend_project_categories')) { $schema->dropTable('cospend_project_categories'); } if ($schema->hasTable('cospend_project_paymentmodes')) { $schema->dropTable('cospend_project_paymentmodes'); } + return $schema; } diff --git a/lib/Migration/Version010511Date20231012151740.php b/lib/Migration/Version010511Date20231012151740.php index 211a23e6e..74e963858 100644 --- a/lib/Migration/Version010511Date20231012151740.php +++ b/lib/Migration/Version010511Date20231012151740.php @@ -24,6 +24,7 @@ public function __construct() { public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); + if ($schema->hasTable('cospend_bills')) { $table = $schema->getTable('cospend_bills'); if (!$table->hasColumn('deleted')) { @@ -35,6 +36,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt return $schema; } } + return null; } } diff --git a/lib/Migration/Version010512Date20231201151136.php b/lib/Migration/Version010512Date20231201151136.php index 467b49deb..0f798ea61 100644 --- a/lib/Migration/Version010512Date20231201151136.php +++ b/lib/Migration/Version010512Date20231201151136.php @@ -24,6 +24,7 @@ public function __construct() { public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); + if ($schema->hasTable('cospend_projects')) { $table = $schema->getTable('cospend_projects'); if (!$table->hasColumn('archived_ts')) { @@ -35,6 +36,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt return $schema; } } + return null; } } diff --git a/lib/Migration/Version010514Date20231203164157.php b/lib/Migration/Version010514Date20231203164157.php index 51a51d7c4..c407b2c5c 100644 --- a/lib/Migration/Version010514Date20231203164157.php +++ b/lib/Migration/Version010514Date20231203164157.php @@ -25,6 +25,7 @@ public function __construct(private IDBConnection $connection) { */ public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { $qb = $this->connection->getQueryBuilder(); + $qb->update('cospend_projects') ->set('lastchanged', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)) ->where( diff --git a/lib/Migration/Version010600Date20240103034026.php b/lib/Migration/Version010600Date20240103034026.php index 2d5d39ea3..954869670 100644 --- a/lib/Migration/Version010600Date20240103034026.php +++ b/lib/Migration/Version010600Date20240103034026.php @@ -97,10 +97,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt */ } - if ($schemaChanged) { - return $schema; - } - return null; + return $schemaChanged ? $schema : null; } /**