Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration & MySql Query addCheck() and dropCheck() #19881

Merged
merged 18 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Yii Framework 2 Change Log
- New #20137: Added `yii\caching\CallbackDependency` to allow using a callback to determine if a cache dependency is still valid (laxity7)
- Enh #20134: Raise minimum `PHP` version to `7.3` (@terabytesoftw)
- Bug #20141: Update `ezyang/htmlpurifier` dependency to version `4.17` (@terabytesoftw)
- Bug #19817: Add MySQL Query `addCheck()` and `dropCheck()` (@bobonov)

2.0.49.2 October 12, 2023
-------------------------
Expand Down
31 changes: 30 additions & 1 deletion framework/db/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,35 @@ public function dropIndex($name, $table)
$this->endCommand($time);
}

/**
* Creates a SQL command for adding a check constraint to an existing table.
* @param string $name the name of the check constraint.
* The name will be properly quoted by the method.
* @param string $table the table that the check constraint will be added to.
* The name will be properly quoted by the method.
* @param string $expression the SQL of the `CHECK` constraint.
*/
public function addCheck($name, $table, $expression)
{
$time = $this->beginCommand("add check $name in table $table");
$this->db->createCommand()->addCheck($name, $table, $expression)->execute();
$this->endCommand($time);
}

/**
* Creates a SQL command for dropping a check constraint.
* @param string $name the name of the check constraint to be dropped.
* The name will be properly quoted by the method.
* @param string $table the table whose check constraint is to be dropped.
* The name will be properly quoted by the method.
*/
public function dropCheck($name, $table)
{
$time = $this->beginCommand("drop check $name in table $table");
$this->db->createCommand()->dropCheck($name, $table)->execute();
$this->endCommand($time);
}

/**
* Builds and execute a SQL statement for adding comment to column.
*
Expand All @@ -530,7 +559,7 @@ public function dropIndex($name, $table)
*/
public function addCommentOnColumn($table, $column, $comment)
{
$time = $this->beginCommand("add comment on column $column");
$time = $this->beginCommand("drop comment on column $column");
terabytesoftw marked this conversation as resolved.
Show resolved Hide resolved
$this->db->createCommand()->addCommentOnColumn($table, $column, $comment)->execute();
$this->endCommand($time);
}
Expand Down
18 changes: 0 additions & 18 deletions framework/db/mysql/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,24 +151,6 @@ public function dropUnique($name, $table)
return $this->dropIndex($name, $table);
}

/**
* {@inheritdoc}
* @throws NotSupportedException this is not supported by MySQL.
*/
public function addCheck($name, $table, $expression)
{
throw new NotSupportedException(__METHOD__ . ' is not supported by MySQL.');
}

/**
* {@inheritdoc}
* @throws NotSupportedException this is not supported by MySQL.
*/
public function dropCheck($name, $table)
{
throw new NotSupportedException(__METHOD__ . ' is not supported by MySQL.');
}

/**
* Creates a SQL statement for resetting the sequence value of a table's primary key.
* The sequence will be reset such that the primary key of the next new row inserted
Expand Down
Loading