🐸 Frogue(Fed)

~ololduck/Frogue

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> {
        // Store remote notes from actors we follow
        // object_url is the canonical ActivityPub ID (unique to prevent duplicates)
        manager
            .get_connection()
            .execute_unprepared(
                "CREATE TABLE IF NOT EXISTS ap_remote_notes (
                    id INTEGER PRIMARY KEY AUTOINCREMENT,
                    remote_actor_id INTEGER NOT NULL,
                    object_url TEXT NOT NULL UNIQUE,
                    content_html TEXT NOT NULL,
                    published TIMESTAMP WITH TIME ZONE NOT NULL,
                    received_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
                    FOREIGN KEY (remote_actor_id) REFERENCES ap_remote_actors(id) ON DELETE CASCADE
                )",
            )
            .await?;

        Ok(())
    }

    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager
            .get_connection()
            .execute_unprepared("DROP TABLE IF EXISTS ap_remote_notes")
            .await?;

        Ok(())
    }
}