H2 Database Support Implementation
Overview
This document outlines the implementation of H2 database support for the Firmiana Matrix Chat Server, providing an in-memory or file-based database alternative to MongoDB for development and testing.
Objectives
- Add H2 as an alternative database backend alongside MongoDB
- Maintain compatibility with existing MongoDB implementations
- Provide configuration options to switch between database backends
- Support both in-memory and persistent H2 modes
Scope
- Add H2 JDBC driver dependency
- Configure Micronaut Data for H2 support
- Create database schema and initialization
- Update repository layer to support both databases
- Add configuration properties for database selection
Implementation Details
Dependencies
- h2: H2 database engine
- Micronaut Data JDBC: ORM support
- r2dbc-h2: R2DBC driver for reactive access
Configuration
- Add database.type property (mongodb or h2)
- Add h2.mode property (memory or file)
- Add h2.path property for file-based storage
- Conditional bean creation based on database type
Database Schema
- Create schema for all entities
- Define indexes for performance
- Set up relationships and constraints
Benefits
- Fast in-memory database for testing
- Persistent file-based option for development
- No external database server required
- Excellent for CI/CD pipelines
- Web console for database inspection
Timeline
- Phase 1: Add dependencies and configuration
- Phase 2: Create database schema
- Phase 3: Update repositories
- Phase 4: Testing and validation