Skip to content

Commit

Permalink
Add missing array cast in SqliteAdapter
Browse files Browse the repository at this point in the history
Add an array cast to SqliteAdapter to fix compatibility issue with
phinx/table.

Fixes #804
  • Loading branch information
markstory committed Jan 14, 2025
1 parent c88055d commit ae1ae36
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/Db/Adapter/SqliteAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,10 @@ public function createTable(Table $table, array $columns = [], array $indexes =

$sql = 'CREATE TABLE ';
$sql .= $this->quoteTableName($table->getName()) . ' (';
if (isset($options['primary_key'])) {
$options['primary_key'] = (array)$options['primary_key'];
}

foreach ($columns as $column) {
$sql .= $this->quoteColumnName((string)$column->getName()) . ' ' . $this->getColumnSqlDefinition($column) . ', ';

Expand Down
9 changes: 3 additions & 6 deletions tests/TestCase/Db/Adapter/SqliteAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,17 +360,14 @@ public function testCreateTableWithoutAutoIncrementingPrimaryKeyAndWithForeignKe

public function testAddPrimaryKey()
{
$table = new Table('table1', ['id' => false], $this->adapter);
$table = new Table('table1', [], $this->adapter);
$table
->addColumn('column1', 'integer')
->addColumn('column2', 'integer')
->addPrimaryKey('id')
->save();

$table
->changePrimaryKey('column1')
->save();

$this->assertTrue($this->adapter->hasPrimaryKey('table1', ['column1']));
$this->assertTrue($this->adapter->hasPrimaryKey('table1', ['id']));
}

public function testChangePrimaryKey()
Expand Down

0 comments on commit ae1ae36

Please sign in to comment.