works.iterative.sqldb

Members list

Type members

Classlikes

case class DatabasePermissionService(repository: PermissionRepository, config: PermissionConfig) extends PermissionService, EnumerablePermissionService, MutablePermissionService

Database-backed implementation of PermissionService with fail-closed error handling.

Database-backed implementation of PermissionService with fail-closed error handling.

This implementation provides production-ready permission storage that:

  • Persists RelationTuples to a SQL database via PermissionRepository
  • Delegates permission logic to PermissionLogic (pure domain logic)
  • Implements fail-closed pattern: database errors result in access denial (return false)
  • Logs infrastructure failures before denying access for debugging

SECURITY CRITICAL: Database errors must NEVER bypass authorization checks. The fail-closed pattern ensures that any infrastructure failure (database down, connection timeout, query error) results in access denial rather than granting unintended permissions.

Value parameters

config

Permission configuration defining inheritance rules

repository

The repository for persisting relation tuples

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
trait MutablePermissionService
trait EnumerablePermissionService
trait PermissionService
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
case class FlywayConfig(locations: List[String] = ..., cleanDisabled: Boolean = ...)

Configuration for Flyway migrations

Configuration for Flyway migrations

Value parameters

cleanDisabled

Whether database cleaning is disabled (true by default for safety)

locations

Classpath locations to scan for migrations

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object FlywayConfig

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type

Service for managing database migrations using Flyway

Service for managing database migrations using Flyway

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
case class MessageCatalogueData(messageKey: MessageId, language: Language, messageText: String, description: Option[String], createdAt: Instant, updatedAt: Instant, createdBy: Option[String], updatedBy: Option[String])

Data model representing a message catalogue entry for SQL storage. Contains persistence-related fields for database storage and audit tracking.

Data model representing a message catalogue entry for SQL storage. Contains persistence-related fields for database storage and audit tracking.

Value parameters

createdAt

Timestamp when this message was first created

createdBy

Optional username of the user who created this message

description

Optional description of the message purpose or context

language

The language code for this message

messageKey

The unique message identifier

messageText

The actual message text content

updatedAt

Timestamp when this message was last updated

updatedBy

Optional username of the user who last updated this message

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Supertypes
class Object
trait Matchable
class Any

Repository interface for persisting RelationTuples to a SQL database.

Repository interface for persisting RelationTuples to a SQL database.

This trait defines the contract for storing Zanzibar-inspired permission tuples, enabling database-backed PermissionService implementations.

Implementation notes:

  • All operations return Task[T] to handle database errors
  • Database errors should be handled at the service layer (fail-closed pattern)
  • Implementations should use parameterized queries to prevent SQL injection
  • addRelation should be idempotent (duplicate inserts should succeed)

Attributes

Supertypes
class Object
trait Matchable
class Any
class SqlMessageCatalogueService(repository: MessageCatalogueRepository, cacheRef: Ref[Map[Language, Map[String, String]]], defaultLanguage: Language) extends MessageCatalogueService

MessageCatalogueService implementation with database-backed pre-loaded cache.

MessageCatalogueService implementation with database-backed pre-loaded cache.

This service manages the lifecycle of SQL-backed message catalogues:

  • Pre-loads all messages from database at startup (fail-fast via .orDie)
  • Stores messages in in-memory cache (ZIO Ref) for fast synchronous access
  • Supports hot reload of messages from database without application restart

Lifecycle:

  1. Startup: Pre-load all configured languages from database (parallel loading) 2. Runtime: Serve messages from in-memory cache (no database queries) 3. On demand: Reload messages from database via reload() method

Key characteristics:

  • Fail-fast startup: Application won't start if messages cannot be loaded
  • Zero database queries during message retrieval (all queries at startup/reload)
  • Thread-safe concurrent access via ZIO Ref atomic updates
  • Hot reload support: Update database, call reload(), no restart needed
  • Atomic cache updates: Reload errors leave existing cache unchanged

Performance:

  • Startup: ~100-200ms for 10K messages across multiple languages
  • Reload: ~50-200ms depending on message count and language count
  • Lookup: O(1) map access (identical to JSON implementation)

Value parameters

cacheRef

Reference to the in-memory cache of messages by language

defaultLanguage

The default language to use when messages() is called

repository

The repository for loading messages from database

Attributes

See also

works.iterative.core.service.impl.InMemoryMessageCatalogue for the message catalogue implementation

MessageCatalogueRepository for database access

docs/message-catalogue-reload.md for reload mechanism documentation

Companion
object
Supertypes
trait MessageCatalogueService
class Object
trait Matchable
class Any

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type