//! SeaORM migration: create room_notifications table use sea_orm_migration::prelude::*; pub struct Migration; impl MigrationName for Migration { fn name(&self) -> &str { "init" } } #[async_trait::async_trait] impl MigrationTrait for Migration { async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { let sql = include_str!("sql/init.sql"); super::execute_sql(manager, sql).await?; let e = " CREATE OR REPLACE FUNCTION room_message_tsv_trigger() RETURNS trigger LANGUAGE plpgsql AS $function$ BEGIN NEW.content_tsv := to_tsvector('english', NEW.content); RETURN NEW; END; $function$; create or replace trigger room_message_tsv_update before insert or update on room_message for each row execute procedure room_message_tsv_trigger(); DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'notification_type' AND typtype = 'e') THEN CREATE TYPE notification_type AS ENUM ( 'mention', 'invitation', 'role_change', 'room_created', 'room_deleted', 'system_announcement' ); END IF; END $$;"; manager.get_connection().execute_unprepared(e).await?; Ok(()) } }