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
83b72c1d
Unverified
Commit
83b72c1d
authored
Dec 26, 2017
by
Simon Podlipsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix getting portable sequence definition for PSQL10
parent
1cc2d24f
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
158 additions
and
99 deletions
+158
-99
.travis.yml
.travis.yml
+3
-3
AbstractPostgreSQLDriver.php
lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php
+3
-0
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+9
-9
PostgreSQL100Keywords.php
...octrine/DBAL/Platforms/Keywords/PostgreSQL100Keywords.php
+19
-0
PostgreSQL100Platform.php
lib/Doctrine/DBAL/Platforms/PostgreSQL100Platform.php
+33
-0
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+8
-8
PostgreSqlSchemaManager.php
lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
+6
-3
AbstractPostgreSQLDriverTest.php
...ctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php
+2
-1
OracleSchemaManagerTest.php
.../Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php
+5
-0
SchemaManagerFunctionalTestCase.php
...BAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
+37
-0
PostgreSQL100PlatformTest.php
...ctrine/Tests/DBAL/Platforms/PostgreSQL100PlatformTest.php
+33
-0
PostgreSQLSchemaManagerTest.php
...octrine/Tests/DBAL/Schema/PostgreSQLSchemaManagerTest.php
+0
-75
No files found.
.travis.yml
View file @
83b72c1d
...
...
@@ -247,7 +247,7 @@ jobs:
-
stage
:
Test
php
:
7.1
env
:
DB=pgsql POSTGRESQL_VERSION=10
env
:
DB=pgsql POSTGRESQL_VERSION=10
.0
sudo
:
required
services
:
-
postgresql
...
...
@@ -257,7 +257,7 @@ jobs:
-
bash ./tests/travis/install-postgres-10.sh
-
stage
:
Test
php
:
7.2
env
:
DB=pgsql POSTGRESQL_VERSION=10
env
:
DB=pgsql POSTGRESQL_VERSION=10
.0
sudo
:
required
services
:
-
postgresql
...
...
@@ -267,7 +267,7 @@ jobs:
-
bash ./tests/travis/install-postgres-10.sh
-
stage
:
Test
php
:
nightly
env
:
DB=pgsql POSTGRESQL_VERSION=10
env
:
DB=pgsql POSTGRESQL_VERSION=10
.0
sudo
:
required
services
:
-
postgresql
...
...
lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php
View file @
83b72c1d
...
...
@@ -22,6 +22,7 @@ namespace Doctrine\DBAL\Driver;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Exception
;
use
Doctrine\DBAL\Platforms\PostgreSQL100Platform
;
use
Doctrine\DBAL\Platforms\PostgreSQL91Platform
;
use
Doctrine\DBAL\Platforms\PostgreSQL92Platform
;
use
Doctrine\DBAL\Platforms\PostgreSQL94Platform
;
...
...
@@ -113,6 +114,8 @@ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDri
$version
=
$majorVersion
.
'.'
.
$minorVersion
.
'.'
.
$patchVersion
;
switch
(
true
)
{
case
version_compare
(
$version
,
'10.0'
,
'>='
)
:
return
new
PostgreSQL100Platform
();
case
version_compare
(
$version
,
'9.4'
,
'>='
)
:
return
new
PostgreSQL94Platform
();
case
version_compare
(
$version
,
'9.2'
,
'>='
)
:
...
...
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
83b72c1d
lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL100Keywords.php
0 → 100644
View file @
83b72c1d
<?php
declare
(
strict_types
=
1
);
namespace
Doctrine\DBAL\Platforms\Keywords
;
/**
* PostgreSQL 10.0 reserved keywords list.
*/
class
PostgreSQL100Keywords
extends
PostgreSQL94Keywords
{
/**
* {@inheritdoc}
*/
public
function
getName
()
:
string
{
return
'PostgreSQL100'
;
}
}
lib/Doctrine/DBAL/Platforms/PostgreSQL100Platform.php
0 → 100644
View file @
83b72c1d
<?php
declare
(
strict_types
=
1
);
namespace
Doctrine\DBAL\Platforms
;
use
Doctrine\DBAL\Platforms\Keywords\PostgreSQL100Keywords
;
/**
* Provides the behavior, features and SQL dialect of the PostgreSQL 10.0 database platform.
*/
class
PostgreSQL100Platform
extends
PostgreSQL94Platform
{
/**
* {@inheritdoc}
*/
protected
function
getReservedKeywordsClass
()
:
string
{
return
PostgreSQL100Keywords
::
class
;
}
public
function
getListSequencesSQL
(
$database
)
:
string
{
return
"SELECT sequence_name AS relname,
sequence_schema AS schemaname,
minimum_value AS min_value,
increment AS increment_by
FROM information_schema.sequences
WHERE sequence_catalog = "
.
$this
->
quoteStringLiteral
(
$database
)
.
"
AND sequence_schema NOT LIKE 'pg\_%'
AND sequence_schema != 'information_schema'"
;
}
}
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
83b72c1d
lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
View file @
83b72c1d
...
...
@@ -283,15 +283,18 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
*/
protected
function
_getPortableSequenceDefinition
(
$sequence
)
{
if
(
$sequence
[
'schemaname'
]
!=
'public'
)
{
if
(
$sequence
[
'schemaname'
]
!=
=
'public'
)
{
$sequenceName
=
$sequence
[
'schemaname'
]
.
"."
.
$sequence
[
'relname'
];
}
else
{
$sequenceName
=
$sequence
[
'relname'
];
}
$data
=
$this
->
_conn
->
fetchAll
(
'SELECT min_value, increment_by FROM '
.
$this
->
_platform
->
quoteIdentifier
(
$sequenceName
));
if
(
!
isset
(
$sequence
[
'increment_by'
],
$sequence
[
'min_value'
]))
{
$data
=
$this
->
_conn
->
fetchAssoc
(
'SELECT min_value, increment_by FROM '
.
$this
->
_platform
->
quoteIdentifier
(
$sequenceName
));
$sequence
+=
$data
;
}
return
new
Sequence
(
$sequenceName
,
$
data
[
0
][
'increment_by'
],
$data
[
0
]
[
'min_value'
]);
return
new
Sequence
(
$sequenceName
,
$
sequence
[
'increment_by'
],
$sequence
[
'min_value'
]);
}
/**
...
...
tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php
View file @
83b72c1d
...
...
@@ -3,6 +3,7 @@
namespace
Doctrine\Tests\DBAL\Driver
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Platforms\PostgreSQL100Platform
;
use
Doctrine\DBAL\Platforms\PostgreSqlPlatform
;
use
Doctrine\DBAL\Schema\PostgreSqlSchemaManager
;
...
...
@@ -67,7 +68,7 @@ class AbstractPostgreSQLDriverTest extends AbstractDriverTest
array
(
'9.4'
,
'Doctrine\DBAL\Platforms\PostgreSQL94Platform'
),
array
(
'9.4.0'
,
'Doctrine\DBAL\Platforms\PostgreSQL94Platform'
),
array
(
'9.4.1'
,
'Doctrine\DBAL\Platforms\PostgreSQL94Platform'
),
array
(
'10'
,
'Doctrine\DBAL\Platforms\PostgreSQL94Platform'
),
array
(
'10'
,
PostgreSQL100Platform
::
class
),
);
}
...
...
tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php
View file @
83b72c1d
...
...
@@ -273,4 +273,9 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase
self
::
assertSame
(
'datetime'
,
$columns
[
'col_datetime'
]
->
getType
()
->
getName
());
self
::
assertSame
(
'datetimetz'
,
$columns
[
'col_datetimetz'
]
->
getType
()
->
getName
());
}
public
function
testCreateAndListSequences
()
:
void
{
self
::
markTestSkipped
(
"Skipped for uppercase letters are contained in sequences' names. Fix the schema manager in 3.0."
);
}
}
tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
View file @
83b72c1d
...
...
@@ -8,6 +8,7 @@ use Doctrine\DBAL\Platforms\OraclePlatform;
use
Doctrine\DBAL\Schema\Column
;
use
Doctrine\DBAL\Schema\ColumnDiff
;
use
Doctrine\DBAL\Schema\Comparator
;
use
Doctrine\DBAL\Schema\Sequence
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Schema\TableDiff
;
use
Doctrine\DBAL\Types\Type
;
...
...
@@ -1360,4 +1361,40 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
'valid with extra opening brackets'
=>
[
'(DC2Type:should((.stop)).before)'
,
'should((.stop'
,
$currentType
],
];
}
public
function
testCreateAndListSequences
()
:
void
{
if
(
!
$this
->
_sm
->
getDatabasePlatform
()
->
supportsSequences
())
{
self
::
markTestSkipped
(
'This test is only supported on platforms that support sequences.'
);
}
$sequence1Name
=
'sequence_1'
;
$sequence1AllocationSize
=
1
;
$sequence1InitialValue
=
2
;
$sequence2Name
=
'sequence_2'
;
$sequence2AllocationSize
=
3
;
$sequence2InitialValue
=
4
;
$sequence1
=
new
Sequence
(
$sequence1Name
,
$sequence1AllocationSize
,
$sequence1InitialValue
);
$sequence2
=
new
Sequence
(
$sequence2Name
,
$sequence2AllocationSize
,
$sequence2InitialValue
);
$this
->
_sm
->
createSequence
(
$sequence1
);
$this
->
_sm
->
createSequence
(
$sequence2
);
/** @var Sequence[] $actualSequences */
$actualSequences
=
[];
foreach
(
$this
->
_sm
->
listSequences
()
as
$sequence
)
{
$actualSequences
[
$sequence
->
getName
()]
=
$sequence
;
}
$actualSequence1
=
$actualSequences
[
$sequence1Name
];
$actualSequence2
=
$actualSequences
[
$sequence2Name
];
self
::
assertSame
(
$sequence1Name
,
$actualSequence1
->
getName
());
self
::
assertEquals
(
$sequence1AllocationSize
,
$actualSequence1
->
getAllocationSize
());
self
::
assertEquals
(
$sequence1InitialValue
,
$actualSequence1
->
getInitialValue
());
self
::
assertSame
(
$sequence2Name
,
$actualSequence2
->
getName
());
self
::
assertEquals
(
$sequence2AllocationSize
,
$actualSequence2
->
getAllocationSize
());
self
::
assertEquals
(
$sequence2InitialValue
,
$actualSequence2
->
getInitialValue
());
}
}
tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL100PlatformTest.php
0 → 100644
View file @
83b72c1d
<?php
declare
(
strict_types
=
1
);
namespace
Doctrine\Tests\DBAL\Platforms
;
use
Doctrine\DBAL\Platforms\PostgreSQL100Platform
;
class
PostgreSQL100PlatformTest
extends
PostgreSQL94PlatformTest
{
/**
* {@inheritdoc}
*/
public
function
createPlatform
()
:
PostgreSQL100Platform
{
return
new
PostgreSQL100Platform
();
}
public
function
testGetListSequencesSQL
()
:
void
{
self
::
assertSame
(
"SELECT sequence_name AS relname,
sequence_schema AS schemaname,
minimum_value AS min_value,
increment AS increment_by
FROM information_schema.sequences
WHERE sequence_catalog = 'test_db'
AND sequence_schema NOT LIKE 'pg\_%'
AND sequence_schema != 'information_schema'"
,
$this
->
_platform
->
getListSequencesSQL
(
'test_db'
)
);
}
}
tests/Doctrine/Tests/DBAL/Schema/PostgreSQLSchemaManagerTest.php
deleted
100644 → 0
View file @
1cc2d24f
<?php
namespace
Doctrine\Tests\DBAL\Schema
;
use
Doctrine\DBAL\Configuration
;
use
Doctrine\DBAL\Schema\PostgreSqlSchemaManager
;
use
Doctrine\DBAL\Schema\Sequence
;
class
PostgreSQLSchemaManagerTest
extends
\PHPUnit\Framework\TestCase
{
/**
* @var \Doctrine\DBAL\Schema\PostgreSQLSchemaManager
*/
private
$schemaManager
;
/**
* @var \Doctrine\DBAL\Connection|\PHPUnit_Framework_MockObject_MockObject
*/
private
$connection
;
protected
function
setUp
()
{
$driverMock
=
$this
->
createMock
(
'Doctrine\DBAL\Driver'
);
$platform
=
$this
->
createMock
(
'Doctrine\DBAL\Platforms\PostgreSqlPlatform'
);
$this
->
connection
=
$this
->
getMockBuilder
(
'Doctrine\DBAL\Connection'
)
->
setConstructorArgs
([[
'platform'
=>
$platform
],
$driverMock
])
->
getMock
();
$this
->
schemaManager
=
new
PostgreSqlSchemaManager
(
$this
->
connection
,
$platform
);
}
/**
* @group DBAL-474
*/
public
function
testFiltersSequences
()
{
$configuration
=
new
Configuration
();
$configuration
->
setFilterSchemaAssetsExpression
(
'/^schema/'
);
$sequences
=
[
[
'relname'
=>
'foo'
,
'schemaname'
=>
'schema'
],
[
'relname'
=>
'bar'
,
'schemaname'
=>
'schema'
],
[
'relname'
=>
'baz'
,
'schemaname'
=>
''
],
[
'relname'
=>
'bloo'
,
'schemaname'
=>
'bloo_schema'
],
];
$this
->
connection
->
expects
(
$this
->
any
())
->
method
(
'getConfiguration'
)
->
will
(
$this
->
returnValue
(
$configuration
));
$this
->
connection
->
expects
(
$this
->
at
(
0
))
->
method
(
'fetchAll'
)
->
will
(
$this
->
returnValue
(
$sequences
));
$this
->
connection
->
expects
(
$this
->
at
(
1
))
->
method
(
'fetchAll'
)
->
will
(
$this
->
returnValue
([[
'min_value'
=>
1
,
'increment_by'
=>
1
]]));
$this
->
connection
->
expects
(
$this
->
at
(
2
))
->
method
(
'fetchAll'
)
->
will
(
$this
->
returnValue
([[
'min_value'
=>
2
,
'increment_by'
=>
2
]]));
$this
->
connection
->
expects
(
$this
->
exactly
(
3
))
->
method
(
'fetchAll'
);
self
::
assertEquals
(
[
new
Sequence
(
'schema.foo'
,
2
,
2
),
new
Sequence
(
'schema.bar'
,
1
,
1
),
],
$this
->
schemaManager
->
listSequences
(
'database'
)
);
}
}
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