2025-05-25 12:56:56 +09:00
|
|
|
use sea_orm_migration::{prelude::*, schema::*};
|
|
|
|
|
|
|
|
use crate::TableMigration;
|
|
|
|
|
|
|
|
#[derive(DeriveMigrationName)]
|
|
|
|
pub struct Migration;
|
|
|
|
|
|
|
|
#[async_trait::async_trait]
|
|
|
|
impl MigrationTrait for Migration {
|
|
|
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
2025-05-25 17:19:37 +09:00
|
|
|
Node::up(manager).await?;
|
2025-05-25 12:56:56 +09:00
|
|
|
RecordDeletion::up(manager).await?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
2025-05-25 17:19:37 +09:00
|
|
|
Node::down(manager).await?;
|
2025-05-25 12:56:56 +09:00
|
|
|
RecordDeletion::down(manager).await?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(DeriveIden)]
|
2025-05-25 17:19:37 +09:00
|
|
|
enum Node {
|
2025-05-25 12:56:56 +09:00
|
|
|
Table,
|
|
|
|
Id,
|
|
|
|
CreatedAt,
|
|
|
|
UpdatedAt,
|
|
|
|
SyncedAt,
|
2025-05-25 17:19:37 +09:00
|
|
|
PeerId,
|
2025-05-25 12:56:56 +09:00
|
|
|
Note,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_trait::async_trait]
|
2025-05-25 17:19:37 +09:00
|
|
|
impl TableMigration for Node {
|
2025-05-25 12:56:56 +09:00
|
|
|
async fn up<'a>(manager: &'a SchemaManager<'a>) -> Result<(), DbErr> {
|
|
|
|
manager.create_table(
|
|
|
|
Table::create()
|
|
|
|
.table(Self::Table)
|
|
|
|
.if_not_exists()
|
|
|
|
.col(pk_uuid(Self::Id))
|
2025-05-25 17:19:37 +09:00
|
|
|
.col(timestamp(Self::CreatedAt))
|
2025-05-25 12:56:56 +09:00
|
|
|
.col(timestamp(Self::UpdatedAt))
|
2025-05-25 17:19:37 +09:00
|
|
|
.col(timestamp_null(Self::SyncedAt))
|
|
|
|
.col(string_len(Self::PeerId, 255))
|
2025-05-25 12:56:56 +09:00
|
|
|
.col(text(Self::Note))
|
|
|
|
.to_owned()
|
|
|
|
).await?;
|
|
|
|
Ok(())
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
async fn down<'a>(manager: &'a SchemaManager<'a>) -> Result<(), DbErr>{
|
|
|
|
manager.drop_table(Table::drop().table(Self::Table).to_owned()).await
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(DeriveIden, DeriveMigrationName)]
|
|
|
|
enum RecordDeletion {
|
|
|
|
Table,
|
|
|
|
Id,
|
|
|
|
CreatedAt,
|
|
|
|
TableName,
|
|
|
|
RecordId,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_trait::async_trait]
|
|
|
|
impl TableMigration for RecordDeletion {
|
|
|
|
async fn up<'a>(manager: &'a SchemaManager<'a>) -> Result<(), DbErr> {
|
|
|
|
manager.create_table(
|
|
|
|
Table::create()
|
|
|
|
.table(Self::Table)
|
|
|
|
.if_not_exists()
|
|
|
|
.col(pk_uuid(Self::Id))
|
|
|
|
.col(timestamp_with_time_zone(Self::CreatedAt))
|
|
|
|
.col(string(Self::TableName))
|
|
|
|
.col(uuid(Self::RecordId))
|
|
|
|
.to_owned()
|
|
|
|
).await?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
async fn down<'a>(manager: &'a SchemaManager<'a>) -> Result<(), DbErr>{
|
|
|
|
manager.drop_table(Table::drop().table(Self::Table).to_owned()).await
|
|
|
|
}
|
|
|
|
}
|