--
-- PostgreSQL database dump
--

\restrict FdwVQAkdhU1Jxr218lV8bnvN6N1NgEpkvs1wtEgWfo8YAS8iltwbPnF2XOeFGFE

-- Dumped from database version 16.10 (Ubuntu 16.10-0ubuntu0.24.04.1)
-- Dumped by pg_dump version 16.10 (Ubuntu 16.10-0ubuntu0.24.04.1)

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- Name: notifications; Type: TABLE; Schema: gamification_system; Owner: postgres
--

-- =====================================================================================
-- Table: notifications
-- Schema: gamification_system
-- Description: Sistema de notificaciones para eventos de gamificación
-- Version: 3.1 (2025-11-08) - Actualizada columna priority con 4 niveles
-- Source of Truth: docs/02-especificaciones-tecnicas/tipos-compartidos/TYPES-NOTIFICATIONS.md
-- =====================================================================================
--
-- CHANGELOG:
-- v3.1 (2025-11-08): Actualizada priority a 4 niveles (agregado 'critical')
-- v3.0 (2025-11-08): Agregada columna priority (notification_priority ENUM)
-- v2.0 (2025-11-07): Actualizado para usar ENUM notification_type
-- v1.0: Creación inicial
--
-- =====================================================================================

CREATE TABLE gamification_system.notifications (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    user_id uuid NOT NULL,
    type gamification_system.notification_type NOT NULL,
    title text NOT NULL,
    message text NOT NULL,
    data jsonb,
    priority gamification_system.notification_priority DEFAULT 'medium'::gamification_system.notification_priority NOT NULL,
    read boolean DEFAULT false NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now()
);


ALTER TABLE gamification_system.notifications OWNER TO gamilit_user;

--
-- Name: TABLE notifications; Type: COMMENT; Schema: gamification_system; Owner: postgres
--

COMMENT ON TABLE gamification_system.notifications IS 'User notifications for various system events';


--
-- Name: COLUMN notifications.type; Type: COMMENT; Schema: gamification_system; Owner: postgres
--

COMMENT ON COLUMN gamification_system.notifications.type IS 'Type of notification using gamification_system.notification_type ENUM (v2.0 - 11 types): achievement_unlocked, rank_up, friend_request, guild_invitation, mission_completed, level_up, message_received, system_announcement, ml_coins_earned, streak_milestone, exercise_feedback. See TYPES-NOTIFICATIONS.md for specifications.';


--
-- Name: COLUMN notifications.data; Type: COMMENT; Schema: gamification_system; Owner: postgres
--

COMMENT ON COLUMN gamification_system.notifications.data IS 'Additional notification data in JSON format';


--
-- Name: COLUMN notifications.priority; Type: COMMENT; Schema: gamification_system; Owner: postgres
--

COMMENT ON COLUMN gamification_system.notifications.priority IS 'Notification priority using gamification_system.notification_priority ENUM (v1.1 - 4 levels): low (informational), medium (standard, DEFAULT), high (urgent), critical (system alerts/emergencies). Aligns with TYPES-NOTIFICATIONS.md specification.';


--
-- Name: notifications notifications_pkey; Type: CONSTRAINT; Schema: gamification_system; Owner: postgres
--

ALTER TABLE ONLY gamification_system.notifications
    ADD CONSTRAINT notifications_pkey PRIMARY KEY (id);


--
-- Name: idx_notifications_created_at; Type: INDEX; Schema: gamification_system; Owner: postgres
--

CREATE INDEX idx_notifications_created_at ON gamification_system.notifications USING btree (created_at DESC);


--
-- Name: idx_notifications_type; Type: INDEX; Schema: gamification_system; Owner: postgres
--

CREATE INDEX idx_notifications_type ON gamification_system.notifications USING btree (type);


--
-- Name: idx_notifications_user_id; Type: INDEX; Schema: gamification_system; Owner: postgres
--

CREATE INDEX idx_notifications_user_id ON gamification_system.notifications USING btree (user_id);


--
-- Name: idx_notifications_user_read; Type: INDEX; Schema: gamification_system; Owner: postgres
--

CREATE INDEX idx_notifications_user_read ON gamification_system.notifications USING btree (user_id, read);


--
-- Name: notifications notifications_updated_at; Type: TRIGGER; Schema: gamification_system; Owner: postgres
-- NOTE: Trigger movido a archivo separado para evitar duplicación
-- Ver: gamification_system/triggers/18-notifications_updated_at.sql
--


--
-- Name: notifications fk_notifications_user; Type: FK CONSTRAINT; Schema: gamification_system; Owner: postgres
--

ALTER TABLE ONLY gamification_system.notifications
    ADD CONSTRAINT fk_notifications_user FOREIGN KEY (user_id) REFERENCES auth_management.profiles(id) ON DELETE CASCADE;


--
-- Name: TABLE notifications; Type: ACL; Schema: gamification_system; Owner: postgres
--

GRANT ALL ON TABLE gamification_system.notifications TO gamilit_user;


--
-- PostgreSQL database dump complete
--

\unrestrict FdwVQAkdhU1Jxr218lV8bnvN6N1NgEpkvs1wtEgWfo8YAS8iltwbPnF2XOeFGFE

