-- Admin rights final patch
-- Run this once.

UPDATE users
SET role = 'admin',
    is_active = 1
WHERE username = 'admin';

CREATE TABLE IF NOT EXISTS project_edit_permissions (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT,
    user_id INT UNSIGNED NOT NULL,
    project_id INT UNSIGNED NOT NULL,
    can_edit TINYINT(1) NOT NULL DEFAULT 1,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (id),
    UNIQUE KEY uq_project_edit_permissions (user_id, project_id),
    KEY idx_project_edit_permissions_user (user_id),
    KEY idx_project_edit_permissions_project (project_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
