Skip to content

Commit

Permalink
safer migrations
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
julien-nc committed Apr 7, 2024
1 parent 6f88c95 commit 8756307
Show file tree
Hide file tree
Showing 36 changed files with 348 additions and 272 deletions.
15 changes: 9 additions & 6 deletions lib/Migration/Version000102Date20190907142139.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
20 changes: 12 additions & 8 deletions lib/Migration/Version000103Date20190907163755.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 18 additions & 12 deletions lib/Migration/Version000106Date20191023153118.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 9 additions & 6 deletions lib/Migration/Version000201Date20191223203543.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
15 changes: 9 additions & 6 deletions lib/Migration/Version000202Date20191225201436.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
15 changes: 9 additions & 6 deletions lib/Migration/Version000203Date20191227005654.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
15 changes: 9 additions & 6 deletions lib/Migration/Version000204Date20191228201832.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
15 changes: 9 additions & 6 deletions lib/Migration/Version000205Date20200102013739.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
12 changes: 7 additions & 5 deletions lib/Migration/Version000301Date20200108160931.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 14 additions & 10 deletions lib/Migration/Version000302Date20200110144741.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 9 additions & 6 deletions lib/Migration/Version000303Date20200201171814.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
7 changes: 5 additions & 2 deletions lib/Migration/Version000303Date20200201172933.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
15 changes: 9 additions & 6 deletions lib/Migration/Version000304Date20200313092247.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
7 changes: 5 additions & 2 deletions lib/Migration/Version000304Date20200313095955.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
35 changes: 23 additions & 12 deletions lib/Migration/Version000403Date20200231152118.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading

0 comments on commit 8756307

Please sign in to comment.