Computed is_quote node column

This commit is contained in:
Natty 2024-01-07 23:18:19 +01:00
parent c2cfd7e007
commit 074c6f999e
Signed by: natty
GPG Key ID: BF6CB659ADEE60EC
4 changed files with 47 additions and 0 deletions

View File

@ -60,6 +60,7 @@ pub struct Model {
pub thread_id: Option<String>, pub thread_id: Option<String>,
#[sea_orm(column_name = "updatedAt")] #[sea_orm(column_name = "updatedAt")]
pub updated_at: Option<DateTimeWithTimeZone>, pub updated_at: Option<DateTimeWithTimeZone>,
pub is_quote: Option<bool>,
} }
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

View File

@ -5,6 +5,7 @@ mod m20230729_201733_drop_messaging_integrations;
mod m20230729_212237_user_unique_idx; mod m20230729_212237_user_unique_idx;
mod m20230806_142918_drop_featured_note_option; mod m20230806_142918_drop_featured_note_option;
mod m20240107_005747_remove_user_groups; mod m20240107_005747_remove_user_groups;
mod m20240107_220523_generated_is_quote;
pub struct Migrator; pub struct Migrator;
@ -17,6 +18,7 @@ impl MigratorTrait for Migrator {
Box::new(m20230729_212237_user_unique_idx::Migration), Box::new(m20230729_212237_user_unique_idx::Migration),
Box::new(m20230806_142918_drop_featured_note_option::Migration), Box::new(m20230806_142918_drop_featured_note_option::Migration),
Box::new(m20240107_005747_remove_user_groups::Migration), Box::new(m20240107_005747_remove_user_groups::Migration),
Box::new(m20240107_220523_generated_is_quote::Migration),
] ]
} }
} }

View File

@ -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(())
}
}

View File

@ -72,6 +72,7 @@ pub struct NoteBase {
pub has_poll: bool, pub has_poll: bool,
pub file_ids: Vec<String>, pub file_ids: Vec<String>,
pub emojis: EmojiContext, pub emojis: EmojiContext,
pub is_quote: bool,
} }
pack!(PackNoteBase, Required<Id> as id & Required<NoteBase> as note); pack!(PackNoteBase, Required<Id> as id & Required<NoteBase> as note);