feature/grpc-connector #1
@@ -14,3 +14,4 @@ async-std = { version = "1", features = ["attributes", "tokio1"] }
|
||||
[dependencies.sea-orm-migration]
|
||||
version = "2.0.0-rc"
|
||||
features = ["runtime-tokio-rustls", "sqlx-postgres"]
|
||||
|
||||
|
||||
@@ -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),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
61
crates/migration/src/m20260301_000001_create_agents.rs
Normal file
61
crates/migration/src/m20260301_000001_create_agents.rs
Normal 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,
|
||||
}
|
||||
@@ -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,
|
||||
}
|
||||
Reference in New Issue
Block a user