schema with beans instead of arrays

This commit is contained in:
Jan-Niclas Loosen
2025-02-21 19:06:16 +01:00
parent 13fa680b87
commit 024e6e73cb
13 changed files with 123 additions and 140 deletions

View File

@@ -1,6 +1,7 @@
<?php
namespace DatabaseHelper;
use DatabaseHelper\beans\Schema;
use DatabaseHelper\enums\Propagation;
use DatabaseHelper\enums\Type;
use InvalidArgumentException;
@@ -36,7 +37,7 @@ class Migration
public function modify(string $name, Type $type, mixed $default = null, bool $isNullable = false, bool $isUnique = false): Migration {
$this->schema->requireColumn($name);
if (isset($this->schema->foreignKeys[$name]))
if (isset($this->schema->references[$name]))
throw new InvalidArgumentException('Referencing columns cannot be modified.');
$this->schema->columns[$name] = [
@@ -62,7 +63,7 @@ class Migration
$name = $foreignTable->primaryKey();
$this->schema->requireColumn($name);
$this->schema->foreignKeys[$name] = [
$this->schema->references[$name] = [
'name' => $name,
'table' => $foreignTable->name,
'onDelete' => $onDelete,
@@ -79,7 +80,7 @@ class Migration
if ($this->schema->existsReference($foreignTable))
throw new InvalidArgumentException('Foreign table is not referenced.');
unset($this->schema->foreignKeys[$name]);
unset($this->schema->references[$name]);
$this->drop($name);
$this->foreignKeysToDrop[] = $name;
@@ -131,7 +132,7 @@ class Migration
// Process foreign keys to add.
foreach ($this->foreignKeysToAdd as $key) {
$foreignKey = $this->schema->foreignKeys[$key];
$foreignKey = $this->schema->references[$key];
$clause = " ADD CONSTRAINT `fk_{$foreignKey['name']}`";
$clause .= " FOREIGN KEY (`{$foreignKey['name']}`)";