use sea_orm_migration::prelude::*;
use sea_orm_migration::sea_orm::ConnectionTrait;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.get_connection()
.execute_unprepared(
r"
ALTER TABLE edge ADD COLUMN IF NOT EXISTS scope_attribute TEXT;
ALTER TABLE edge ADD COLUMN IF NOT EXISTS scope_value TEXT;
-- Partial: only declared edges are ever looked up this way, and they are the
-- minority of a graph that also holds analysis edges and unscoped writes.
CREATE INDEX IF NOT EXISTS edge_scope_idx
ON edge (tenant_id, scope_attribute, scope_value)
WHERE scope_attribute IS NOT NULL;
",
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.get_connection()
.execute_unprepared(
r"
DROP INDEX IF EXISTS edge_scope_idx;
ALTER TABLE edge DROP COLUMN IF EXISTS scope_value;
ALTER TABLE edge DROP COLUMN IF EXISTS scope_attribute;
",
)
.await?;
Ok(())
}
}