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
fe824157
Unverified
Commit
fe824157
authored
Nov 19, 2017
by
Luís Cobucci
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'pg_serial_defaults' into 2.6
Backporting
https://github.com/doctrine/dbal/pull/2907
parents
53af700a
79e6d130
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
121 additions
and
0 deletions
+121
-0
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+20
-0
PostgreSqlSchemaManagerTest.php
...ts/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php
+44
-0
AbstractPostgreSqlPlatformTestCase.php
...sts/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php
+57
-0
No files found.
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
fe824157
...
...
@@ -26,7 +26,9 @@ use Doctrine\DBAL\Schema\Index;
use
Doctrine\DBAL\Schema\Sequence
;
use
Doctrine\DBAL\Schema\TableDiff
;
use
Doctrine\DBAL\Types\BinaryType
;
use
Doctrine\DBAL\Types\BigIntType
;
use
Doctrine\DBAL\Types\BlobType
;
use
Doctrine\DBAL\Types\IntegerType
;
/**
* PostgreSqlPlatform.
...
...
@@ -1186,4 +1188,22 @@ class PostgreSqlPlatform extends AbstractPlatform
return
parent
::
quoteStringLiteral
(
$str
);
}
/**
* {@inheritdoc}
*/
public
function
getDefaultValueDeclarationSQL
(
$field
)
{
if
(
$this
->
isSerialField
(
$field
))
{
return
''
;
}
return
parent
::
getDefaultValueDeclarationSQL
(
$field
);
}
private
function
isSerialField
(
array
$field
)
:
bool
{
return
$field
[
'autoincrement'
]
??
false
===
true
&&
isset
(
$field
[
'type'
])
&&
(
$field
[
'type'
]
instanceof
IntegerType
||
$field
[
'type'
]
instanceof
BigIntType
);
}
}
tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php
View file @
fe824157
...
...
@@ -419,6 +419,50 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$this
->
assertEquals
(
-
1.1
,
$columns
[
'col_decimal'
]
->
getDefault
());
$this
->
assertEquals
(
'(-1)'
,
$columns
[
'col_string'
]
->
getDefault
());
}
public
static
function
serialTypes
()
:
array
{
return
[
[
'integer'
],
[
'bigint'
],
];
}
/**
* @dataProvider serialTypes
* @group 2906
*/
public
function
testAutoIncrementCreatesSerialDataTypesWithoutADefaultValue
(
string
$type
)
:
void
{
$tableName
=
"test_serial_type_
$type
"
;
$table
=
new
Schema\Table
(
$tableName
);
$table
->
addColumn
(
'id'
,
$type
,
[
'autoincrement'
=>
true
,
'notnull'
=>
false
]);
$this
->
_sm
->
dropAndCreateTable
(
$table
);
$columns
=
$this
->
_sm
->
listTableColumns
(
$tableName
);
self
::
assertNull
(
$columns
[
'id'
]
->
getDefault
());
}
/**
* @dataProvider serialTypes
* @group 2906
*/
public
function
testAutoIncrementCreatesSerialDataTypesWithoutADefaultValueEvenWhenDefaultIsSet
(
string
$type
)
:
void
{
$tableName
=
"test_serial_type_with_default_
$type
"
;
$table
=
new
Schema\Table
(
$tableName
);
$table
->
addColumn
(
'id'
,
$type
,
[
'autoincrement'
=>
true
,
'notnull'
=>
false
,
'default'
=>
1
]);
$this
->
_sm
->
dropAndCreateTable
(
$table
);
$columns
=
$this
->
_sm
->
listTableColumns
(
$tableName
);
self
::
assertNull
(
$columns
[
'id'
]
->
getDefault
());
}
}
class
MoneyType
extends
Type
...
...
tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php
View file @
fe824157
...
...
@@ -144,6 +144,63 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
$this
->
assertEquals
(
array
(
'CREATE TABLE autoinc_table (id SERIAL NOT NULL)'
),
$this
->
_platform
->
getCreateTableSQL
(
$table
));
}
public
static
function
serialTypes
()
:
array
{
return
[
[
'integer'
,
'SERIAL'
],
[
'bigint'
,
'BIGSERIAL'
],
];
}
/**
* @dataProvider serialTypes
* @group 2906
*/
public
function
testGenerateTableWithAutoincrementDoesNotSetDefault
(
string
$type
,
string
$definition
)
:
void
{
$table
=
new
\Doctrine\DBAL\Schema\Table
(
'autoinc_table_notnull'
);
$column
=
$table
->
addColumn
(
'id'
,
$type
);
$column
->
setAutoIncrement
(
true
);
$column
->
setNotNull
(
false
);
$sql
=
$this
->
_platform
->
getCreateTableSQL
(
$table
);
self
::
assertEquals
([
"CREATE TABLE autoinc_table_notnull (id
$definition
)"
],
$sql
);
}
/**
* @dataProvider serialTypes
* @group 2906
*/
public
function
testCreateTableWithAutoincrementAndNotNullAddsConstraint
(
string
$type
,
string
$definition
)
:
void
{
$table
=
new
\Doctrine\DBAL\Schema\Table
(
'autoinc_table_notnull_enabled'
);
$column
=
$table
->
addColumn
(
'id'
,
$type
);
$column
->
setAutoIncrement
(
true
);
$column
->
setNotNull
(
true
);
$sql
=
$this
->
_platform
->
getCreateTableSQL
(
$table
);
self
::
assertEquals
([
"CREATE TABLE autoinc_table_notnull_enabled (id
$definition
NOT NULL)"
],
$sql
);
}
/**
* @dataProvider serialTypes
* @group 2906
*/
public
function
testGetDefaultValueDeclarationSQLIgnoresTheDefaultKeyWhenTheFieldIsSerial
(
string
$type
)
:
void
{
$sql
=
$this
->
_platform
->
getDefaultValueDeclarationSQL
(
[
'autoincrement'
=>
true
,
'type'
=>
Type
::
getType
(
$type
),
'default'
=>
1
,
]
);
self
::
assertSame
(
''
,
$sql
);
}
public
function
testGeneratesTypeDeclarationForIntegers
()
{
$this
->
assertEquals
(
...
...
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