Skip to content

Commit

Permalink
Ignoring table partitions definitions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Cima committed Apr 13, 2016
1 parent 91269d5 commit 10428b8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function parseTables($sqlScript)

$table = new Table($name);
$table->setDefinition(trim($definition));
$table->setCreationScript(trim($creationScript));
$table->setCreationScript(trim($creationScript) . ';');

if ($engine) {
$table->setEngine($engine);
Expand Down
9 changes: 5 additions & 4 deletions src/RegExpPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ class RegExpPattern
public static function tables()
{
$pattern = '/(?<creationScript>CREATE\s+TABLE\s+`(?<tableName>\S+)`\s+';
$pattern .= '\((?<tableDefinition>[^;]+)\)';
$pattern .= '(?:\s+ENGINE=(?<engine>\S+))?\s*';
$pattern .= '\((?<tableDefinition>[^;\/]+)\)';
$pattern .= '(?:\s+ENGINE=(?<engine>[^;\s]+))?\s*';
$pattern .= '(?:AUTO_INCREMENT=(?<autoIncrement>\d+))?\s*';
$pattern .= '(?:DEFAULT CHARSET=(?<defaultCharset>\S+))?\s*';
$pattern .= ';)/';
$pattern .= '(?:DEFAULT CHARSET=(?<defaultCharset>[^;\s]+))?\s*)';
$pattern .= '(?:\/\*.+?\*\/)?\s*';
$pattern .= ';/';
$pattern .= 's'; // modifier

return $pattern;
Expand Down
13 changes: 12 additions & 1 deletion tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,15 @@ public function testIsGeneratingTableCreationScript()
$this->assertEquals($table->getCreationScript(), $table->generateCreationScript(false, false));
}
}
}

public function testIsParsingTableWithPartitionDefinitions()
{
$parser = new Parser();

$database = $parser->parseDatabase($this->getDatabaseFixture('partition.sql'));

$this->assertInstanceOf(Database::class, $database);
$this->assertCount(1, $database->getTables());
$this->assertCount(9, $database->getTableByName('export')->getColumns());
}
}
21 changes: 21 additions & 0 deletions tests/fixtures/partition.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `export` (
`id_export` int(10) unsigned NOT NULL AUTO_INCREMENT,
`export_type` varchar(50) NOT NULL,
`filename` varchar(255) NOT NULL DEFAULT '',
`file_content` longblob NOT NULL,
`generated_at` datetime NOT NULL,
`downloaded_at` datetime DEFAULT NULL,
`generated_by` varchar(50) NOT NULL DEFAULT '',
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id_export`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE (id_export)
(PARTITION p0 VALUES LESS THAN (1000) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN (2000) ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN (3000) ENGINE = InnoDB,
PARTITION p3 VALUES LESS THAN (4000) ENGINE = InnoDB,
PARTITION p4 VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */;
/*!40101 SET character_set_client = @saved_cs_client */;

0 comments on commit 10428b8

Please sign in to comment.