From addb770d81a47441786e816cb8e4baed614e9bc4 Mon Sep 17 00:00:00 2001 From: Magnus Backhurst Date: Fri, 5 May 2017 23:03:38 +0200 Subject: [PATCH 1/4] Added bigint type to column type integer. --- mysql2phinx.php | 1 + 1 file changed, 1 insertion(+) diff --git a/mysql2phinx.php b/mysql2phinx.php index d505e64..293f061 100644 --- a/mysql2phinx.php +++ b/mysql2phinx.php @@ -148,6 +148,7 @@ function getPhinxColumnType($columndata) case 'smallint': case 'int': case 'mediumint': + case 'bigint': return 'integer'; case 'timestamp': From e81f219e9f8b5abc4ea444d4354d9a6de7751090 Mon Sep 17 00:00:00 2001 From: Magnus Backhurst Date: Sat, 6 May 2017 14:08:03 +0200 Subject: [PATCH 2/4] Added support for decimal column type with precision and scale. --- README.md | 1 - mysql2phinx.php | 13 ++++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 012ca5e..3ade807 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,6 @@ Currently **not supported**: * Column types: * [ ] `float` - * [ ] `decimal` * [ ] `time` * [ ] `binary` * [ ] `boolean` diff --git a/mysql2phinx.php b/mysql2phinx.php index 293f061..69de494 100644 --- a/mysql2phinx.php +++ b/mysql2phinx.php @@ -160,6 +160,9 @@ function getPhinxColumnType($columndata) case 'datetime': return 'datetime'; + case 'decimal': + return 'decimal'; + case 'enum': return 'enum'; @@ -242,11 +245,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']); From f38b882e1ae21882cd65859d884d6fb543e5c67b Mon Sep 17 00:00:00 2001 From: Magnus Backhurst Date: Sat, 6 May 2017 14:18:51 +0200 Subject: [PATCH 3/4] Added mediumtext and longtext types to column type text. --- mysql2phinx.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mysql2phinx.php b/mysql2phinx.php index 69de494..4969a91 100644 --- a/mysql2phinx.php +++ b/mysql2phinx.php @@ -171,6 +171,8 @@ function getPhinxColumnType($columndata) case 'text': case 'tinytext': + case 'mediumtext': + case 'longtext': return 'text'; case 'varchar': From 42dd613749d1a5a0ace1106ff59a75499fb16e05 Mon Sep 17 00:00:00 2001 From: Magnus Backhurst Date: Sat, 6 May 2017 17:07:51 +0200 Subject: [PATCH 4/4] Changed the handling of host and port parameter to work as I think was intended. --- mysql2phinx.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql2phinx.php b/mysql2phinx.php index 4969a91..5bd58f4 100644 --- a/mysql2phinx.php +++ b/mysql2phinx.php @@ -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)