CREATE TABLE IF NOT EXISTS maintenance_agreements (
    id INT AUTO_INCREMENT PRIMARY KEY,
    tenant_id INT NOT NULL,
    owner_user_id INT NOT NULL,
    title VARCHAR(190) NOT NULL,
    client_name VARCHAR(190) NOT NULL,
    frequency VARCHAR(40) NOT NULL,
    status VARCHAR(40) NOT NULL DEFAULT 'active',
    next_run_date DATE NOT NULL,
    address VARCHAR(255) NULL,
    assigned_user_id INT NULL,
    notes TEXT NULL,
    generated_job_count INT NOT NULL DEFAULT 0,
    last_generated_job_id INT NULL,
    last_generated_at DATETIME NULL,
    created_at DATETIME NOT NULL,
    updated_at DATETIME NOT NULL
);
