mirror of
				https://github.com/TheAnachronism/docspell.git
				synced 2025-11-03 18:00:11 +00:00 
			
		
		
		
	Fix selectNextGroup query for an empty job table
This commit is contained in:
		@@ -135,7 +135,7 @@ object QJob {
 | 
			
		||||
      .trace(
 | 
			
		||||
        s"nextGroupQuery: $frag  (now=${now.toMillis}, pause=${initialPause.millis})"
 | 
			
		||||
      ) *>
 | 
			
		||||
      groups.build.query[Ident].option
 | 
			
		||||
      frag.query[Option[Ident]].unique
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private def stuckTriggerValue(t: RJob.Table, initialPause: Duration, now: Timestamp) =
 | 
			
		||||
 
 | 
			
		||||
@@ -12,6 +12,7 @@ import java.util.concurrent.atomic.AtomicLong
 | 
			
		||||
import cats.syntax.all._
 | 
			
		||||
 | 
			
		||||
import docspell.common._
 | 
			
		||||
import docspell.store.qb.{Condition, DML}
 | 
			
		||||
import docspell.store.records.{RJob, RJobGroupUse}
 | 
			
		||||
import docspell.store.{DatabaseTest, Db}
 | 
			
		||||
 | 
			
		||||
@@ -42,6 +43,19 @@ class QJobTest extends DatabaseTest {
 | 
			
		||||
      None
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
  Db.all.toList.foreach { db =>
 | 
			
		||||
    test(s"selectNextGroup on empty table ($db)") {
 | 
			
		||||
      val store = createStore(db)
 | 
			
		||||
      val nextGroup = for {
 | 
			
		||||
        _ <- store.transact(RJobGroupUse.deleteAll)
 | 
			
		||||
        _ <- store.transact(DML.delete(RJob.T, Condition.unit))
 | 
			
		||||
        next <- store.transact(QJob.selectNextGroup(worker, nowTs, initialPause))
 | 
			
		||||
      } yield next
 | 
			
		||||
 | 
			
		||||
      nextGroup.assertEquals(None)
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Db.all.toList.foreach { db =>
 | 
			
		||||
    test(s"set group must insert or update ($db)") {
 | 
			
		||||
      val store = createStore(db)
 | 
			
		||||
 
 | 
			
		||||
@@ -20,9 +20,11 @@ object DML extends DoobieMeta {
 | 
			
		||||
  def delete(table: TableDef, cond: Condition): ConnectionIO[Int] =
 | 
			
		||||
    deleteFragment(table, cond).update.run
 | 
			
		||||
 | 
			
		||||
  def deleteFragment(table: TableDef, cond: Condition): Fragment =
 | 
			
		||||
    fr"DELETE FROM" ++ FromExprBuilder.buildTable(table) ++ fr" WHERE" ++ ConditionBuilder
 | 
			
		||||
      .build(cond)
 | 
			
		||||
  def deleteFragment(table: TableDef, cond: Condition): Fragment = {
 | 
			
		||||
    val delete = fr"DELETE FROM" ++ FromExprBuilder.buildTable(table)
 | 
			
		||||
    if (cond == Condition.unit) delete
 | 
			
		||||
    else delete ++ fr"WHERE" ++ ConditionBuilder.build(cond)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  def insert(table: TableDef, cols: Nel[Column[_]], values: Fragment): ConnectionIO[Int] =
 | 
			
		||||
    insertFragment(table, cols, List(values)).update.run
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user