Table name with space leads to invalid migration script
ravage84 opened this issue · comments
Migrations version: 2.3.7
OS: Windows
PHP: 5.5
A collegue of mine had a space in one of his MySQL table names an tried to generate a migration script.
It was ticket_return_reason_ types
instead of ticket_return_reason_types
.
This lead to an error and an invalid migration script.
app>php Console/cake.php Migrations.migration generate -f
Cake Migration Shell
---------------------------------------------------------------
Parse error: syntax error, unexpected 'types' (T_STRING), expecting ',' or ';' i
n C:\xampp\htdocs\tnw_barakuda\app\Config\Schema\schema.php on line 2514
Call Stack:
0.0010 129160 1. {main}() C:\xampp\htdocs\tnw_barakuda\app\Console\cak
e.php:0
0.0010 194968 2. ShellDispatcher::run() C:\xampp\htdocs\tnw_barakuda\a
pp\Console\cake.php:47
0.0250 1888800 3. ShellDispatcher->dispatch() C:\xampp\htdocs\tnw_barak
uda\lib\Cake\Console\ShellDispatcher.php:66
0.0300 2313216 4. Shell->runCommand() C:\xampp\htdocs\tnw_barakuda\lib\
Cake\Console\ShellDispatcher.php:212
0.0760 4395384 5. MigrationShell->generate() C:\xampp\htdocs\tnw_baraku
da\lib\Cake\Console\Shell.php:451
0.0770 4497792 6. MigrationShell->_getSchema() C:\xampp\htdocs\tnw_bara
kuda\app\Plugin\Migrations\Console\Command\MigrationShell.php:398
Fatal Error Error: syntax error, unexpected 'types' (T_STRING), expecting ',' or
';' in [C:\xampp\htdocs\tnw_barakuda\app\Config\Schema\schema.php, line 2514]
// Property with space in name:
public $ticket_return_reason_ types = array(
// table content
);
I think that should be caught while analyzing the schema, before generating the script, by a regex check and should throw a clear exception message.
Probably there could be other cases of invalid characters in a table name, such as $
or a digit at the beginning of the name.
I agree, we should provide a clear error message because this could be tricky to debug... Thank you,
Hi @ravage84
Thanks for reporting. The issue was in CakePHP core CakeSchema class. Now solved and merged to 2.x (cakephp/cakephp#9555)
Cheers,
Andrej