diff --git a/ext_calckey_model/entity_ck/src/entities/note.rs b/ext_calckey_model/entity_ck/src/entities/note.rs index 8ec2b61..3248610 100644 --- a/ext_calckey_model/entity_ck/src/entities/note.rs +++ b/ext_calckey_model/entity_ck/src/entities/note.rs @@ -60,6 +60,7 @@ pub struct Model { pub thread_id: Option, #[sea_orm(column_name = "updatedAt")] pub updated_at: Option, + pub is_quote: Option, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/ext_calckey_model/migration/src/lib.rs b/ext_calckey_model/migration/src/lib.rs index b04cc11..f466443 100644 --- a/ext_calckey_model/migration/src/lib.rs +++ b/ext_calckey_model/migration/src/lib.rs @@ -5,6 +5,7 @@ mod m20230729_201733_drop_messaging_integrations; mod m20230729_212237_user_unique_idx; mod m20230806_142918_drop_featured_note_option; mod m20240107_005747_remove_user_groups; +mod m20240107_220523_generated_is_quote; pub struct Migrator; @@ -17,6 +18,7 @@ impl MigratorTrait for Migrator { Box::new(m20230729_212237_user_unique_idx::Migration), Box::new(m20230806_142918_drop_featured_note_option::Migration), Box::new(m20240107_005747_remove_user_groups::Migration), + Box::new(m20240107_220523_generated_is_quote::Migration), ] } } diff --git a/ext_calckey_model/migration/src/m20240107_220523_generated_is_quote.rs b/ext_calckey_model/migration/src/m20240107_220523_generated_is_quote.rs new file mode 100644 index 0000000..75fca48 --- /dev/null +++ b/ext_calckey_model/migration/src/m20240107_220523_generated_is_quote.rs @@ -0,0 +1,43 @@ +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> { + let db = manager.get_connection(); + + db.execute_unprepared( + r#" + ALTER TABLE "note" ADD COLUMN "is_quote" BOOLEAN GENERATED ALWAYS AS ( + "note"."renoteId" IS NOT NULL + AND + ( + note.text IS NOT NULL AND note.text != '' + OR + CARDINALITY(note."fileIds") != 0 + OR + note."hasPoll" = TRUE + ) + ) STORED + "#, + ) + .await?; + + Ok(()) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + let db = manager.get_connection(); + + db.execute_unprepared( + r#" + ALTER TABLE "note" DROP COLUMN "is_quote"; + "#, + ) + .await?; + + Ok(()) + } +} diff --git a/magnetar_sdk/src/types/note.rs b/magnetar_sdk/src/types/note.rs index 0652837..ccf3fd5 100644 --- a/magnetar_sdk/src/types/note.rs +++ b/magnetar_sdk/src/types/note.rs @@ -72,6 +72,7 @@ pub struct NoteBase { pub has_poll: bool, pub file_ids: Vec, pub emojis: EmojiContext, + pub is_quote: bool, } pack!(PackNoteBase, Required as id & Required as note);