Skip to content

Commit

Permalink
fix-ups
Browse files Browse the repository at this point in the history
  • Loading branch information
Colin Viebrock committed Dec 28, 2020
1 parent 135169d commit 1c36ca8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
37 changes: 21 additions & 16 deletions src/MigrationParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ public function buildStructure()
}

$data['comment'] = trim(str_replace(["\r", "\n"], '', $comment));
if ($data['comment']==='') {
$data['comment'] = null;
}

$this->structure[$field] = $data;
}
Expand Down Expand Up @@ -310,21 +313,23 @@ public function buildStructure()
$this->structure['remember_token']['field'] = null;
}

// look for id primary key
if (
array_key_exists('id', $this->structure)
&& $this->structure['id']['method'] === 'integer'
&& $this->structure['id']['autoIncrement'] === true
&& $this->structure['id']['args'] === null
) {
$this->structure['id']['method'] = 'id';
$this->structure['id']['args'] = null;
$this->structure['id']['default'] = null;
$this->structure['id']['nullable'] = false;
$this->structure['id']['field'] = null;
$this->structure['id']['comment'] = null;
$this->structure['id']['autoIncrement'] = null;
$this->structure['id']['unsigned'] = null;
// look for id
foreach ($this->structure as $field=>$struct) {
if (
$struct['method'] === 'bigInteger'
&& $struct['autoIncrement'] === true
&& $struct['args'] === null
) {
$this->structure[$field]['method'] = 'id';
$this->structure[$field]['args'] = null;
$this->structure[$field]['default'] = null;
$this->structure[$field]['nullable'] = false;
$this->structure[$field]['autoIncrement'] = null;
$this->structure[$field]['unsigned'] = null;
if ($field==='id') {
$this->structure[$field]['field'] = null;
}
}
}
}

Expand Down Expand Up @@ -393,7 +398,7 @@ public function formatStructure()
}

// If isn't empty, set the comment
if ($data['comment'] !== '' || $data['comment'] !== null) {
if ($data['comment'] !== null) {
$temp .= '->comment(\'' . addslashes($data['comment']) . '\')';
}

Expand Down
1 change: 0 additions & 1 deletion src/foreign_key.stub
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class DummyClass extends Migration
Schema::table('DummyTable', function (Blueprint $table) {
// foreign
});
// extras
}

/**
Expand Down

0 comments on commit 1c36ca8

Please sign in to comment.