Skip to content

Commit ffa2d9d

Browse files
Fixed column renaming
1 parent 6f628cd commit ffa2d9d

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/Schema/Grammar.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,20 @@ public function compileRename(Blueprint $blueprint, Fluent $command)
233233

234234
return "alter table {$from} rename to ".$this->wrapTable($command->to);
235235
}
236+
237+
/**
238+
* Compile a rename column command.
239+
*
240+
* @param \Illuminate\Database\Schema\Blueprint $blueprint
241+
* @param \Illuminate\Support\Fluent $command
242+
* @param \Illuminate\Database\Connection $connection
243+
* @return array|string
244+
*/
245+
public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Connection $connection)
246+
{
247+
return sprintf('alter table %s change %s %s',
248+
$this->wrapTable($blueprint),
249+
$this->wrap($command->from),
250+
$this->wrap($command->to));
251+
}
236252
}

tests/Hybrid/RenameTableTest.php renamed to tests/Hybrid/RenameTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,36 @@ public function rename_table()
5454
$this->assertCount(1, $statements);
5555
$this->assertEquals('alter table `test` rename to `test_renamed`', $statements[0]);
5656
}
57+
58+
/** @test */
59+
public function rename_column()
60+
{
61+
if ($this->runHybridIntegrations()) {
62+
$cached = $this->mockDatabaseConnection;
63+
64+
$this->mockDatabaseConnection = false;
65+
66+
$this->createTable(function (Blueprint $table) {
67+
$table->id();
68+
$table->string('data');
69+
});
70+
71+
Schema::table('test', function (Blueprint $table) {
72+
$table->renameColumn('data', 'data1');
73+
});
74+
75+
$columnNames = Schema::getColumnListing('test');
76+
$this->assertEquals(['id', 'data1'], $columnNames);
77+
78+
$this->mockDatabaseConnection = $cached;
79+
}
80+
81+
$blueprint = new Blueprint('test');
82+
$blueprint->renameColumn('data', 'data1');
83+
84+
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
85+
86+
$this->assertCount(1, $statements);
87+
$this->assertEquals('alter table `test` change `data` `data1`', $statements[0]);
88+
}
5789
}

0 commit comments

Comments
 (0)