feat: Add migration scripts for agents and public key revocations

This commit is contained in:
GW_MC
2026-03-21 03:09:22 +00:00
parent 3800e38463
commit 9640f03d69
4 changed files with 129 additions and 1 deletions

View File

@@ -1,9 +1,16 @@
pub use sea_orm_migration::prelude::*;
mod m20260301_000001_create_agents;
mod m20260301_000002_create_public_key_revokaction;
pub struct Migrator;
#[async_trait::async_trait]
impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![]
vec![
Box::new(m20260301_000001_create_agents::Migration),
Box::new(m20260301_000002_create_public_key_revokaction::Migration),
]
}
}

View File

@@ -0,0 +1,61 @@
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(Agents::Table)
.if_not_exists()
.col(ColumnDef::new(Agents::Id).uuid().not_null().primary_key())
.col(ColumnDef::new(Agents::Name).string().not_null())
.col(ColumnDef::new(Agents::IpAddress).string())
.col(ColumnDef::new(Agents::Version).string())
.col(ColumnDef::new(Agents::State).string().not_null())
.col(ColumnDef::new(Agents::DeploymentMode).string())
.col(ColumnDef::new(Agents::LastSeenAt).timestamp_with_time_zone())
.col(ColumnDef::new(Agents::Capabilities).json())
.col(ColumnDef::new(Agents::PublicKeyHash).string())
.col(ColumnDef::new(Agents::Labels).json())
.col(
ColumnDef::new(Agents::CreatedAt)
.timestamp_with_time_zone()
.not_null(),
)
.col(
ColumnDef::new(Agents::UpdatedAt)
.timestamp_with_time_zone()
.not_null(),
)
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(Agents::Table).to_owned())
.await
}
}
#[derive(DeriveIden)]
enum Agents {
Table,
Id,
Name,
IpAddress,
Version,
State,
DeploymentMode,
LastSeenAt,
Capabilities,
PublicKeyHash,
Labels,
CreatedAt,
UpdatedAt,
}

View File

@@ -0,0 +1,59 @@
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> {
let table = manager
.create_table(
Table::create()
.table(PublicKeyRevocations::Table)
.if_not_exists()
.col(
ColumnDef::new(PublicKeyRevocations::Id)
.uuid()
.not_null()
.primary_key(),
)
.col(
ColumnDef::new(PublicKeyRevocations::PublicKeyHash)
.string()
.not_null(),
)
.col(
ColumnDef::new(PublicKeyRevocations::CreatedAt)
.timestamp_with_time_zone()
.not_null(),
)
.to_owned(),
)
.await?;
// add index on PublicKeyHash for faster lookups
manager
.create_index(
Index::create()
.name("idx_public_key_hash")
.table(PublicKeyRevocations::Table)
.col(PublicKeyRevocations::PublicKeyHash)
.to_owned(),
)
.await?;
Ok(table)
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(PublicKeyRevocations::Table).to_owned())
.await
}
}
#[derive(DeriveIden)]
enum PublicKeyRevocations {
Table,
Id,
PublicKeyHash,
CreatedAt,
}