2018-11-27 19:26:33 +00:00
< ? php
/** @ license MIT
* Copyright 2017 J . King , Dustin Wilson et al .
* See LICENSE and AUTHORS files for details */
declare ( strict_types = 1 );
2018-12-12 17:42:40 +00:00
namespace JKingWeb\Arsse\TestCase\Db\PostgreSQLPDO ;
2018-11-27 19:26:33 +00:00
2018-12-05 22:28:11 +00:00
/**
2018-12-10 17:39:09 +00:00
* @ group slow
* @ group coverageOptional
2018-11-27 19:26:33 +00:00
* @ covers \JKingWeb\Arsse\Database < extended >
* @ covers \JKingWeb\Arsse\Misc\Query < extended >
*/
class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\Base {
protected static $implementation = " PDO PostgreSQL " ;
protected function nextID ( string $table ) : int {
2018-12-05 14:05:43 +00:00
return ( int ) static :: $drv -> query ( " SELECT coalesce(last_value, (select max(id) from $table )) + 1 from pg_sequences where sequencename = ' { $table } _id_seq' " ) -> getValue ();
2018-11-28 21:24:12 +00:00
}
public function setUp () {
parent :: setUp ();
2018-12-05 22:28:11 +00:00
$seqList =
2018-11-28 21:24:12 +00:00
" select
replace ( substring ( column_default , 10 ), right ( column_default , 12 ), '' ) as seq ,
table_name as table ,
column_name as col
2018-11-28 22:16:03 +00:00
from information_schema . columns
where table_schema = current_schema ()
and table_name like 'arsse_%'
2018-11-28 21:24:12 +00:00
and column_default like 'nextval(%'
" ;
2018-12-05 22:28:11 +00:00
foreach ( static :: $drv -> query ( $seqList ) as $r ) {
2018-12-05 14:05:43 +00:00
$num = ( int ) static :: $drv -> query ( " SELECT max( { $r [ 'col' ] } ) from { $r [ 'table' ] } " ) -> getValue ();
2018-11-28 21:24:12 +00:00
if ( ! $num ) {
continue ;
}
$num ++ ;
static :: $drv -> exec ( " ALTER SEQUENCE { $r [ 'seq' ] } RESTART WITH $num " );
}
2018-11-27 19:26:33 +00:00
}
}