Commit 3c811d7d authored by Guilherme Blanco's avatar Guilherme Blanco

Merge pull request #376 from flip111/patch-3

Update CreateSchemaSqlCollector.php setting default namespace/schema nam...
parents a67755c2 fd50553d
......@@ -2751,6 +2751,18 @@ abstract class AbstractPlatform
return false;
}
/**
* Returns the default schema name.
*
* @return string
*
* @throws \Doctrine\DBAL\DBALException If not supported on this platform.
*/
public function getDefaultSchemaName()
{
throw DBALException::notSupported(__METHOD__);
}
/**
* Whether this platform supports create database.
*
......
......@@ -164,6 +164,14 @@ class PostgreSqlPlatform extends AbstractPlatform
return true;
}
/**
* {@inheritdoc}
*/
public function getDefaultSchemaName()
{
return 'public';
}
/**
* {@inheritDoc}
*/
......
......@@ -131,6 +131,14 @@ class SQLServerPlatform extends AbstractPlatform
return true;
}
/**
* {@inheritdoc}
*/
public function getDefaultSchemaName()
{
return 'dbo';
}
/**
* {@inheritDoc}
*/
......
......@@ -105,7 +105,11 @@ class CreateSchemaSqlCollector extends AbstractVisitor
*/
private function getNamespace($asset)
{
$namespace = $asset->getNamespaceName() ?: 'default';
$namespace = $asset->getNamespaceName();
if ( !isset($namespace)) {
$namespace = $this->platform->supportsSchemas() ? $this->platform->getDefaultSchemaName() : 'default';
}
if ( !isset($this->createTableQueries[$namespace])) {
$this->createTableQueries[$namespace] = array();
......
......@@ -13,7 +13,7 @@ class CreateSchemaSqlCollectorTest extends \PHPUnit_Framework_TestCase
array('supportsSchemas', 'schemaNeedsCreation', 'getCreateTableSQL')
);
$platformMock->expects($this->exactly(1))
$platformMock->expects($this->any())
->method('supportsSchemas')
->will($this->returnValue(true));
......@@ -32,6 +32,6 @@ class CreateSchemaSqlCollectorTest extends \PHPUnit_Framework_TestCase
$sqlCollector = new CreateSchemaSqlCollector($platformMock);
$sqlCollector->acceptTable($tableMock);
$sql = $sqlCollector->getQueries();
$this->assertEquals('CREATE SCHEMA default', $sql[0]);
$this->assertEquals('CREATE SCHEMA public', $sql[0]);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment