Replace individual Rust migration modules with a define_sql_migrations macro that reads up/down SQL files via include_str!. Consolidate all legacy single-file SQL into per-table directories and add full schema migration coverage for 90+ tables.
34 lines
843 B
PL/PgSQL
34 lines
843 B
PL/PgSQL
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
|
|
$$;
|