migrations/Version20260404100000.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. final class Version20260404100000 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Create conversation_turn table for per-turn token usage audit';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         if (!$schema->hasTable('conversation_turn')) {
  15.             $this->addSql('CREATE TABLE conversation_turn (
  16.                 id INT AUTO_INCREMENT NOT NULL,
  17.                 user_id INT NOT NULL,
  18.                 conversation_id VARCHAR(64) NOT NULL,
  19.                 turn_index SMALLINT UNSIGNED NOT NULL DEFAULT 0,
  20.                 tool_name VARCHAR(64) DEFAULT NULL,
  21.                 tool_args_summary VARCHAR(255) DEFAULT NULL,
  22.                 input_tokens INT UNSIGNED NOT NULL DEFAULT 0,
  23.                 output_tokens INT UNSIGNED NOT NULL DEFAULT 0,
  24.                 cache_read_tokens INT UNSIGNED NOT NULL DEFAULT 0,
  25.                 cache_creation_tokens INT UNSIGNED NOT NULL DEFAULT 0,
  26.                 cost_usd DECIMAL(10,6) DEFAULT NULL,
  27.                 created_at DATETIME NOT NULL,
  28.                 INDEX idx_conversation_turn_user_conv (user_id, conversation_id),
  29.                 CONSTRAINT fk_conversation_turn_user FOREIGN KEY (user_id) REFERENCES user (id),
  30.                 PRIMARY KEY (id)
  31.             ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB');
  32.         }
  33.     }
  34.     public function down(Schema $schema): void
  35.     {
  36.         if ($schema->hasTable('conversation_turn')) {
  37.             $this->addSql('DROP TABLE conversation_turn');
  38.         }
  39.     }
  40. }