Skip to content

Commit 2e54570

Browse files
committed
addPrimaryKey
1 parent 0ff4da0 commit 2e54570

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/PHPFUI/ORM/Migration.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,18 @@ protected function addIndex(string $table, string | array $fields, string $index
226226
return $this->runSQL($sql);
227227
}
228228

229+
/**
230+
* Adds a primary key to the table.
231+
*/
232+
protected function addPrimaryKey(string $table, array $fields) : bool
233+
{
234+
$this->dropPrimaryKey($table);
235+
$keys = implode('`, `', $fields);
236+
$this->alters[$table] = ["ADD PRIMARY KEY (`{$keys}`)"];
237+
238+
return true;
239+
}
240+
229241
/**
230242
* Adds a primary key to the table. If $field is not specified, it will the primary key will be the table name with Id appended. If $newFieldName is not specified, it will default to $field. This method works on an existing field only.
231243
*/

0 commit comments

Comments
 (0)