Skip to content

Commit

Permalink
Updates existing migration to improve foreign key handling
Browse files Browse the repository at this point in the history
  • Loading branch information
BenParizek committed Sep 27, 2023
1 parent cb435d2 commit 2855386
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@
namespace BarrelStrength\Sprout\core\migrations;

use craft\db\Migration;
use craft\helpers\Db;

class m230904_000000_remove_source_groups_table extends Migration
{
public const SOURCE_GROUPS_TABLE = '{{%sprout_source_groups}}';

public const DATASETS_TABLE = '{{%sprout_datasets}}';

public function safeUp(): void
{
if ($this->getDb()->tableExists(self::DATASETS_TABLE) && $this->getDb()->columnExists(self::DATASETS_TABLE, 'groupId')) {
$fkName = Db::findForeignKey(self::DATASETS_TABLE, 'groupId');
$this->dropForeignKey($fkName, self::DATASETS_TABLE);
$this->dropColumn(self::DATASETS_TABLE, 'groupId');
}

$this->dropTableIfExists(self::SOURCE_GROUPS_TABLE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace BarrelStrength\Sprout\datastudio\migrations;

use craft\db\Migration;
use craft\helpers\Db;

class m230904_000000_remove_source_groups_column extends Migration
{
Expand All @@ -11,6 +12,8 @@ class m230904_000000_remove_source_groups_column extends Migration
public function safeUp(): void
{
if ($this->getDb()->tableExists(self::DATASETS_TABLE) && $this->getDb()->columnExists(self::DATASETS_TABLE, 'groupId')) {
$fkName = Db::findForeignKey(self::DATASETS_TABLE, 'groupId');
$this->dropForeignKey($fkName, self::DATASETS_TABLE);
$this->dropColumn(self::DATASETS_TABLE, 'groupId');
}
}
Expand Down

0 comments on commit 2855386

Please sign in to comment.