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

Configure Feed

Select the types of activity you want to include in your feed.

feat/db: group table

+84 -43
+2 -2
crates/db/migration/src/lib.rs
··· 1 1 pub use sea_orm_migration::prelude::*; 2 2 3 - mod m20220101_000001_create_table; 3 + mod m20260318_233726_group_table; 4 4 5 5 pub struct Migrator; 6 6 7 7 #[async_trait::async_trait] 8 8 impl MigratorTrait for Migrator { 9 9 fn migrations() -> Vec<Box<dyn MigrationTrait>> { 10 - vec![Box::new(m20220101_000001_create_table::Migration)] 10 + vec![Box::new(m20260318_233726_group_table::Migration)] 11 11 } 12 12 }
-41
crates/db/migration/src/m20220101_000001_create_table.rs
··· 1 - use sea_orm_migration::{prelude::*, schema::*}; 2 - 3 - #[derive(DeriveMigrationName)] 4 - pub struct Migration; 5 - 6 - #[async_trait::async_trait] 7 - impl MigrationTrait for Migration { 8 - async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { 9 - // Replace the sample below with your own migration scripts 10 - todo!(); 11 - 12 - manager 13 - .create_table( 14 - Table::create() 15 - .table(Post::Table) 16 - .if_not_exists() 17 - .col(pk_auto(Post::Id)) 18 - .col(string(Post::Title)) 19 - .col(string(Post::Text)) 20 - .to_owned(), 21 - ) 22 - .await 23 - } 24 - 25 - async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { 26 - // Replace the sample below with your own migration scripts 27 - todo!(); 28 - 29 - manager 30 - .drop_table(Table::drop().table(Post::Table).to_owned()) 31 - .await 32 - } 33 - } 34 - 35 - #[derive(DeriveIden)] 36 - enum Post { 37 - Table, 38 - Id, 39 - Title, 40 - Text, 41 - }
+82
crates/db/migration/src/m20260318_233726_group_table.rs
··· 1 + use sea_orm_migration::{prelude::*, schema::*}; 2 + 3 + #[derive(DeriveMigrationName)] 4 + pub struct Migration; 5 + 6 + #[async_trait::async_trait] 7 + impl MigrationTrait for Migration { 8 + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { 9 + // Replace the sample below with your own migration scripts 10 + 11 + manager 12 + .create_table( 13 + Table::create() 14 + .table(Group::Table) 15 + .if_not_exists() 16 + .col(pk_auto(Group::Id)) 17 + .col(string(Group::NanoId).unique_key().not_null()) 18 + .col(string(Group::Name).not_null()) 19 + //Note: Color is a hex color with the leading # 20 + .col(string(Group::Color).not_null()) 21 + .col(string(Group::DescriptionPath).not_null()) 22 + .col(integer(Group::Priority).not_null().default(0)) 23 + .col(timestamp(Group::CreatedAt).default(Expr::current_timestamp())) 24 + .col(timestamp(Group::ModifiedAt).default(Expr::current_timestamp())) 25 + .foreign_key( 26 + ForeignKey::create() 27 + .name("fk_group_parent_id") // unique constraint name 28 + .from(Group::Table, Group::ParentGroupId) 29 + .to(Group::Table, Group::NanoId) // self-referential to the nano-id 30 + .on_update(ForeignKeyAction::Cascade) 31 + .on_delete(ForeignKeyAction::Cascade), 32 + ) 33 + .to_owned(), 34 + ) 35 + .await?; 36 + 37 + manager 38 + .create_index( 39 + Index::create() 40 + .name("idx_groups_pub_id") 41 + .table(Group::Table) 42 + .col(Group::NanoId) 43 + .to_owned(), 44 + ) 45 + .await 46 + } 47 + 48 + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { 49 + manager 50 + .drop_index(Index::drop().name("idx_groups_pub_id").to_owned()) 51 + .await?; 52 + 53 + manager 54 + .drop_table(Table::drop().table(Group::Table).to_owned()) 55 + .await 56 + } 57 + } 58 + 59 + #[derive(DeriveIden)] 60 + enum Group { 61 + Table, 62 + /// Unique integer id 63 + Id, 64 + /// Unique nano-id that is userfacing 65 + NanoId, 66 + /// Name of the group 67 + Name, 68 + /// Nano-id of the parent of this group 69 + ParentGroupId, 70 + /// Color of this group 71 + /// NOTE: color is a string that looks like "#FFFFFF" 72 + Color, 73 + /// Priority level of the group 74 + Priority, 75 + /// The relative file path to the location of 76 + /// the description note for this task 77 + DescriptionPath, 78 + /// Creation time 79 + CreatedAt, 80 + /// Last modified 81 + ModifiedAt, 82 + }