My personal-knowledge-system, with deeply integrated task tracking and long term goal planning capabilities.

feat/db: task table

suri.codes 3a9e8357 1b056403

verified
+134 -7
+5 -1
crates/db/migration/src/lib.rs
··· 1 1 pub use sea_orm_migration::prelude::*; 2 2 3 3 mod m20260318_233726_group_table; 4 + mod m20260319_002245_task_table; 4 5 5 6 pub struct Migrator; 6 7 7 8 #[async_trait::async_trait] 8 9 impl MigratorTrait for Migrator { 9 10 fn migrations() -> Vec<Box<dyn MigrationTrait>> { 10 - vec![Box::new(m20260318_233726_group_table::Migration)] 11 + vec![ 12 + Box::new(m20260318_233726_group_table::Migration), 13 + Box::new(m20260319_002245_task_table::Migration), 14 + ] 11 15 } 12 16 }
+12 -5
crates/db/migration/src/m20260318_233726_group_table.rs
··· 6 6 #[async_trait::async_trait] 7 7 impl MigrationTrait for Migration { 8 8 async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { 9 - // Replace the sample below with your own migration scripts 10 - 11 9 manager 12 10 .create_table( 13 11 Table::create() ··· 57 55 } 58 56 59 57 #[derive(DeriveIden)] 60 - enum Group { 58 + pub enum Group { 61 59 Table, 60 + 62 61 /// Unique integer id 63 62 Id, 63 + 64 64 /// Unique nano-id that is userfacing 65 65 NanoId, 66 + 67 + /// Nano-id of the parent of this group 68 + ParentGroupId, 69 + 66 70 /// Name of the group 67 71 Name, 68 - /// Nano-id of the parent of this group 69 - ParentGroupId, 72 + 70 73 /// Color of this group 71 74 /// NOTE: color is a string that looks like "#FFFFFF" 72 75 Color, 76 + 73 77 /// Priority level of the group 74 78 Priority, 79 + 75 80 /// The relative file path to the location of 76 81 /// the description note for this task 77 82 DescriptionPath, 83 + 78 84 /// Creation time 79 85 CreatedAt, 86 + 80 87 /// Last modified 81 88 ModifiedAt, 82 89 }
+117
crates/db/migration/src/m20260319_002245_task_table.rs
··· 1 + use sea_orm_migration::{prelude::*, schema::*}; 2 + 3 + use crate::m20260318_233726_group_table::Group; 4 + 5 + #[derive(DeriveMigrationName)] 6 + pub struct Migration; 7 + 8 + #[async_trait::async_trait] 9 + impl MigrationTrait for Migration { 10 + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { 11 + manager 12 + .create_table( 13 + Table::create() 14 + .table(Task::Table) 15 + .if_not_exists() 16 + .col(pk_auto(Task::Id)) 17 + .col(string(Task::NanoId).unique_key().not_null()) 18 + .col(string(Task::Name).not_null()) 19 + .col(string(Task::DescriptionPath).not_null()) 20 + .col(integer(Task::Priority).not_null().default(0)) 21 + .col(timestamp(Task::Due).null()) 22 + .col(timestamp(Task::CreatedAt).default(Expr::current_timestamp())) 23 + .col(timestamp(Task::ModifiedAt).default(Expr::current_timestamp())) 24 + .foreign_key( 25 + ForeignKey::create() 26 + .name("fk_task_group_id") // unique constraint name 27 + .from(Task::Table, Task::GroupId) 28 + .to(Group::Table, Group::NanoId) // self-referential to the nano-id 29 + .on_update(ForeignKeyAction::Cascade) 30 + .on_delete(ForeignKeyAction::Cascade), 31 + ) 32 + .to_owned(), 33 + ) 34 + .await?; 35 + 36 + manager 37 + .create_index( 38 + Index::create() 39 + .name("idx_tasks_pub_id") 40 + .table(Task::Table) 41 + .col(Task::NanoId) 42 + .to_owned(), 43 + ) 44 + .await?; 45 + 46 + manager 47 + .create_index( 48 + Index::create() 49 + .name("idx_tasks_group_id") 50 + .table(Task::Table) 51 + .col(Task::GroupId) 52 + .to_owned(), 53 + ) 54 + .await?; 55 + 56 + manager 57 + .create_index( 58 + Index::create() 59 + .name("idx_tasks_due") 60 + .table(Task::Table) 61 + .col(Task::Due) 62 + .to_owned(), 63 + ) 64 + .await 65 + } 66 + 67 + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { 68 + manager 69 + .drop_index(Index::drop().name("idx_tasks_due").to_owned()) 70 + .await?; 71 + 72 + manager 73 + .drop_index(Index::drop().name("idx_tasks_group_id").to_owned()) 74 + .await?; 75 + 76 + manager 77 + .drop_index(Index::drop().name("idx_tasks_pub_id").to_owned()) 78 + .await?; 79 + 80 + manager 81 + .drop_table(Table::drop().table(Task::Table).to_owned()) 82 + .await 83 + } 84 + } 85 + 86 + #[derive(DeriveIden)] 87 + enum Task { 88 + Table, 89 + 90 + /// Unique integer id 91 + Id, 92 + 93 + /// Unique nano-id that is userfacing 94 + NanoId, 95 + 96 + /// Nano-id of the group this task is a part of 97 + GroupId, 98 + 99 + /// Name of the Task 100 + Name, 101 + 102 + /// Priority level of the group 103 + Priority, 104 + 105 + /// The relative file path to the location of 106 + /// the description note for this task 107 + DescriptionPath, 108 + 109 + /// The duedate for this task 110 + Due, 111 + 112 + /// Creation time 113 + CreatedAt, 114 + 115 + /// Last modified 116 + ModifiedAt, 117 + }
-1
crates/db/src/lib.rs
··· 21 21 conn: DatabaseConnection, 22 22 } 23 23 24 - #[expect(dead_code)] 25 24 impl Db { 26 25 async fn connect(path: &Path) -> DbResult<Self> { 27 26 let connection_string = dbg! {format!(