• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hyperledger / identus-cloud-agent / 10793991050

10 Sep 2024 01:56PM CUT coverage: 48.504% (-4.5%) from 52.962%
10793991050

push

web-flow
build: sbt and plugins dependency update (#1337)

Signed-off-by: Hyperledger Bot <hyperledger-bot@hyperledger.org>
Signed-off-by: Yurii Shynbuiev <yurii.shynbuiev@iohk.io>
Co-authored-by: Hyperledger Bot <hyperledger-bot@hyperledger.org>
Co-authored-by: Yurii Shynbuiev <yurii.shynbuiev@iohk.io>

7406 of 15269 relevant lines covered (48.5%)

0.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

26.67
/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/repository/Migrations.scala
1
package org.hyperledger.identus.pollux.sql.repository
2

3
import doobie.*
4
import doobie.implicits.*
5
import doobie.util.transactor.Transactor
6
import org.flywaydb.core.api.exception.FlywayValidateException
7
import org.flywaydb.core.Flyway
8
import org.hyperledger.identus.shared.db.{ContextAwareTask, DbConfig}
9
import org.hyperledger.identus.shared.db.Implicits.*
10
import zio.*
11
import zio.interop.catz.*
12

13
final case class Migrations(config: DbConfig) {
14

15
  val migrationScriptsLocation: String = "sql/pollux"
16

17
  def migrate: Task[Unit] =
1✔
18
    for {
1✔
19
      _ <- ZIO.logInfo("Applying database migrations")
1✔
20
      _ <- ZIO.attempt {
1✔
21
        Flyway
22
          .configure()
1✔
23
          .loadDefaultConfigurationFiles()
1✔
24
          .dataSource(
1✔
25
            config.jdbcUrl,
26
            config.username,
27
            config.password
28
          )
29
          .locations(migrationScriptsLocation)
1✔
30
          .load()
1✔
31
          .migrate()
1✔
32
      }
33
    } yield ()
1✔
34

35
  def repair: Task[Unit] =
×
36
    for {
×
37
      _ <- ZIO.logInfo("Repairing Flyway schema history")
×
38
      _ <- ZIO.attempt {
×
39
        Flyway
40
          .configure()
×
41
          .dataSource(config.jdbcUrl, config.username, config.password)
×
42
          .locations(migrationScriptsLocation)
×
43
          .load()
×
44
          .repair()
×
45
      }
46
    } yield ()
×
47

48
  def migrateAndRepair: Task[Unit] =
×
49
    migrate.catchSome { case e: FlywayValidateException =>
×
50
      ZIO.logError("Migration validation failed, attempting to repair") *> repair *> migrate
×
51
    }
52

53
}
54

55
object Migrations {
56
  val layer: URLayer[DbConfig, Migrations] =
57
    ZLayer.fromFunction(Migrations.apply)
1✔
58

59
  /** Fail if the RLS is not enabled from a sample table */
60
  def validateRLS: RIO[Transactor[ContextAwareTask], Unit] = {
×
61
    val cxnIO = sql"""
×
62
      | SELECT row_security_active('public.credential_schema');
63
      """.stripMargin
×
64
      .query[Boolean]
65
      .unique
×
66

67
    for {
×
68
      xa <- ZIO.service[Transactor[ContextAwareTask]]
×
69
      isRlsActive <- cxnIO.transactWithoutContext(xa)
×
70
      _ <- ZIO
×
71
        .fail(Exception("The RLS policy is not active for Pollux DB application user"))
×
72
        .unless(isRlsActive)
73
    } yield ()
×
74
  }
75

76
  def initDbPrivileges(appUser: String): RIO[Transactor[Task], Unit] = {
×
77
    val cxnIO = for {
×
78
      _ <- doobie.free.connection.createStatement.map { stm =>
×
79
        stm.execute(s"""
×
80
          | ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO "$appUser"
81
          """.stripMargin)
×
82
      }
83
    } yield ()
×
84

85
    for {
×
86
      xa <- ZIO.service[Transactor[Task]]
×
87
      _ <- cxnIO.transact(xa)
×
88
    } yield ()
×
89
  }
90
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc