<?php
require_once '/var/www/config/.env.php';

$db_host = getenv('DB_HOST');
$db_user = getenv('DB_USER');
$db_password = getenv('DB_PASSWORD');
$db_name = getenv('DB_NAME');

$mysqli = new mysqli($db_host, $db_user, $db_password, $db_name);

if ($mysqli->connect_error) {
    die('Erreur connexion : ' . $mysqli->connect_error);
}

$mysqli->set_charset('utf8mb4');

$mysqli->query('
    CREATE TABLE IF NOT EXISTS posts (
        id INT AUTO_INCREMENT PRIMARY KEY,
        comment TEXT NOT NULL,
        image_path VARCHAR(255),
        poster_ip VARCHAR(45) NOT NULL,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    )
');

$mysqli->query('
    CREATE TABLE IF NOT EXISTS rate_limit (
        ip VARCHAR(45) PRIMARY KEY,
        last_post_time BIGINT NOT NULL
    )
');
?>
