Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Currently **not supported**:

* Column types:
* [ ] `float`
* [ ] `decimal`
* [ ] `time`
* [ ] `binary`
* [ ] `boolean`
20 changes: 17 additions & 3 deletions mysql2phinx.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
'name' => $argv[1],
'user' => $argv[2],
'pass' => $argv[3],
'host' => $argc === 5 ? $argv[6] : 'localhost',
'port' => $argc === 6 ? $argv[5] : '3306'
'host' => $argc >= 5 ? $argv[4] : 'localhost',
'port' => $argc >= 6 ? $argv[5] : '3306'
);

function createMigration($mysqli, $indent = 2)
Expand Down Expand Up @@ -148,6 +148,7 @@ function getPhinxColumnType($columndata)
case 'smallint':
case 'int':
case 'mediumint':
case 'bigint':
return 'integer';

case 'timestamp':
Expand All @@ -159,6 +160,9 @@ function getPhinxColumnType($columndata)
case 'datetime':
return 'datetime';

case 'decimal':
return 'decimal';

case 'enum':
return 'enum';

Expand All @@ -167,6 +171,8 @@ function getPhinxColumnType($columndata)

case 'text':
case 'tinytext':
case 'mediumtext':
case 'longtext':
return 'text';

case 'varchar':
Expand Down Expand Up @@ -241,11 +247,19 @@ function getPhinxColumnAttibutes($phinxtype, $columndata)
}

// unsigned
$pattern = '/\(\d+\) unsigned$/';
$pattern = '/\(\d+(\s*,\s*\d+)?\) unsigned$/';
if (1 === preg_match($pattern, $columndata['Type'], $match)) {
$attributes[] = '\'signed\' => false';
}

// decimal values
if ($phinxtype === 'decimal'
&& 1 === preg_match('/decimal\((\d+)\s*,\s*(\d+)\)/i', $columndata['Type'], $decimalMatch)
) {
$attributes[] = '\'precision\' => ' . (int) $decimalMatch[1];
$attributes[] = '\'scale\' => ' . (int) $decimalMatch[2];
}

// enum values
if ($phinxtype === 'enum') {
$attributes[] = '\'values\' => ' . str_replace('enum', 'array', $columndata['Type']);
Expand Down