Skip to content

Commit b47dff3

Browse files
Merge pull request #65 from singlestore-labs/ISSUE-63
Fixed column renaming
2 parents 9971238 + e37fd73 commit b47dff3

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/Schema/Grammar.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,17 @@ 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+
* @return array|string
241+
*/
242+
public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Connection $connection)
243+
{
244+
return sprintf('alter table %s change %s %s',
245+
$this->wrapTable($blueprint),
246+
$this->wrap($command->from),
247+
$this->wrap($command->to));
248+
}
236249
}

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)