Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
commands to skip confirmation prompts (@vjik)
- Chg #300: Replace deprecated `self::getDefaultName()` with `$this->getName()` (@Tigrov)
- Enh #301: Add `MigrationBuilder::columnBuilder()` method (@Tigrov)
- Enh #299: Update `MigrationBuilder::update()` method to adapt changes in `yiisoft/db` (@rustamwin)

## 1.2.0 November 27, 2024

Expand Down
16 changes: 12 additions & 4 deletions src/MigrationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Yiisoft\Db\Constant\ReferentialAction;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Expression\ExpressionInterface;
use Yiisoft\Db\Query\QueryInterface;
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
use Yiisoft\Db\Migration\Informer\MigrationInformerInterface;
Expand Down Expand Up @@ -154,18 +155,25 @@ public function upsert(
*
* @param string $table The table to be updated.
* @param array $columns The column data (name => value) to be updated.
* @param array|string $condition The condition to put in the `WHERE` part. Please refer to
* @param array|ExpressionInterface|string $condition The condition to put in the `WHERE` part. Please refer to
* {@see QueryInterface::where()} on how to specify condition.
* @param array|ExpressionInterface|string|null $from The condition to put in the `FROM` part. Please refer to
* {@see QueryInterface::from()} on how to specify condition.
* @param array $params The parameters to be bound to the query.
*
* @throws Exception
* @throws InvalidConfigException
* @throws NotSupportedException
*/
public function update(string $table, array $columns, array|string $condition = '', array $params = []): void
{
public function update(
string $table,
array $columns,
array|ExpressionInterface|string $condition = '',
array|ExpressionInterface|string|null $from = null,
array $params = []
): void {
$time = $this->beginCommand("Update $table");
$this->db->createCommand()->update($table, $columns, $condition, $params)->execute();
$this->db->createCommand()->update($table, $columns, $condition, $from, $params)->execute();
$this->endCommand($time);
}

Expand Down
3 changes: 1 addition & 2 deletions tests/Common/AbstractMigrationBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ public function testUpdate(): void
{
$this->builder->createTable('test', ['id' => ColumnBuilder::primaryKey(), 'name' => ColumnBuilder::string()]);
$this->builder->insert('test', ['name' => 'Ivan']);
$this->builder->update('test', ['name' => 'Petr'], '[[id]]=:id', ['id' => 1]);

$this->builder->update('test', ['name' => 'Petr'], '[[id]]=:id', null, ['id' => 1]);
$this->assertEquals(
[
['id' => '1', 'name' => 'Petr'],
Expand Down
Loading