Skip to content

Commit f12628c

Browse files
committed
fix: Fix clanked migration
1 parent 4ff9e67 commit f12628c

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
"hybridauth/hybridauth": "~3.0",
3939
"sonata-project/google-authenticator": "~2.3.0",
4040
"wikimedia/common-passwords": "^v0.5",
41-
"ext-json": "*"
41+
"ext-json": "*",
42+
"ext-pdo": "*"
4243
},
4344
"require-dev": {
4445
"phpunit/phpunit": "10.*",

src/Database/Migration/Migration18.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Nails\Auth\Database\Migration;
44

55
use Nails\Common\Console\Migrate\Base;
6+
use PDO;
67

78
class Migration18 extends Base
89
{
@@ -116,9 +117,9 @@ public function execute()
116117
*/
117118
protected function getTableColumns($table)
118119
{
119-
$rows = $this->getAll(sprintf('SHOW COLUMNS FROM `%s`', $table)) ?: [];
120-
$out = [];
121-
foreach ($rows as $r) {
120+
$result = $this->query(sprintf('SHOW COLUMNS FROM `%s`', $table));
121+
$out = [];
122+
foreach ($result->fetchAll(PDO::FETCH_ASSOC) as $r) {
122123
// Expected fields: Field, Type, Null, Key, Default, Extra
123124
$out[$r['Field']] = $r;
124125
}
@@ -130,9 +131,12 @@ protected function getTableColumns($table)
130131
*/
131132
protected function getTableForeignKeys($table)
132133
{
133-
// INFORMATION_SCHEMA works with resolved database name
134-
$db = $this->getOne('SELECT DATABASE()');
135-
$sql = "
134+
$result = $this->query('SELECT DATABASE() as `db`;');
135+
$row = $result->fetch(PDO::FETCH_ASSOC);
136+
$db = $row['db'];
137+
138+
$statement = $this->prepare(
139+
<<<EOT
136140
SELECT
137141
kcu.CONSTRAINT_NAME,
138142
kcu.COLUMN_NAME,
@@ -143,8 +147,12 @@ protected function getTableForeignKeys($table)
143147
kcu.TABLE_SCHEMA = ?
144148
AND kcu.TABLE_NAME = ?
145149
AND kcu.REFERENCED_TABLE_NAME IS NOT NULL
146-
";
147-
$rows = $this->getAll($sql, [$db, $table]) ?: [];
150+
EOT
151+
);
152+
153+
$statement->execute([$db, $table]);
154+
155+
$rows = $statement->fetchAll(PDO::FETCH_ASSOC);
148156
$out = [];
149157
foreach ($rows as $r) {
150158
$out[$r['COLUMN_NAME']][] = $r;

0 commit comments

Comments
 (0)