Skip to content

Commit 1c36ca8

Browse files
author
Colin Viebrock
committed
fix-ups
1 parent 135169d commit 1c36ca8

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

src/MigrationParser.php

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ public function buildStructure()
263263
}
264264

265265
$data['comment'] = trim(str_replace(["\r", "\n"], '', $comment));
266+
if ($data['comment']==='') {
267+
$data['comment'] = null;
268+
}
266269

267270
$this->structure[$field] = $data;
268271
}
@@ -310,21 +313,23 @@ public function buildStructure()
310313
$this->structure['remember_token']['field'] = null;
311314
}
312315

313-
// look for id primary key
314-
if (
315-
array_key_exists('id', $this->structure)
316-
&& $this->structure['id']['method'] === 'integer'
317-
&& $this->structure['id']['autoIncrement'] === true
318-
&& $this->structure['id']['args'] === null
319-
) {
320-
$this->structure['id']['method'] = 'id';
321-
$this->structure['id']['args'] = null;
322-
$this->structure['id']['default'] = null;
323-
$this->structure['id']['nullable'] = false;
324-
$this->structure['id']['field'] = null;
325-
$this->structure['id']['comment'] = null;
326-
$this->structure['id']['autoIncrement'] = null;
327-
$this->structure['id']['unsigned'] = null;
316+
// look for id
317+
foreach ($this->structure as $field=>$struct) {
318+
if (
319+
$struct['method'] === 'bigInteger'
320+
&& $struct['autoIncrement'] === true
321+
&& $struct['args'] === null
322+
) {
323+
$this->structure[$field]['method'] = 'id';
324+
$this->structure[$field]['args'] = null;
325+
$this->structure[$field]['default'] = null;
326+
$this->structure[$field]['nullable'] = false;
327+
$this->structure[$field]['autoIncrement'] = null;
328+
$this->structure[$field]['unsigned'] = null;
329+
if ($field==='id') {
330+
$this->structure[$field]['field'] = null;
331+
}
332+
}
328333
}
329334
}
330335

@@ -393,7 +398,7 @@ public function formatStructure()
393398
}
394399

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

src/foreign_key.stub

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class DummyClass extends Migration
2020
Schema::table('DummyTable', function (Blueprint $table) {
2121
// foreign
2222
});
23-
// extras
2423
}
2524

2625
/**

0 commit comments

Comments
 (0)