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 ...@@ -2751,6 +2751,18 @@ abstract class AbstractPlatform
return false; 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. * Whether this platform supports create database.
* *
......
...@@ -164,6 +164,14 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -164,6 +164,14 @@ class PostgreSqlPlatform extends AbstractPlatform
return true; return true;
} }
/**
* {@inheritdoc}
*/
public function getDefaultSchemaName()
{
return 'public';
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
......
...@@ -131,6 +131,14 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -131,6 +131,14 @@ class SQLServerPlatform extends AbstractPlatform
return true; return true;
} }
/**
* {@inheritdoc}
*/
public function getDefaultSchemaName()
{
return 'dbo';
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
......
...@@ -105,7 +105,11 @@ class CreateSchemaSqlCollector extends AbstractVisitor ...@@ -105,7 +105,11 @@ class CreateSchemaSqlCollector extends AbstractVisitor
*/ */
private function getNamespace($asset) 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])) { if ( !isset($this->createTableQueries[$namespace])) {
$this->createTableQueries[$namespace] = array(); $this->createTableQueries[$namespace] = array();
......
...@@ -13,7 +13,7 @@ class CreateSchemaSqlCollectorTest extends \PHPUnit_Framework_TestCase ...@@ -13,7 +13,7 @@ class CreateSchemaSqlCollectorTest extends \PHPUnit_Framework_TestCase
array('supportsSchemas', 'schemaNeedsCreation', 'getCreateTableSQL') array('supportsSchemas', 'schemaNeedsCreation', 'getCreateTableSQL')
); );
$platformMock->expects($this->exactly(1)) $platformMock->expects($this->any())
->method('supportsSchemas') ->method('supportsSchemas')
->will($this->returnValue(true)); ->will($this->returnValue(true));
...@@ -32,6 +32,6 @@ class CreateSchemaSqlCollectorTest extends \PHPUnit_Framework_TestCase ...@@ -32,6 +32,6 @@ class CreateSchemaSqlCollectorTest extends \PHPUnit_Framework_TestCase
$sqlCollector = new CreateSchemaSqlCollector($platformMock); $sqlCollector = new CreateSchemaSqlCollector($platformMock);
$sqlCollector->acceptTable($tableMock); $sqlCollector->acceptTable($tableMock);
$sql = $sqlCollector->getQueries(); $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