mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Remove fts_migration table
It is now stored it SOLR instead.
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
package docspell.joex.fts
|
||||
|
||||
import cats.data.{Kleisli, OptionT}
|
||||
import cats.data.Kleisli
|
||||
import cats.effect._
|
||||
import cats.implicits._
|
||||
import cats.{Applicative, FlatMap, Traverse}
|
||||
@ -8,13 +8,13 @@ import cats.{Applicative, FlatMap, Traverse}
|
||||
import docspell.common._
|
||||
import docspell.ftsclient._
|
||||
import docspell.joex.Config
|
||||
import docspell.store.records.RFtsMigration
|
||||
import docspell.store.{AddResult, Store}
|
||||
import docspell.store.Store
|
||||
|
||||
/** Migrating the index from the previous version to this version.
|
||||
*
|
||||
* The sql database stores the outcome of a migration task. If this
|
||||
* task has already been applied, it is skipped.
|
||||
* The migration asks the fulltext search client for a list of
|
||||
* migration tasks to run. It may be empty when there is no migration
|
||||
* required.
|
||||
*/
|
||||
case class Migration[F[_]](
|
||||
version: Int,
|
||||
@ -35,41 +35,16 @@ object Migration {
|
||||
logger: Logger[F]
|
||||
): Kleisli[F, List[Migration[F]], Unit] = {
|
||||
val ctx = FtsContext(cfg, store, fts, logger)
|
||||
Kleisli(migs => Traverse[List].sequence(migs.map(applySingle[F](ctx))).map(_ => ()))
|
||||
Kleisli { migs =>
|
||||
if (migs.isEmpty) logger.info("No fulltext search migrations to run.")
|
||||
else Traverse[List].sequence(migs.map(applySingle[F](ctx))).map(_ => ())
|
||||
}
|
||||
}
|
||||
|
||||
def applySingle[F[_]: Effect](ctx: FtsContext[F])(m: Migration[F]): F[Unit] = {
|
||||
val insertRecord: F[Option[RFtsMigration]] =
|
||||
for {
|
||||
rec <- RFtsMigration.create(m.version, m.engine, m.description)
|
||||
res <- ctx.store.add(
|
||||
RFtsMigration.insert(rec),
|
||||
RFtsMigration.exists(m.version, m.engine)
|
||||
)
|
||||
ret <- res match {
|
||||
case AddResult.Success => rec.some.pure[F]
|
||||
case AddResult.EntityExists(_) => None.pure[F]
|
||||
case AddResult.Failure(ex) => Effect[F].raiseError(ex)
|
||||
}
|
||||
} yield ret
|
||||
|
||||
(for {
|
||||
_ <- OptionT.liftF(ctx.logger.info(s"Apply ${m.version}/${m.description}"))
|
||||
rec <- OptionT(insertRecord)
|
||||
res <- OptionT.liftF(m.task.run(ctx).attempt)
|
||||
ret <- OptionT.liftF(res match {
|
||||
case Right(()) => ().pure[F]
|
||||
case Left(ex) =>
|
||||
ctx.logger.error(ex)(
|
||||
s"Applying index migration ${m.version}/${m.description} failed"
|
||||
) *>
|
||||
ctx.store.transact(RFtsMigration.deleteById(rec.id)) *> Effect[F]
|
||||
.raiseError[Unit](
|
||||
ex
|
||||
)
|
||||
})
|
||||
} yield ret).getOrElseF(
|
||||
ctx.logger.info(s"Migration ${m.version}/${m.description} already applied.")
|
||||
)
|
||||
for {
|
||||
_ <- ctx.logger.info(s"Apply ${m.version}/${m.description}")
|
||||
_ <- m.task.run(ctx)
|
||||
} yield ()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user