2018-11-27 14:26:33 -05: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 12:42:40 -05:00
namespace JKingWeb\Arsse\TestCase\Db\PostgreSQLPDO ;
2018-11-27 14:26:33 -05:00
2018-12-05 17:28:11 -05:00
/**
2018-12-10 12:39:09 -05:00
* @ group slow
2018-12-13 19:47:51 -05:00
* @ group optional
2018-12-10 12:39:09 -05:00
* @ group coverageOptional
2018-11-27 14:26:33 -05:00
* @ covers \JKingWeb\Arsse\Database < extended >
*/
2019-09-11 15:25:26 -04:00
class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\AbstractTest {
2019-08-25 13:19:11 -04:00
use \JKingWeb\Arsse\Test\DatabaseDrivers\PostgreSQLPDO ;
2018-11-27 14:26:33 -05:00
protected function nextID ( string $table ) : int {
2018-12-05 09:05:43 -05: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 16:24:12 -05:00
}
2019-10-16 14:42:43 -04:00
public function setUp () : void {
2018-11-28 16:24:12 -05:00
parent :: setUp ();
2018-12-05 17:28:11 -05:00
$seqList =
2018-11-28 16:24:12 -05:00
" select
replace ( substring ( column_default , 10 ), right ( column_default , 12 ), '' ) as seq ,
table_name as table ,
column_name as col
2018-11-28 17:16:03 -05:00
from information_schema . columns
where table_schema = current_schema ()
and table_name like 'arsse_%'
2018-11-28 16:24:12 -05:00
and column_default like 'nextval(%'
" ;
2018-12-05 17:28:11 -05:00
foreach ( static :: $drv -> query ( $seqList ) as $r ) {
2018-12-05 09:05:43 -05:00
$num = ( int ) static :: $drv -> query ( " SELECT max( { $r [ 'col' ] } ) from { $r [ 'table' ] } " ) -> getValue ();
2018-11-28 16:24:12 -05:00
if ( ! $num ) {
continue ;
}
$num ++ ;
static :: $drv -> exec ( " ALTER SEQUENCE { $r [ 'seq' ] } RESTART WITH $num " );
}
2018-11-27 14:26:33 -05:00
}
}