Skip to content

Commit

Permalink
Merge pull request #10 from XCMer/master
Browse files Browse the repository at this point in the history
incorporating changes from the master branch of base repo
  • Loading branch information
Gadoma committed Nov 8, 2013
2 parents 9b0a56f + 51dd5cf commit acc50ea
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Raahul/LarryFour/Command/GenerateFromDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function fire()
foreach ($tables as $table)
{
if( DB::getDriverName() === 'mysql' ) {
$tablesData[ $table ] = DB::select("DESCRIBE $table");
$tablesData[ $table ] = DB::select("DESCRIBE `$table`");
} else if( DB::getDriverName() === 'pgsql' ) {
// PostgreSQL port of MySQL DESCRIBE statement
$tablesData[ $table ] = DB::select(
Expand Down
3 changes: 2 additions & 1 deletion src/Raahul/LarryFour/DbParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ private function createTableMigration($tableName, $columns)
'type' => $type,
'parameters' => $this->getLaravelColumnParameters($column->parameters, $type),
'default' => is_null($column->defaultValue) ? '' : $column->defaultValue,
'unsigned' => $column->unsigned,
'nullable' => $column->null,
'primary' => ( $column->index == 'primary' ),
'unique' => ( $column->index == 'unique' ),
Expand All @@ -110,7 +111,7 @@ private function getLaravelColumnType($column)
}

// Special handling for tinyints with precision 1, that can be bools
if (($column->type == 'tinyint') && ($column->parameters == array(1)))
if (($column->type == 'tinyint'))
{
return 'boolean';
}
Expand Down
6 changes: 6 additions & 0 deletions src/Raahul/LarryFour/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ public function parseFieldDefinitionLine($line, $model, $type)
// Parse the field definition
$parsed = $this->fieldParser->parse(trim($line));

// Check for errors
if (!$parsed)
{
throw new ParseError("Could not parse field line. Check for errors like misplaced quotes.");
}

// Check if the field is timestamps
if ($parsed['type'] == 'timestamps')
{
Expand Down
10 changes: 10 additions & 0 deletions tests/ParseErrorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ public function testRelatedModelNotDefinedError()
$this->assertErrorOutput($input, "Model definition for model \"Profile\" not found, but relation to it is defined in model \"User\"");
}

public function testSegmentParsingError()
{
$input = <<<EOF
User:
access enum "admin","jack","
EOF;

$this->assertErrorOutput($input, "[Line 2] Could not parse field line. Check for errors like misplaced quotes.");
}

private function assertErrorOutput($input, $expectedError)
{
try {
Expand Down

0 comments on commit acc50ea

Please sign in to comment.