CREATE DATABASE IF NOT EXISTS {{DB_NAME}}
  CHARACTER SET utf8mb4
  COLLATE utf8mb4_unicode_ci;

USE {{DB_NAME}};

CREATE TABLE IF NOT EXISTS users (
  id INT AUTO_INCREMENT PRIMARY KEY,
  username VARCHAR(100) NOT NULL UNIQUE,
  email VARCHAR(255) NOT NULL UNIQUE,
  password VARCHAR(255) NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS posts (
  id INT AUTO_INCREMENT PRIMARY KEY,
  title VARCHAR(255) NOT NULL,
  description TEXT,
  content LONGTEXT NOT NULL,
  author_id INT NOT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (author_id) REFERENCES users(id)
    ON DELETE CASCADE
);

INSERT INTO users (username, email, password)
VALUES (
  'admin',
  'admin@example.com',
  '$2a$12$V1mDeopHyVF0wZAk5dfEneZPBQGhpgwxaYtvdKEj1ZVRzRTLa9VVq'
);
