Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
fabe3c34
Commit
fabe3c34
authored
Aug 05, 2013
by
Jakub Zienkiewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support schema creation for psql platform
parent
2a7f59c1
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
118 additions
and
3 deletions
+118
-3
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+26
-0
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+16
-0
CreateSchemaSqlCollector.php
...Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php
+3
-2
AbstractPlatformTestCase.php
...octrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
+16
-0
PostgreSqlPlatformTest.php
.../Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php
+20
-1
CreateSchemaSqlCollectorTest.php
...ests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php
+37
-0
No files found.
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
fabe3c34
...
...
@@ -1487,6 +1487,32 @@ abstract class AbstractPlatform
return
'ALTER TABLE '
.
$table
.
' ADD PRIMARY KEY ('
.
$this
->
getIndexFieldDeclarationListSQL
(
$index
->
getQuotedColumns
(
$this
))
.
')'
;
}
/**
* Returns the SQL to create a named schema.
*
* @param string $schemaName
*
* @return string
* @throws \Doctrine\DBAL\DBALException If not supported on this platform.
*/
public
function
getCreateSchemaSQL
(
$schemaName
)
{
throw
DBALException
::
notSupported
(
__METHOD__
);
}
/**
* Checks whether the schema $schemaName needs creating.
*
* @param string $schemaName
*
* @return boolean
* @throws \Doctrine\DBAL\DBALException If not supported on this platform.
*/
public
function
schemaNeedsCreation
(
$schemaName
)
{
throw
DBALException
::
notSupported
(
__METHOD__
);
}
/**
* Quotes a string so that it can be safely used as a table or column name,
* even if it is a reserved word of the platform. This also detects identifier
...
...
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
fabe3c34
...
...
@@ -531,6 +531,22 @@ class PostgreSqlPlatform extends AbstractPlatform
return
'DROP SEQUENCE '
.
$sequence
.
' CASCADE'
;
}
/**
* {@inheritDoc}
*/
public
function
getCreateSchemaSQL
(
$schemaName
)
{
return
'CREATE SCHEMA '
.
$schemaName
;
}
/**
* {@inheritDoc}
*/
public
function
schemaNeedsCreation
(
$schemaName
)
{
return
!
in_array
(
$schemaName
,
array
(
'default'
,
'public'
));
}
/**
* {@inheritDoc}
*/
...
...
lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php
View file @
fabe3c34
...
...
@@ -135,8 +135,9 @@ class CreateSchemaSqlCollector extends AbstractVisitor
$sql
=
array
();
foreach
(
array_keys
(
$this
->
createTableQueries
)
as
$namespace
)
{
if
(
$this
->
platform
->
supportsSchemas
())
{
// TODO: Create Schema here
if
(
$this
->
platform
->
supportsSchemas
()
&&
$this
->
platform
->
schemaNeedsCreation
(
$namespace
))
{
$query
=
$this
->
platform
->
getCreateSchemaSQL
(
$namespace
);
array_push
(
$sql
,
$query
);
}
}
...
...
tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
View file @
fabe3c34
...
...
@@ -494,4 +494,20 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$sql
=
$this
->
_platform
->
getCreateTableSQL
(
$table
,
AbstractPlatform
::
CREATE_FOREIGNKEYS
);
$this
->
assertEquals
(
$this
->
getQuotedColumnInForeignKeySQL
(),
$sql
);
}
/**
* @expectedException \Doctrine\DBAL\DBALException
*/
public
function
testGetCreateSchemaSQL
()
{
$this
->
_platform
->
getCreateSchemaSQL
(
'schema'
);
}
/**
* @expectedException \Doctrine\DBAL\DBALException
*/
public
function
testSchemaNeedsCreation
()
{
$this
->
_platform
->
schemaNeedsCreation
(
'schema'
);
}
}
tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php
View file @
fabe3c34
...
...
@@ -314,5 +314,24 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase
$this
->
assertEquals
(
'1'
,
$platform
->
convertBooleans
(
true
));
$this
->
assertEquals
(
'0'
,
$platform
->
convertBooleans
(
false
));
}
}
public
function
testGetCreateSchemaSQL
()
{
$schemaName
=
'schema'
;
$sql
=
$this
->
_platform
->
getCreateSchemaSQL
(
$schemaName
);
$this
->
assertEquals
(
'CREATE SCHEMA '
.
$schemaName
,
$sql
);
}
public
function
testSchemaNeedsCreation
()
{
$schemaNames
=
array
(
'default'
=>
false
,
'public'
=>
false
,
'schema'
=>
true
,
);
foreach
(
$schemaNames
as
$name
=>
$expected
)
{
$actual
=
$this
->
_platform
->
schemaNeedsCreation
(
$name
);
$this
->
assertEquals
(
$expected
,
$actual
);
}
}
}
tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php
0 → 100644
View file @
fabe3c34
<?php
namespace
Doctrine\Tests\DBAL\Schema\Visitor
;
use
\Doctrine\DBAL\Schema\Visitor\CreateSchemaSqlCollector
;
class
CreateSchemaSqlCollectorTest
extends
\PHPUnit_Framework_TestCase
{
public
function
testGetQueriesForPsql
()
{
$platformMock
=
$this
->
getMock
(
'Doctrine\DBAL\Platforms\PostgreSqlPlatform'
,
array
(
'supportsSchemas'
,
'schemaNeedsCreation'
,
'getCreateTableSQL'
)
);
$platformMock
->
expects
(
$this
->
exactly
(
1
))
->
method
(
'supportsSchemas'
)
->
will
(
$this
->
returnValue
(
true
));
$platformMock
->
expects
(
$this
->
any
())
->
method
(
'schemaNeedsCreation'
)
->
will
(
$this
->
returnValue
(
true
));
$platformMock
->
expects
(
$this
->
any
())
->
method
(
'getCreateTableSQL'
)
->
will
(
$this
->
returnValue
(
array
(
'foo'
)));
$tableMock
=
$this
->
getMockBuilder
(
'\Doctrine\DBAL\Schema\Table'
)
->
disableOriginalConstructor
()
->
getMock
();
$sqlCollector
=
new
CreateSchemaSqlCollector
(
$platformMock
);
$sqlCollector
->
acceptTable
(
$tableMock
);
$sql
=
$sqlCollector
->
getQueries
();
$this
->
assertEquals
(
'CREATE SCHEMA default'
,
$sql
[
0
]);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment