Skip to content

Commit

Permalink
Refactor DB migrations to use humhub\components\Migration with safe m…
Browse files Browse the repository at this point in the history
…ethods
  • Loading branch information
marc-farre committed May 13, 2024
1 parent 4ac4696 commit 9069e38
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 45 deletions.
22 changes: 3 additions & 19 deletions migrations/m200212_175551_initial.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use yii\db\Migration;
use humhub\components\Migration;

/**
* Class m200212_175551_initial
Expand All @@ -12,7 +12,7 @@ class m200212_175551_initial extends Migration
*/
public function safeUp()
{
$this->createTable('external_websites_website', [
$this->safeCreateTable('external_websites_website', [
'id' => $this->primaryKey(),
'space_id' => $this->integer(11)->notNull(),
'title' => $this->string(255),
Expand All @@ -30,7 +30,7 @@ public function safeUp()
'updated_at' => $this->dateTime(),
'updated_by' => $this->integer(11),
], '');
$this->createTable('external_websites_website_page', [
$this->safeCreateTable('external_websites_website_page', [
'id' => $this->primaryKey(),
'title' => $this->string(255),
'page_url' => $this->text(),
Expand All @@ -51,20 +51,4 @@ public function safeDown()

return false;
}


/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m200212_175551_initial cannot be reverted.\n";
return false;
}
*/
}
2 changes: 1 addition & 1 deletion migrations/m210608_145036_remove_fa_from_icon_values.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use humhub\modules\externalWebsites\models\Website;
use yii\db\Migration;
use humhub\components\Migration;

/**
* Class m210608_145036_remove_fa_from_icon_values
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use yii\db\Migration;
use humhub\components\Migration;

/**
* Handles adding columns to table `{{%external_websites_website_page}}`.
Expand All @@ -12,7 +12,7 @@ class m220303_193035_add_other_website_ids_column_to_external_websites_website_p
*/
public function safeUp()
{
$this->addColumn('{{%external_websites_website_page}}', 'other_website_ids', $this->text()->after('website_id'));
$this->safeAddColumn('{{%external_websites_website_page}}', 'other_website_ids', $this->text()->after('website_id'));
}

/**
Expand All @@ -21,5 +21,7 @@ public function safeUp()
public function safeDown()
{
echo "m220303_193035_add_other_website_ids_column_to_external_websites_website_page_table cannot be reverted.\n";

return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use yii\db\Migration;
use humhub\components\Migration;

/**
* Class m220303_210819_add_page_url_params_to_remove_to_external_websites_website_table
Expand All @@ -12,7 +12,7 @@ class m220303_210819_add_page_url_params_to_remove_to_external_websites_website_
*/
public function safeUp()
{
$this->addColumn('{{%external_websites_website}}', 'page_url_params_to_remove', $this->text()->after('first_page_url'));
$this->safeAddColumn('{{%external_websites_website}}', 'page_url_params_to_remove', $this->text()->after('first_page_url'));
}

/**
Expand Down
21 changes: 3 additions & 18 deletions migrations/m230325_104344_replace_hide_sidebar_with_layout.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use humhub\components\Migration;
use humhub\modules\externalWebsites\models\Website;
use yii\db\Migration;

/**
* Class m230325_104344_replace_hide_sidebar_with_layout
Expand All @@ -13,8 +13,8 @@ class m230325_104344_replace_hide_sidebar_with_layout extends Migration
*/
public function safeUp()
{
$this->dropColumn('{{%external_websites_website}}', 'hide_sidebar');
$this->addColumn('{{%external_websites_website}}', 'layout', $this->string(127)->after('sort_order'));
$this->safeDropColumn('{{%external_websites_website}}', 'hide_sidebar');
$this->safeAddColumn('{{%external_websites_website}}', 'layout', $this->string(127)->after('sort_order'));

/** @var Website $website */
foreach (Website::find()->each() as $website) {
Expand All @@ -32,19 +32,4 @@ public function safeDown()

return false;
}

/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m230325_104344_replace_hide_sidebar_with_layout cannot be reverted.\n";
return false;
}
*/
}
6 changes: 3 additions & 3 deletions migrations/uninstall.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

use yii\db\Migration;
use humhub\components\Migration;

class uninstall extends Migration
{

public function up()
{
$this->dropTable('external_websites_website');
$this->dropTable('external_websites_website_page');
$this->safeDropTable('external_websites_website');
$this->safeDropTable('external_websites_website_page');
}

public function down()
Expand Down

0 comments on commit 9069e38

Please sign in to comment.