# Inveetaire Database Initialization

This directory contains the database initialization scripts generated from the physical database design (PDD v1.0).

## Required Database

* **Database Engine:** MariaDB 10.4+ or MySQL 5.7+ (using InnoDB engine)
* **Default Charset:** `utf8mb4`
* **Default Collation:** `utf8mb4_unicode_ci`

---

## Prerequisites

1. Ensure MariaDB/MySQL is running.
2. Create the target database `inveetaire`:
   ```sql
   CREATE DATABASE IF NOT EXISTS `inveetaire` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
   ```
3. Set the correct connection details (host, database name, user, password) inside your `.env` file at the project root.

---

## Installation & Setup

You can initialize the database using either the command line or any database client (such as phpMyAdmin, DBeaver, or HeidiSQL).

### Option 1: Command Line (CLI)

Run the following commands in your shell from the project directory:

1. **Import Database Schema:**
   ```bash
   mysql -u root inveetaire < database/schema.sql
   ```

2. **Import Seed Data:**
   ```bash
   mysql -u root inveetaire < database/seed.sql
   ```

*(Replace `root` and `inveetaire` with your specific database username and database name if different).*

### Option 2: phpMyAdmin or Database Clients

1. Open your database management tool and select the `inveetaire` database.
2. Go to the **Import** tab.
3. Choose `database/schema.sql` and run the import.
4. Go to the **Import** tab again, choose `database/seed.sql`, and run the import.

---

## File Manifest

* [schema.sql](schema.sql): Complete database table definitions, indices, and foreign keys. Deferred ALTER statements are placed at the end of the script to avoid dependency ordering conflicts.
* [seed.sql](seed.sql): Idempotent seed data for roles, event types, commercial plans, themes, versions, and system configuration overrides.
