<?php

/**
 * FRAM-1099
 * 
 * This merge request adds a new table: `indexing_vector_cache`.
 * 
 * This new table is responsible for storing cached vector embeddings to reduce the amount of calls
 * made to the AI API server.
 */

use Claromentis\Core\DAL;

/** @var \Claromentis\Setup\SetupFacade $migrations */
$logger = $migrations->getLogger();

$logger->notice("Starting migration for FRAM-1104");

$database = $migrations->GetDb();

try {
    $columns = [
        'id'           => 'IDENTITY',
        'user_id'      => 'INT NOT_NULL',
        'title'        => 'VARCHAR(255) NULL',
        'created_at'   => 'INT_DATE',
        'updated_at'   => 'INT_DATE'
    ];

    $database->CreateTable('ai_chats', $columns);

} catch (DAL\Exceptions\TransactionException $exception) {
    $logger->error("Migration failed for FRAM-1104");

    // Rethrow the exception to ensure the migration and upgrade fails
    throw $exception;
}