2018-12-14 00:47:51 +00:00
< ? php
/** @ license MIT
* Copyright 2017 J . King , Dustin Wilson et al .
* See LICENSE and AUTHORS files for details */
declare ( strict_types = 1 );
2021-04-14 15:17:01 +00:00
2018-12-14 00:47:51 +00:00
namespace JKingWeb\Arsse\TestCase\Db\PostgreSQL ;
/**
* @ group slow
* @ group coverageOptional
2024-07-10 20:28:19 +00:00
* @ coversNothing
2018-12-14 00:47:51 +00:00
*/
2019-09-11 19:25:26 +00:00
class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\AbstractTest {
2019-08-25 17:19:11 +00:00
use \JKingWeb\Arsse\Test\DatabaseDrivers\PostgreSQL ;
2018-12-14 00:47:51 +00:00
protected function nextID ( string $table ) : int {
return ( int ) static :: $drv -> query ( " SELECT coalesce(last_value, (select max(id) from $table )) + 1 from pg_sequences where sequencename = ' { $table } _id_seq' " ) -> getValue ();
}
2019-10-16 18:42:43 +00:00
public function setUp () : void {
2018-12-14 00:47:51 +00:00
parent :: setUp ();
$seqList =
" select
replace ( substring ( column_default , 10 ), right ( column_default , 12 ), '' ) as seq ,
table_name as table ,
column_name as col
from information_schema . columns
where table_schema = current_schema ()
and table_name like 'arsse_%'
and column_default like 'nextval(%'
" ;
foreach ( static :: $drv -> query ( $seqList ) as $r ) {
$num = ( int ) static :: $drv -> query ( " SELECT max( { $r [ 'col' ] } ) from { $r [ 'table' ] } " ) -> getValue ();
if ( ! $num ) {
continue ;
}
$num ++ ;
static :: $drv -> exec ( " ALTER SEQUENCE { $r [ 'seq' ] } RESTART WITH $num " );
}
}
}