Skip to content

Commit faa14e1

Browse files
committed
Better primary key detection
1 parent c2dc1c5 commit faa14e1

File tree

5 files changed

+8
-11
lines changed

5 files changed

+8
-11
lines changed

src/PHPFUI/ORM/Record.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
*/
1414
abstract class Record extends DataObject
1515
{
16-
public const ALLOWS_NULL_INDEX = 4;
16+
public const ALLOWS_NULL_INDEX = 3;
1717

18-
public const DEFAULT_INDEX = 5;
19-
20-
public const KEY_INDEX = 3;
18+
public const DEFAULT_INDEX = 4;
2119

2220
public const LENGTH_INDEX = 2;
2321

src/PHPFUI/ORM/Record/Definition/Migration.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ abstract class Migration extends \PHPFUI\ORM\Record
1515

1616
/** @var array<string, array<mixed>> */
1717
protected static array $fields = [
18-
// MYSQL_TYPE, PHP_TYPE, LENGTH, KEY, ALLOWS_NULL, DEFAULT
19-
'migrationId' => ['int(11)', 'int', 11, true, false, null, ],
20-
'ran' => ['timestamp', 'string', 20, false, false, null, ],
18+
// MYSQL_TYPE, PHP_TYPE, LENGTH, ALLOWS_NULL, DEFAULT
19+
'migrationId' => ['int(11)', 'int', 11, false, null, ],
20+
'ran' => ['timestamp', 'string', 20, false, null, ],
2121
];
2222

2323
/** @var array<string, true> */

src/PHPFUI/ORM/Schema/Field.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct(\PHPFUI\ORM\PDOInstance $pdo, array $fields, bool $a
2424
$this->type = \strtolower($fields['Type']);
2525
$this->nullable = 'YES' == $fields['Null'];
2626
$this->defaultValue = $fields['Default'];
27-
$this->primaryKey = 'PRI' == $fields['Key'];
27+
$this->primaryKey = false; // use indexes to find primary keys
2828
$this->autoIncrement = \str_contains($fields['Extra'], 'auto_increment');
2929

3030
return;

src/PHPFUI/ORM/Schema/Index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function __construct(\PHPFUI\ORM\PDOInstance $pdo, array $fields)
1414
{
1515
if (\str_starts_with($pdo->getDSN(), 'mysql'))
1616
{
17-
$this->primaryKey = 'PRIMARY' == $fields['Key_name'] || ! (bool)$fields['Non_unique'];
17+
$this->primaryKey = 'PRIMARY' == $fields['Key_name'];
1818
$this->name = $fields['Column_name'];
1919
$this->extra = \implode(',', $fields);
2020
}

src/PHPFUI/ORM/Tool/Generate/CRUD.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ abstract class ~~CLASS~~ extends \PHPFUI\ORM\Record
3131
3232
/** @var array<string, array<mixed>> */
3333
protected static array $fields = [
34-
// MYSQL_TYPE, PHP_TYPE, LENGTH, KEY, ALLOWS_NULL, DEFAULT
34+
// MYSQL_TYPE, PHP_TYPE, LENGTH, ALLOWS_NULL, DEFAULT
3535
~~FIELD_ARRAY~~ ];
3636
3737
/** @var array<string, true> */
@@ -190,7 +190,6 @@ protected function getLine(\PHPFUI\ORM\Schema\Field $field) : string
190190
$defaultValue = (int)$field->defaultValue;
191191
}
192192

193-
$retVal .= $this->line($field->primaryKey ? 'true' : 'false');
194193
$retVal .= $this->line($allowNulls ? 'true' : 'false');
195194

196195
if (null !== $defaultValue)

0 commit comments

Comments
 (0)