//! Visual (focus) mode: each user's default view, and per-topic read state
//! for the "new" / "N unread" markers on topic tiles.
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
.alter_table(
Table::alter()
.table(Users::Table)
.add_column(ColumnDef::new(Users::PreferredView).string_len(16).not_null().default("list"))
.to_owned(),
)
.await?;
manager
.create_table(
Table::create()
.table(TopicReads::Table)
.if_not_exists()
.col(ColumnDef::new(TopicReads::UserId).uuid().not_null())
.col(ColumnDef::new(TopicReads::TopicId).uuid().not_null())
// Highest post_number the user has had on screen.
.col(ColumnDef::new(TopicReads::LastReadPostNumber).integer().not_null())
.col(ColumnDef::new(TopicReads::UpdatedAt).timestamp_with_time_zone().not_null())
.primary_key(Index::create().col(TopicReads::UserId).col(TopicReads::TopicId))
.foreign_key(
ForeignKey::create()
.from(TopicReads::Table, TopicReads::UserId)
.to(Users::Table, Users::Id)
.on_delete(ForeignKeyAction::Cascade),
)
.foreign_key(
ForeignKey::create()
.from(TopicReads::Table, TopicReads::TopicId)
.to(Topics::Table, Topics::Id)
.on_delete(ForeignKeyAction::Cascade),
)
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager.drop_table(Table::drop().table(TopicReads::Table).to_owned()).await?;
manager
.alter_table(Table::alter().table(Users::Table).drop_column(Users::PreferredView).to_owned())
.await
}
}
#[derive(DeriveIden)]
enum Users {
Table,
Id,
PreferredView,
}
#[derive(DeriveIden)]
enum Topics {
Table,
Id,
}
#[derive(DeriveIden)]
enum TopicReads {
Table,
UserId,
TopicId,
LastReadPostNumber,
UpdatedAt,
}
neiam
/recourse
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
Log in to mark this repository.
2.5 KiB · text
History
263b40b