bitrouter 1.0.0-alpha.32

BitRouter: an LLM API router. CLI + assembly library.
Documentation
//! Separate durable ACP content from the content-free routing ledger.
use sea_orm_migration::prelude::*;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .create_table(
                Table::create()
                    .table(Alias::new("acp_capture_connections"))
                    .if_not_exists()
                    .col(
                        ColumnDef::new(Alias::new("connection_id"))
                            .string_len(64)
                            .not_null(),
                    )
                    .col(ColumnDef::new(Alias::new("owner")).text().not_null())
                    .col(ColumnDef::new(Alias::new("source")).text().not_null())
                    .col(ColumnDef::new(Alias::new("controller_instance_id")).text())
                    .col(ColumnDef::new(Alias::new("route_scope_id")).text())
                    .col(ColumnDef::new(Alias::new("state")).text().not_null())
                    .col(ColumnDef::new(Alias::new("head")).big_integer().not_null())
                    .col(ColumnDef::new(Alias::new("started_at")).text().not_null())
                    .col(
                        ColumnDef::new(Alias::new("metadata_json"))
                            .text()
                            .not_null(),
                    )
                    .primary_key(Index::create().col(Alias::new("connection_id")))
                    .to_owned(),
            )
            .await?;
        manager
            .create_table(
                Table::create()
                    .table(Alias::new("acp_canonical_sessions"))
                    .if_not_exists()
                    .col(
                        ColumnDef::new(Alias::new("session_key"))
                            .string_len(64)
                            .not_null(),
                    )
                    .col(ColumnDef::new(Alias::new("owner")).text().not_null())
                    .col(ColumnDef::new(Alias::new("source")).text().not_null())
                    .col(
                        ColumnDef::new(Alias::new("native_session_id"))
                            .text()
                            .not_null(),
                    )
                    .col(ColumnDef::new(Alias::new("head")).big_integer().not_null())
                    .col(
                        ColumnDef::new(Alias::new("history_origin"))
                            .text()
                            .not_null(),
                    )
                    .col(ColumnDef::new(Alias::new("parent_key")).string_len(64))
                    .col(ColumnDef::new(Alias::new("parent_watermark")).big_integer())
                    .col(ColumnDef::new(Alias::new("deleted")).boolean().not_null())
                    .primary_key(Index::create().col(Alias::new("session_key")))
                    .to_owned(),
            )
            .await?;
        manager
            .create_table(
                Table::create()
                    .table(Alias::new("acp_capture_events"))
                    .if_not_exists()
                    .col(
                        ColumnDef::new(Alias::new("connection_id"))
                            .string_len(64)
                            .not_null(),
                    )
                    .col(
                        ColumnDef::new(Alias::new("sequence"))
                            .big_integer()
                            .not_null(),
                    )
                    .col(ColumnDef::new(Alias::new("session_key")).string_len(64))
                    .col(ColumnDef::new(Alias::new("session_sequence")).big_integer())
                    .col(ColumnDef::new(Alias::new("replay")).boolean().not_null())
                    .col(ColumnDef::new(Alias::new("event_json")).text().not_null())
                    .col(ColumnDef::new(Alias::new("captured_at")).text().not_null())
                    .primary_key(
                        Index::create()
                            .col(Alias::new("connection_id"))
                            .col(Alias::new("sequence")),
                    )
                    .to_owned(),
            )
            .await?;
        manager
            .create_index(
                Index::create()
                    .name("idx_acp_session_sequence")
                    .table(Alias::new("acp_capture_events"))
                    .col(Alias::new("session_key"))
                    .col(Alias::new("session_sequence"))
                    .unique()
                    .to_owned(),
            )
            .await?;
        Ok(())
    }
    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .drop_table(
                Table::drop()
                    .table(Alias::new("acp_capture_events"))
                    .to_owned(),
            )
            .await?;
        manager
            .drop_table(
                Table::drop()
                    .table(Alias::new("acp_canonical_sessions"))
                    .to_owned(),
            )
            .await?;
        manager
            .drop_table(
                Table::drop()
                    .table(Alias::new("acp_capture_connections"))
                    .to_owned(),
            )
            .await?;
        Ok(())
    }
}