Skip to content

Commit 32de167

Browse files
author
Colin Viebrock
committed
Various fixes and improvements, version bump
1 parent bae09d2 commit 32de167

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

.semver

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
:major: 1
3-
:minor: 6
3+
:minor: 7
44
:patch: 0
55
:special: ''

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
# Changelog
22

3+
## 1.7.0 - 09-Mar-2020
4+
5+
- Adds support for timestamp columns with `ON UPDATE CURRENT_TIMESTAMP`
6+
- suppresses `->characterSet()` and `->collation()` on text columns
7+
that share the table's default character set and/or collation
8+
- removes some extra blank lines from the resulting migration file
9+
- a bit of code cleanup
10+
11+
312
## 1.6.0 - 20-Jan-2020
413

514
- Adds charset and collation information for tables/columns
615
- Fix for default values being double-quoted
716

17+
818
## 1.5.0 - 24-Feb-2019
919

1020
- Fixes for:

ExportToLaravelMigration.spBundle/MigrationParser.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
class MigrationParser
44
{
55

6+
const TS_UPDATE_STRING = 'ON UPDATE CURRENT_TIMESTAMP';
7+
68
/**
79
* @var string
810
*/
9-
protected $version = '1.6.0';
11+
protected $version = '1.7.0';
1012

1113
/**
1214
* @var array
@@ -94,10 +96,10 @@ public function __construct($tableName, $structureFile, $keysFile, $constraintsF
9496

9597
public function makeMigration()
9698
{
99+
$this->buildTableCollationAndCharset();
97100
$this->buildStructure();
98101
$this->buildKeys();
99102
$this->buildConstraints();
100-
$this->buildTableCollationAndCharset();
101103

102104
$indent8 = str_repeat(' ', 8);
103105
$indent12 = str_repeat(' ', 12);
@@ -119,6 +121,8 @@ public function makeMigration()
119121
$output
120122
);
121123

124+
$output = preg_replace("/^(\s*\R){2,}/m", "\n", $output);
125+
122126
return $output;
123127
}
124128

@@ -156,8 +160,8 @@ public function buildStructure()
156160
'field' => $field,
157161
'nullable' => ($null === 'YES'),
158162
'default' => ($default !== 'NULL') ? $default : null,
159-
'characterSet' => ($characterSet !== 'NULL') ? $characterSet : null,
160-
'collation' => ($collation !== 'NULL') ? $collation : null,
163+
'characterSet' => ($characterSet !== 'NULL' && $characterSet !== $this->tableCharset) ? $characterSet : null,
164+
'collation' => ($collation !== 'NULL' && $collation !== $this->tableCollation) ? $collation : null,
161165
'_colType' => $colType,
162166
];
163167

@@ -232,6 +236,11 @@ public function formatStructure()
232236
|| $method === 'double'
233237
|| $method === 'float';
234238

239+
if ($method==='timestamp' && $data['args'] === self::TS_UPDATE_STRING) {
240+
$data['default'] = $data['default'] . ' ' . $data['args'];
241+
$data['args'] = null;
242+
}
243+
235244
$temp = '$table->' . $method;
236245
if ($data['field']) {
237246
$temp .= '(\'' . $field . '\'';
@@ -259,8 +268,8 @@ public function formatStructure()
259268
$temp .= '->default(' . $data['default'] . ')';
260269
} elseif ($method==='boolean') {
261270
$temp .= '->default(' . ($data['default'] ? 'true' : 'false') . ')';
262-
} elseif (strtolower(trim($data['default'])) === 'current_timestamp') {
263-
$temp .= '->default(\DB::raw(\'CURRENT_TIMESTAMP\'))';
271+
} elseif (stripos(trim($data['default']), 'CURRENT_TIMESTAMP') !==false) {
272+
$temp .= '->default(\DB::raw(\'' . trim($data['default']) . '\'))';
264273
} else {
265274
$temp .= '->default(\'' . $this->trimStringQuotes($data['default']) . '\')';
266275
}
@@ -405,9 +414,6 @@ public function buildTableCollationAndCharset()
405414
{
406415
$this->constraints = [];
407416

408-
$rows = file($this->constraintsFile);
409-
array_shift($rows);
410-
411417
$rows = file($this->tableCharsetAndCollationFile);
412418
array_shift($rows);
413419

@@ -439,13 +445,6 @@ protected function copyToClipboard($content)
439445
shell_exec($cmd);
440446
}
441447

442-
protected function extractSize($string)
443-
{
444-
if (preg_match('#\(([^)]+)\)#', $string, $m)) {
445-
return $m[1];
446-
}
447-
}
448-
449448
protected function escapeArray($array)
450449
{
451450
$array = (array)$array;
@@ -585,6 +584,9 @@ protected function parseTime($type, $args, $typeExtra, $extra)
585584

586585
protected function parseTimestamp($type, $args, $typeExtra, $extra)
587586
{
587+
if (stripos($extra, self::TS_UPDATE_STRING) !==false) {
588+
$args = self::TS_UPDATE_STRING;
589+
}
588590
return $this->defaultParse('timestamp', $args);
589591
}
590592

0 commit comments

Comments
 (0)