|
| 1 | +- [Database Setup and Configuration](#database-setup-and-configuration) |
| 2 | + - [Development Database Setup](#development-database-setup) |
| 3 | + - [Option 1: Docker (Recommended)](#option-1-docker-recommended) |
| 4 | + - [Option 2: Local MariaDB Installation](#option-2-local-mariadb-installation) |
| 5 | + - [Testing Database Setup](#testing-database-setup) |
| 6 | + - [Database Seeding and Configuration](#database-seeding-and-configuration) |
| 7 | + - [Development Seeding](#development-seeding) |
| 8 | + - [Migrations](#migrations) |
| 9 | + - [Current Status](#current-status) |
| 10 | + - [Database Management Commands](#database-management-commands) |
| 11 | + |
| 12 | +# Database Setup and Configuration |
| 13 | + |
| 14 | +This document explains how to set up and configure the database for development and testing purposes. |
| 15 | + |
| 16 | +## Development Database Setup |
| 17 | + |
| 18 | +There are two ways to set up a database for development: |
| 19 | + |
| 20 | +### Option 1: Docker (Recommended) |
| 21 | + |
| 22 | +The easiest way to get started is using Docker with the default configuration: |
| 23 | + |
| 24 | +```bash |
| 25 | +npm run docker-dev |
| 26 | +``` |
| 27 | + |
| 28 | +This command will: |
| 29 | +- Start the database container using Docker Compose |
| 30 | +- Use the default configuration settings |
| 31 | +- Set up the database ready for development |
| 32 | + |
| 33 | +### Option 2: Local MariaDB Installation |
| 34 | + |
| 35 | +For a local MariaDB setup, you'll need to install MariaDB on your system first. |
| 36 | + |
| 37 | +**Installation Guide:** [MariaDB Getting Started](https://mariadb.com/get-started-with-mariadb/) |
| 38 | + |
| 39 | +After installing MariaDB locally, configure your application to connect to your local database instance by updating the appropriate configuration files. |
| 40 | + |
| 41 | +## Testing Database Setup |
| 42 | + |
| 43 | +For running tests, Docker must be installed and running on your system. |
| 44 | + |
| 45 | +To set up the test database: |
| 46 | + |
| 47 | +```bash |
| 48 | +npm run docker-test |
| 49 | +``` |
| 50 | + |
| 51 | +This command will: |
| 52 | +- Start a test database container |
| 53 | +- Automatically seed the database with mock data prepared specifically for testing |
| 54 | +- Ensure a clean testing environment |
| 55 | + |
| 56 | +## Database Seeding and Configuration |
| 57 | + |
| 58 | +### Development Seeding |
| 59 | + |
| 60 | +For development purposes, you can seed the database with mock data by setting `forceSeed` to `true` in your configuration. |
| 61 | + |
| 62 | +**Important Notes:** |
| 63 | +- When `forceSeed` is enabled, seeding will execute every time the server reloads |
| 64 | +- The `drop` property will clean all data from the database if set to `true` every time the server reloads |
| 65 | +- Use these options carefully to avoid unintended data loss |
| 66 | + |
| 67 | +### Migrations |
| 68 | + |
| 69 | +Database migrations will be executed automatically if they haven't been run before. |
| 70 | + |
| 71 | +**Clean Setup Recommendation:** |
| 72 | +For a completely clean database setup, it's recommended to run: |
| 73 | + |
| 74 | +```bash |
| 75 | +docker compose down database -v |
| 76 | +``` |
| 77 | + |
| 78 | +And delete all existing data. |
| 79 | + |
| 80 | +**WARNING:** Only perform this clean setup the first time or when you specifically need to reset everything, as it will permanently delete all database data. |
| 81 | + |
| 82 | +## Current Status |
| 83 | + |
| 84 | +**Important:** The database is currently not being used by the application or tests, as the services and controllers are not yet configured to utilize the database layer. This functionality is planned for future implementation. |
| 85 | + |
| 86 | +## Database Management Commands |
| 87 | + |
| 88 | +- `npm run docker-dev` - Start development database |
| 89 | +- `npm run docker-test` - Start test database with mock data |
| 90 | +- `docker compose down database -v` - Clean database setup (removes all data) |
0 commit comments