Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

2.3 KB
Raw Blame
import { Knex } from "knex";

import { TableName } from "../schemas";
import { createOnUpdateTrigger, dropOnUpdateTrigger } from "../utils";

export async function up(knex: Knex): Promise<void> {
  await dropOnUpdateTrigger(knex, TableName.AgentVaultSessionLogChunk);
  await knex.schema.dropTableIfExists(TableName.AgentVaultSessionLogChunk);

  if (await knex.schema.hasColumn(TableName.AgentVaultSessionLogConfig, "storedChunkCount")) {
    await knex.schema.alterTable(TableName.AgentVaultSessionLogConfig, (t) => {
      t.dropColumn("storedChunkCount");
    });
  }
}

export async function down(knex: Knex): Promise<void> {
  if (!(await knex.schema.hasColumn(TableName.AgentVaultSessionLogConfig, "storedChunkCount"))) {
    await knex.schema.alterTable(TableName.AgentVaultSessionLogConfig, (t) => {
      t.bigint("storedChunkCount").notNullable().defaultTo(0);
    });
  }

  if (await knex.schema.hasTable(TableName.AgentVaultSessionLogChunk)) return;

  await knex.schema.createTable(TableName.AgentVaultSessionLogChunk, (t) => {
    t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid());

    t.uuid("chunkId").notNullable();

    t.uuid("sessionId").notNullable();
    t.foreign("sessionId").references("id").inTable(TableName.AgentVaultSession).onDelete("CASCADE");

    t.string("projectId", 36).notNullable();
    t.foreign("projectId").references("id").inTable(TableName.Project).onDelete("CASCADE");

    t.string("proxyId", 36).notNullable();
    t.string("proxyName", 64).notNullable();

    t.timestamp("startedAt", { useTz: true }).notNullable();
    t.timestamp("endedAt", { useTz: true }).notNullable();

    t.bigint("firstSeq").notNullable();
    t.bigint("lastSeq").notNullable();

    t.integer("recordCount").notNullable();
    t.bigint("droppedCount").notNullable().defaultTo(0);

    t.string("bucket", 255).notNullable();

    t.string("objectKey", 1024).notNullable();
    t.integer("ciphertextBytes").notNullable();
    t.string("iv", 24).notNullable();
    t.string("ciphertextSha256", 43).notNullable();

    t.timestamps(true, true, true);

    t.unique(["sessionId", "chunkId"]);

    t.index(["sessionId", "createdAt"]);
    t.index(["sessionId", "startedAt"]);
    t.index(["projectId"]);
  });

  await createOnUpdateTrigger(knex, TableName.AgentVaultSessionLogChunk);
}