Use Doctrines filter by table name

Doctrine's SchemaManager can filter table names by regular expression.
On this way it picks up only ownClouds's tables in a database.

by tbelau666
This commit is contained in:
tbelau666 2014-11-30 23:17:09 +01:00 committed by Morris Jobke
parent 5d296aa6b1
commit ad8d55c327
5 changed files with 17 additions and 6 deletions

View File

@ -228,6 +228,8 @@ class ConvertType extends Command {
} }
protected function getTables(Connection $db) { protected function getTables(Connection $db) {
$db->getConfiguration()->
setFilterSchemaAssetsExpression('/^'.$this->config->getSystemValue('dbtableprefix').'/');
return $db->getSchemaManager()->listTableNames(); return $db->getSchemaManager()->listTableNames();
} }

View File

@ -36,9 +36,7 @@ class MDB2SchemaManager {
* TODO: write more documentation * TODO: write more documentation
*/ */
public function getDbStructure($file, $mode = MDB2_SCHEMA_DUMP_STRUCTURE) { public function getDbStructure($file, $mode = MDB2_SCHEMA_DUMP_STRUCTURE) {
$sm = $this->conn->getSchemaManager(); return \OC_DB_MDB2SchemaWriter::saveSchemaToFile($file, $this->conn);
return \OC_DB_MDB2SchemaWriter::saveSchemaToFile($file, $sm);
} }
/** /**

View File

@ -13,13 +13,17 @@ class OC_DB_MDB2SchemaWriter {
* @param \Doctrine\DBAL\Schema\AbstractSchemaManager $sm * @param \Doctrine\DBAL\Schema\AbstractSchemaManager $sm
* @return bool * @return bool
*/ */
static public function saveSchemaToFile($file, $sm) { static public function saveSchemaToFile($file, $conn) {
$xml = new SimpleXMLElement('<database/>'); $xml = new SimpleXMLElement('<database/>');
$xml->addChild('name', OC_Config::getValue( "dbname", "owncloud" )); $xml->addChild('name', OC_Config::getValue( "dbname", "owncloud" ));
$xml->addChild('create', 'true'); $xml->addChild('create', 'true');
$xml->addChild('overwrite', 'false'); $xml->addChild('overwrite', 'false');
$xml->addChild('charset', 'utf8'); $xml->addChild('charset', 'utf8');
foreach ($sm->listTables() as $table) {
$conn->getConfiguration()->
setFilterSchemaAssetsExpression('/^'.\OCP\Config::getSystemValue('dbtableprefix'.'/'));
foreach ($conn->getSchemaManager()->listTables() as $table) {
self::saveTable($table, $xml->addChild('table')); self::saveTable($table, $xml->addChild('table'));
} }
file_put_contents($file, $xml->asXML()); file_put_contents($file, $xml->asXML());

View File

@ -70,6 +70,8 @@ class Migrator {
*/ */
$tables = $targetSchema->getTables(); $tables = $targetSchema->getTables();
$this->connection->getConfiguration()->
setFilterSchemaAssetsExpression('/^'.\OCP\Config::getSystemValue('dbtableprefix').'/');
$existingTables = $this->connection->getSchemaManager()->listTableNames(); $existingTables = $this->connection->getSchemaManager()->listTableNames();
foreach ($tables as $table) { foreach ($tables as $table) {
@ -153,6 +155,8 @@ class Migrator {
} }
protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) {
$connection->getConfiguration()->
setFilterSchemaAssetsExpression('/^'.\OCP\Config::getSystemValue('dbtableprefix').'/');
$sourceSchema = $connection->getSchemaManager()->createSchema(); $sourceSchema = $connection->getSchemaManager()->createSchema();
// remove tables we don't know about // remove tables we don't know about

View File

@ -21,6 +21,9 @@ class PgSqlTools {
*/ */
public function resynchronizeDatabaseSequences(Connection $conn) { public function resynchronizeDatabaseSequences(Connection $conn) {
$databaseName = $conn->getDatabase(); $databaseName = $conn->getDatabase();
$conn->getConfiguration()->
setFilterSchemaAssetsExpression('/^'.\OCP\Config::getSystemValue('dbtableprefix').'/');
foreach ($conn->getSchemaManager()->listSequences() as $sequence) { foreach ($conn->getSchemaManager()->listSequences() as $sequence) {
$sequenceName = $sequence->getName(); $sequenceName = $sequence->getName();
$sqlInfo = 'SELECT table_schema, table_name, column_name $sqlInfo = 'SELECT table_schema, table_name, column_name