feat: add migration for cache table with necessary columns and indexes
This commit is contained in:
@@ -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),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
61
crates/migration/src/m20260528_110733_create_cache_table.rs
Normal file
61
crates/migration/src/m20260528_110733_create_cache_table.rs
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user