feat: add reply functionality to thoughts, including database migration and tests
This commit is contained in:
@@ -5,6 +5,8 @@ mod m20250905_000001_init;
|
||||
mod m20250906_100000_add_profile_fields;
|
||||
mod m20250906_130237_add_tags;
|
||||
mod m20250906_134056_add_api_keys;
|
||||
mod m20250906_145148_add_reply_to_thoughts;
|
||||
mod m20250906_145755_add_visibility_to_thoughts;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
@@ -17,6 +19,8 @@ impl MigratorTrait for Migrator {
|
||||
Box::new(m20250906_100000_add_profile_fields::Migration),
|
||||
Box::new(m20250906_130237_add_tags::Migration),
|
||||
Box::new(m20250906_134056_add_api_keys::Migration),
|
||||
Box::new(m20250906_145148_add_reply_to_thoughts::Migration),
|
||||
Box::new(m20250906_145755_add_visibility_to_thoughts::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,46 @@
|
||||
use sea_orm_migration::{prelude::*, schema::*};
|
||||
|
||||
use crate::m20250905_000001_init::Thought;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Thought::Table)
|
||||
.add_column(uuid_null(ThoughtExtension::ReplyToId))
|
||||
.add_foreign_key(
|
||||
TableForeignKey::new()
|
||||
.name("fk_thought_reply_to_id")
|
||||
.from_tbl(Thought::Table)
|
||||
.from_col(ThoughtExtension::ReplyToId)
|
||||
.to_tbl(Thought::Table)
|
||||
.to_col(Thought::Id)
|
||||
.on_delete(ForeignKeyAction::SetNull),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(Thought::Table)
|
||||
.drop_foreign_key(Alias::new("fk_thought_reply_to_id"))
|
||||
.drop_column(ThoughtExtension::ReplyToId)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum ThoughtExtension {
|
||||
ReplyToId,
|
||||
}
|
Reference in New Issue
Block a user