The clean & modern RSS server that doesn't give you any crap. https://thearsse.com/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TestDatabase.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /** @license MIT
  3. * Copyright 2017 J. King, Dustin Wilson et al.
  4. * See LICENSE and AUTHORS files for details */
  5. declare(strict_types=1);
  6. namespace JKingWeb\Arsse\TestCase\Db\PosgreSQL;
  7. /**
  8. * @group excludeFromCoverage
  9. * @covers \JKingWeb\Arsse\Database<extended>
  10. * @covers \JKingWeb\Arsse\Misc\Query<extended>
  11. */
  12. class TestDatabase extends \JKingWeb\Arsse\TestCase\Database\Base {
  13. protected static $implementation = "PDO PostgreSQL";
  14. protected function nextID(string $table): int {
  15. return (int) static::$drv->query("SELECT coalesce(last_value, (select max(id) from $table)) + 1 from pg_sequences where sequencename = '{$table}_id_seq'")->getValue();
  16. }
  17. public function setUp() {
  18. parent::setUp();
  19. $seqList =
  20. "select
  21. replace(substring(column_default, 10), right(column_default, 12), '') as seq,
  22. table_name as table,
  23. column_name as col
  24. from information_schema.columns
  25. where table_schema = current_schema()
  26. and table_name like 'arsse_%'
  27. and column_default like 'nextval(%'
  28. ";
  29. foreach (static::$drv->query($seqList) as $r) {
  30. $num = (int) static::$drv->query("SELECT max({$r['col']}) from {$r['table']}")->getValue();
  31. if (!$num) {
  32. continue;
  33. }
  34. $num++;
  35. static::$drv->exec("ALTER SEQUENCE {$r['seq']} RESTART WITH $num");
  36. }
  37. }
  38. }