<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `employee_roles` (
            `id`           BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `employee_id`  BIGINT UNSIGNED NOT NULL,
            `role_id`      BIGINT UNSIGNED NOT NULL,
            `assigned_at`  TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `assigned_by`  BIGINT UNSIGNED NULL,
            `expires_at`   TIMESTAMP NULL DEFAULT NULL,
            `is_active`    TINYINT(1) NOT NULL DEFAULT 1,
            UNIQUE KEY `uq_emp_role_active` (`employee_id`, `role_id`, `is_active`),
            INDEX `idx_employee_roles_role` (`role_id`),
            INDEX `idx_employee_roles_expires` (`expires_at`),
            CONSTRAINT `fk_employee_roles_emp` FOREIGN KEY (`employee_id`) REFERENCES `employees`(`id`) ON DELETE CASCADE,
            CONSTRAINT `fk_employee_roles_role` FOREIGN KEY (`role_id`) REFERENCES `roles`(`id`) ON DELETE CASCADE
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `employee_roles`",
];