feat: add migration for cache table with necessary columns and indexes

This commit is contained in:
GW_MC
2026-05-28 13:13:28 +00:00
parent 52a096d934
commit aa6496de59
5 changed files with 89 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ pub use sea_orm_migration::prelude::*;
mod m20260526_062833_create_account_table;
mod m20260526_110957_create_transcations_table;
mod m20260528_110733_create_cache_table;
pub struct Migrator;
@@ -11,6 +12,7 @@ impl MigratorTrait for Migrator {
vec![
Box::new(m20260526_062833_create_account_table::Migration),
Box::new(m20260526_110957_create_transcations_table::Migration),
Box::new(m20260528_110733_create_cache_table::Migration),
]
}
}

View File

@@ -0,0 +1,61 @@
use sea_orm_migration::{prelude::*, schema::*};
#[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("cache")
.comment("2 level cache for general use")
.if_not_exists()
.col(string("category").not_null().comment("Cache category"))
.col(string("key").not_null().comment("Cache key"))
.col(string("value").not_null().comment("Cache value"))
.col(
boolean("is_invalidated")
.not_null()
.comment("Whether the cache is manually invalidated"),
)
.col(string("expire_at").null().comment("Expiration time"))
.col(string("created_at").not_null().comment("Creation time"))
.col(string("updated_at").not_null().comment("Last update time"))
//
.primary_key(Index::create().col("category").col("key"))
//
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_cache_category")
.table("cache")
.col("category")
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_cache_expire_at")
.table("cache")
.col("expire_at")
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table("cache").to_owned())
.await
}
}