Skip to content

Instantly share code, notes, and snippets.

@motin
Last active June 29, 2021 17:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save motin/a44281d6c916ab343ece to your computer and use it in GitHub Desktop.
Save motin/a44281d6c916ab343ece to your computer and use it in GitHub Desktop.
<?php
use Propel\Generator\Model\Column;
use Propel\Generator\Model\Database;
use Propel\Generator\Model\ForeignKey;
use Propel\Generator\Model\Index;
use Propel\Generator\Model\Table;
use Propel\Generator\Model\Unique;
use Propel\Generator\Model\PropelTypes;
use Propel\Generator\Model\ColumnDefaultValue;
class MyCustomMysqlSchemaParser extends \Propel\Generator\Reverse\MysqlSchemaParser
{
// Mostly copy-pasted from parent class, except as mentioned in comments below
protected function parseTables(Database $database, $filterTable = null)
{
$sql = 'SHOW FULL TABLES';
if ($filterTable) {
if ($schema = $filterTable->getSchema()) {
$sql .= ' FROM ' . $database->getPlatform()->doQuoting($schema);
}
$sql .= sprintf(" LIKE '%s'", $filterTable->getCommonName());
} else if ($schema = $database->getSchema()) {
$sql .= ' FROM ' . $database->getPlatform()->doQuoting($schema);
}
$dataFetcher = $this->dbh->query($sql);
// First load the tables (important that this happen before filling out details of tables)
$tables = [];
foreach ($dataFetcher as $row) {
$name = $row[0];
$type = $row[1];
// Line changed to include views in reverse-engineered schema.xml (https://github.com/propelorm/Propel/issues/458)
if ($name == $this->getMigrationTable() || !in_array($type, array("BASE TABLE", "VIEW"))) {
continue;
}
$table = new Table($name);
$table->setIdMethod($database->getDefaultIdMethod());
if ($filterTable && $filterTable->getSchema()) {
$table->setSchema($filterTable->getSchema());
}
$database->addTable($table);
$tables[] = $table;
}
}
}
// propel config
return [
'propel' => [
// ...
'migrations' => [
'parserClass' => 'MyCustomMysqlSchemaParser', // Extending \Propel\Generator\Reverse\MysqlSchemaParser
],
// ...
]
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment