d4c836aef91b0171a994afd57ae487d5ea91d4db / migration / src / m20261025_000015_create_ap_reactions.rs
Raw
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> {
manager
.get_connection()
.execute_unprepared(
r#"
CREATE TABLE ap_reactions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
note_id INTEGER NOT NULL,
kind TEXT NOT NULL,
emoji TEXT,
remote_actor_id INTEGER,
local_user_id INTEGER,
activity_id TEXT,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (note_id) REFERENCES ap_notes(id) ON DELETE CASCADE,
FOREIGN KEY (remote_actor_id) REFERENCES ap_remote_actors(id) ON DELETE CASCADE,
FOREIGN KEY (local_user_id) REFERENCES users(id) ON DELETE CASCADE,
CHECK ((remote_actor_id IS NOT NULL) != (local_user_id IS NOT NULL))
);
CREATE UNIQUE INDEX unique_ap_remote_reaction ON ap_reactions (note_id, remote_actor_id, kind, COALESCE(emoji, ''));
CREATE UNIQUE INDEX unique_ap_local_reaction ON ap_reactions (note_id, local_user_id, kind);
"#,
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.get_connection()
.execute_unprepared("DROP TABLE IF EXISTS ap_reactions;")
.await?;
Ok(())
}
}