Add user prefs, update capsule to always exist, fix lifetime bug somehow

This commit is contained in:
2024-09-08 23:25:16 -04:00
parent edaafd6867
commit e6aa8df498
30 changed files with 818 additions and 270 deletions

View File

@@ -1,12 +1,18 @@
pub use sea_orm_migration::prelude::*;
mod m20240813_000001_create_users;
mod m20240906_000002_create_cards;
mod m20240906_000003_create_user_prefs;
pub struct Migrator;
#[async_trait::async_trait]
impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![Box::new(m20240813_000001_create_users::Migration)]
vec![
Box::new(m20240813_000001_create_users::Migration),
Box::new(m20240906_000002_create_cards::Migration),
Box::new(m20240906_000003_create_user_prefs::Migration),
]
}
}

View File

@@ -0,0 +1,32 @@
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> {
// User table
// @todo verify all data saved is length-checked
manager
.create_table(
Table::create()
.table(YugiohCard::Table)
.col(pk_auto(YugiohCard::Id))
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(YugiohCard::Table).to_owned())
.await
}
}
#[derive(DeriveIden)]
pub enum YugiohCard {
Table,
Id,
}

View File

@@ -0,0 +1,75 @@
use crate::m20240813_000001_create_users::User;
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> {
// User table
// @todo verify all data saved is length-checked
manager
.create_table(
Table::create()
.table(UserPrefEntry::Table)
.col(pk_auto(UserPrefEntry::Id))
.col(boolean(UserPrefEntry::LoadLocalCardData))
.to_owned(),
)
.await?;
// User to UserPref assoc
manager
.create_table(
Table::create()
.table(UserToUserPref::Table)
.col(integer(UserToUserPref::UserId))
.col(integer(UserToUserPref::UserPrefId))
.primary_key(
Index::create()
.name("pk-user_to_user_pref")
.col(UserToUserPref::UserId)
.col(UserToUserPref::UserPrefId),
)
.foreign_key(
ForeignKey::create()
.name("fk-user_to_user_pref-user_id")
.from(UserToUserPref::Table, UserToUserPref::UserId)
.to(User::Table, User::Id),
)
.foreign_key(
ForeignKey::create()
.name("fk-user_to_user_pref-user_pref_id")
.from(UserToUserPref::Table, UserToUserPref::UserPrefId)
.to(UserPrefEntry::Table, UserPrefEntry::Id),
)
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(UserToUserPref::Table).to_owned())
.await?;
manager
.drop_table(Table::drop().table(UserPrefEntry::Table).to_owned())
.await
}
}
#[derive(DeriveIden)]
pub enum UserPrefEntry {
Table,
Id,
LoadLocalCardData,
}
// Assoc
#[derive(DeriveIden)]
enum UserToUserPref {
Table,
UserId,
UserPrefId,
}