Computed is_quote node column
This commit is contained in:
parent
c2cfd7e007
commit
074c6f999e
|
@ -60,6 +60,7 @@ pub struct Model {
|
|||
pub thread_id: Option<String>,
|
||||
#[sea_orm(column_name = "updatedAt")]
|
||||
pub updated_at: Option<DateTimeWithTimeZone>,
|
||||
pub is_quote: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
|
|
|
@ -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),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
}
|
|
@ -72,6 +72,7 @@ pub struct NoteBase {
|
|||
pub has_poll: bool,
|
||||
pub file_ids: Vec<String>,
|
||||
pub emojis: EmojiContext,
|
||||
pub is_quote: bool,
|
||||
}
|
||||
|
||||
pack!(PackNoteBase, Required<Id> as id & Required<NoteBase> as note);
|
||||
|
|
Loading…
Reference in New Issue