mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-21 18:08:25 +00:00
Add task to index current database state
This commit is contained in:
@ -0,0 +1,10 @@
|
||||
CREATE TABLE "fts_migration" (
|
||||
"id" varchar(254) not null primary key,
|
||||
"version" int not null,
|
||||
"fts_engine" varchar(254) not null,
|
||||
"description" varchar(254) not null,
|
||||
"created" timestamp not null
|
||||
);
|
||||
|
||||
CREATE UNIQE INDEX "fts_migration_version_engine_idx"
|
||||
ON "fts_migration"("version", "fts_engine");
|
@ -138,4 +138,30 @@ object QAttachment {
|
||||
|
||||
q.query[RAttachmentMeta].option
|
||||
}
|
||||
|
||||
case class ContentAndName(
|
||||
id: Ident,
|
||||
item: Ident,
|
||||
collective: Ident,
|
||||
name: Option[String],
|
||||
content: Option[String]
|
||||
)
|
||||
def allAttachmentMetaAndName(chunkSize: Int): Stream[ConnectionIO, ContentAndName] = {
|
||||
val aId = RAttachment.Columns.id.prefix("a")
|
||||
val aItem = RAttachment.Columns.itemId.prefix("a")
|
||||
val aName = RAttachment.Columns.name.prefix("a")
|
||||
val mId = RAttachmentMeta.Columns.id.prefix("m")
|
||||
val mContent = RAttachmentMeta.Columns.content.prefix("m")
|
||||
val iId = RItem.Columns.id.prefix("i")
|
||||
val iColl = RItem.Columns.cid.prefix("i")
|
||||
|
||||
val cols = Seq(aId, aItem, iColl, aName, mContent)
|
||||
val from = RAttachment.table ++ fr"a INNER JOIN" ++
|
||||
RAttachmentMeta.table ++ fr"m ON" ++ aId.is(mId) ++
|
||||
fr"INNER JOIN" ++ RItem.table ++ fr"i ON" ++ iId.is(aItem)
|
||||
|
||||
selectSimple(cols, from, Fragment.empty)
|
||||
.query[ContentAndName]
|
||||
.streamWithChunkSize(chunkSize)
|
||||
}
|
||||
}
|
||||
|
@ -469,4 +469,21 @@ object QItem {
|
||||
prefix(suffix(value))
|
||||
}
|
||||
|
||||
final case class NameAndNotes(
|
||||
id: Ident,
|
||||
collective: Ident,
|
||||
name: String,
|
||||
notes: Option[String]
|
||||
)
|
||||
def allNameAndNotes(chunkSize: Int): Stream[ConnectionIO, NameAndNotes] = {
|
||||
val iId = RItem.Columns.id
|
||||
val iColl = RItem.Columns.cid
|
||||
val iName = RItem.Columns.name
|
||||
val iNotes = RItem.Columns.notes
|
||||
|
||||
val cols = Seq(iId, iColl, iName, iNotes)
|
||||
selectSimple(cols, RItem.table, Fragment.empty)
|
||||
.query[NameAndNotes]
|
||||
.streamWithChunkSize(chunkSize)
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,59 @@
|
||||
package docspell.store.records
|
||||
|
||||
import cats.implicits._
|
||||
import cats.effect._
|
||||
import doobie._
|
||||
import doobie.implicits._
|
||||
import docspell.common._
|
||||
import docspell.store.impl._
|
||||
import docspell.store.impl.Implicits._
|
||||
|
||||
final case class RFtsMigration(
|
||||
id: Ident,
|
||||
version: Int,
|
||||
ftsEngine: Ident,
|
||||
description: String,
|
||||
created: Timestamp
|
||||
)
|
||||
|
||||
object RFtsMigration {
|
||||
|
||||
def create[F[_]: Sync](
|
||||
version: Int,
|
||||
ftsEngine: Ident,
|
||||
description: String
|
||||
): F[RFtsMigration] =
|
||||
for {
|
||||
newId <- Ident.randomId[F]
|
||||
now <- Timestamp.current[F]
|
||||
} yield RFtsMigration(newId, version, ftsEngine, description, now)
|
||||
|
||||
val table = fr"fts_migration"
|
||||
|
||||
object Columns {
|
||||
val id = Column("id")
|
||||
val version = Column("version")
|
||||
val ftsEngine = Column("fts_engine")
|
||||
val description = Column("description")
|
||||
val created = Column("created")
|
||||
|
||||
val all = List(id, version, ftsEngine, description, created)
|
||||
}
|
||||
import Columns._
|
||||
|
||||
def insert(v: RFtsMigration): ConnectionIO[Int] =
|
||||
insertRow(
|
||||
table,
|
||||
all,
|
||||
fr"${v.id},${v.version},${v.ftsEngine},${v.description},${v.created}"
|
||||
).update.run
|
||||
|
||||
def exists(vers: Int, engine: Ident): ConnectionIO[Boolean] =
|
||||
selectCount(id, table, and(version.is(vers), ftsEngine.is(engine)))
|
||||
.query[Int]
|
||||
.unique
|
||||
.map(_ > 0)
|
||||
|
||||
def deleteById(rId: Ident): ConnectionIO[Int] =
|
||||
deleteFrom(table, id.is(rId)).update.run
|
||||
}
|
Reference in New Issue
Block a user