Skip to content

Commit 0164ea0

Browse files
authored
Merge pull request #359 from bowphp/refactor/code-base
Fix migration query builder
2 parents eaf2e6a + b5670f7 commit 0164ea0

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

src/Database/Migration/Migration.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,16 @@ final public function alter(string $table, callable $cb, bool $displayInfo = tru
203203
$generator = new Table($table, $this->adapter->getName(), 'alter')
204204
]);
205205

206+
$sql_definition = $generator->make();
207+
206208
if ($this->adapter->getName() === 'pgsql') {
207-
$sql = sprintf('ALTER TABLE %s %s;', $table, $generator->make());
209+
$sql = sprintf('ALTER TABLE %s %s;', $table, $sql_definition);
208210
} else {
209-
$sql = sprintf('ALTER TABLE `%s` %s;', $table, $generator->make());
211+
$sql = sprintf('ALTER TABLE `%s` %s;', $table, $sql_definition);
212+
}
213+
214+
if (empty($sql_definition)) {
215+
return $this;
210216
}
211217

212218
return $this->executeSqlQuery($sql, $displayInfo);
@@ -218,12 +224,25 @@ final public function alter(string $table, callable $cb, bool $displayInfo = tru
218224
* @param string $sql
219225
* @return Migration
220226
* @throws MigrationException
227+
* @deprecated Use sql() instead.
221228
*/
222229
final public function addSql(string $sql): Migration
223230
{
224231
return $this->executeSqlQuery($sql);
225232
}
226233

234+
/**
235+
* Execute SQL query
236+
*
237+
* @param string $sql
238+
* @return Migration
239+
* @throws MigrationException
240+
*/
241+
final public function sql(string $sql): Migration
242+
{
243+
return $this->executeSqlQuery($sql);
244+
}
245+
227246
/**
228247
* Rename table
229248
*

0 commit comments

Comments
 (0)