Commit 38baf090 authored by okhin's avatar okhin 🚴

Let's have an up and down migration

parent 070ca0af
Pipeline #2334 passed with stages
in 1 minute and 37 seconds
...@@ -30,17 +30,29 @@ class AddParentField extends AbstractMigration ...@@ -30,17 +30,29 @@ class AddParentField extends AbstractMigration
* Remember to call "create()" or "update()" and NOT "save()" when working * Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class. * with the Table class.
*/ */
public function change() public function up()
{ {
$table = $this->table('contreparties'); $table = $this->table('contreparties');
$table->addColumn('parent', 'integer'); if (!$table->hasColumn('parent')) {
$table->update(); $table->addColumn('parent', 'integer');
$table->save();
}
// Let's set some default value // Let's set some default value
$builder = $this->getQueryBuilder(); $builder = $this->getQueryBuilder();
$stmt = $builder->update('contreparties') $stmt = $builder->update('contreparties', 'c')
->set('parent', 'id') ->set('parent', 'id')
->where(['parent' => '']) // ->where('parent = 0')
->execute(); ->execute();
} }
public function down()
{
$table = $this->table('contreparties');
if ($table->hasColumn('parent')) {
$table->removeColumn('parent')
->save();
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment