<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20260404100000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Create conversation_turn table for per-turn token usage audit';
}
public function up(Schema $schema): void
{
if (!$schema->hasTable('conversation_turn')) {
$this->addSql('CREATE TABLE conversation_turn (
id INT AUTO_INCREMENT NOT NULL,
user_id INT NOT NULL,
conversation_id VARCHAR(64) NOT NULL,
turn_index SMALLINT UNSIGNED NOT NULL DEFAULT 0,
tool_name VARCHAR(64) DEFAULT NULL,
tool_args_summary VARCHAR(255) DEFAULT NULL,
input_tokens INT UNSIGNED NOT NULL DEFAULT 0,
output_tokens INT UNSIGNED NOT NULL DEFAULT 0,
cache_read_tokens INT UNSIGNED NOT NULL DEFAULT 0,
cache_creation_tokens INT UNSIGNED NOT NULL DEFAULT 0,
cost_usd DECIMAL(10,6) DEFAULT NULL,
created_at DATETIME NOT NULL,
INDEX idx_conversation_turn_user_conv (user_id, conversation_id),
CONSTRAINT fk_conversation_turn_user FOREIGN KEY (user_id) REFERENCES user (id),
PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');
}
}
public function down(Schema $schema): void
{
if ($schema->hasTable('conversation_turn')) {
$this->addSql('DROP TABLE conversation_turn');
}
}
}