--
--


-- Started on 2025-05-26 20:05:03

SELECT pg_catalog.set_config('search_path', '', false);

--
-- TOC entry 6 (class 2615 OID 2200)
-- Name: public; Type: SCHEMA; Schema: -; Owner: pg_database_owner
--

CREATE SCHEMA public;


ALTER SCHEMA public OWNER TO pg_database_owner;

--
-- TOC entry 5047 (class 0 OID 0)
-- Dependencies: 6
-- Name: SCHEMA public; Type: COMMENT; Schema: -; Owner: pg_database_owner
--

COMMENT ON SCHEMA public IS 'standard public schema';


--
-- TOC entry 1873 (class 1247 OID 153840)
-- Name: advertisement_status_enum; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.advertisement_status_enum AS ENUM (
    'pending',
    'active',
    'expired',
    'rejected',
    'suspended'
);


ALTER TYPE public.advertisement_status_enum OWNER TO postgres;

--
-- TOC entry 1717 (class 1247 OID 151346)
-- Name: boost_type; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.boost_type AS ENUM (
    'daily',
    'weekly',
    'monthly'
);


ALTER TYPE public.boost_type OWNER TO postgres;

--
-- TOC entry 1855 (class 1247 OID 153282)
-- Name: contact_type_enum; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.contact_type_enum AS ENUM (
    'whatsapp',
    'phone'
);


ALTER TYPE public.contact_type_enum OWNER TO postgres;

--
-- TOC entry 1909 (class 1247 OID 161844)
-- Name: credit_reference_type_enum; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.credit_reference_type_enum AS ENUM (
    'manual',
    'subscription',
    'boost',
    'listing',
    'promotional_welcome',
    'refund'
);


ALTER TYPE public.credit_reference_type_enum OWNER TO postgres;

--
-- TOC entry 1771 (class 1247 OID 152088)
-- Name: credit_transaction_type; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.credit_transaction_type AS ENUM (
    'add',
    'deduct',
    'refund'
);


ALTER TYPE public.credit_transaction_type OWNER TO postgres;

--
-- TOC entry 1825 (class 1247 OID 152412)
-- Name: enum_boost_requests_status; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.enum_boost_requests_status AS ENUM (
    'pending',
    'approved',
    'rejected',
    'cancelled'
);


ALTER TYPE public.enum_boost_requests_status OWNER TO postgres;

--
-- TOC entry 1822 (class 1247 OID 152404)
-- Name: enum_boost_requests_type; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.enum_boost_requests_type AS ENUM (
    'daily',
    'weekly',
    'monthly'
);


ALTER TYPE public.enum_boost_requests_type OWNER TO postgres;

--
-- TOC entry 1819 (class 1247 OID 152397)
-- Name: enum_boosts_type; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.enum_boosts_type AS ENUM (
    'daily',
    'weekly',
    'monthly'
);


ALTER TYPE public.enum_boosts_type OWNER TO postgres;

--
-- TOC entry 1828 (class 1247 OID 152471)
-- Name: enum_credit_requests_status; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.enum_credit_requests_status AS ENUM (
    'pending',
    'approved',
    'rejected'
);


ALTER TYPE public.enum_credit_requests_status OWNER TO postgres;

--
-- TOC entry 1885 (class 1247 OID 154153)
-- Name: enum_credit_reservations_status; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.enum_credit_reservations_status AS ENUM (
    'pending',
    'used',
    'released'
);


ALTER TYPE public.enum_credit_reservations_status OWNER TO postgres;

--
-- TOC entry 1912 (class 1247 OID 161896)
-- Name: enum_credit_transactions_credit_type; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.enum_credit_transactions_credit_type AS ENUM (
    'regular',
    'promotional'
);


ALTER TYPE public.enum_credit_transactions_credit_type OWNER TO postgres;

--
-- TOC entry 1813 (class 1247 OID 152357)
-- Name: enum_credit_transactions_type; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.enum_credit_transactions_type AS ENUM (
    'deposit',
    'withdrawal',
    'purchase',
    'refund'
);


ALTER TYPE public.enum_credit_transactions_type OWNER TO postgres;

--
-- TOC entry 1801 (class 1247 OID 152310)
-- Name: enum_payments_entity_type; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.enum_payments_entity_type AS ENUM (
    'subscription',
    'listing',
    'boost',
    'credit',
    'advertisement'
);


ALTER TYPE public.enum_payments_entity_type OWNER TO postgres;

--
-- TOC entry 1804 (class 1247 OID 152320)
-- Name: enum_payments_method; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.enum_payments_method AS ENUM (
    'cash',
    'bank_transfer',
    'check',
    'credit'
);


ALTER TYPE public.enum_payments_method OWNER TO postgres;

--
-- TOC entry 1807 (class 1247 OID 152330)
-- Name: enum_payments_status; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.enum_payments_status AS ENUM (
    'paid',
    'pending',
    'cancelled'
);


ALTER TYPE public.enum_payments_status OWNER TO postgres;

--
-- TOC entry 1798 (class 1247 OID 152301)
-- Name: enum_payments_type; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.enum_payments_type AS ENUM (
    'subscription',
    'listing',
    'boosting',
    'credit',
    'advertisement'
);


ALTER TYPE public.enum_payments_type OWNER TO postgres;

--
-- TOC entry 1816 (class 1247 OID 152366)
-- Name: enum_refund_requests_status; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.enum_refund_requests_status AS ENUM (
    'pending',
    'approved',
    'rejected'
);


ALTER TYPE public.enum_refund_requests_status OWNER TO postgres;

--
-- TOC entry 1894 (class 1247 OID 154208)
-- Name: enum_social_media_posts_status; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.enum_social_media_posts_status AS ENUM (
    'pending',
    'published',
    'failed'
);


ALTER TYPE public.enum_social_media_posts_status OWNER TO postgres;

--
-- TOC entry 1789 (class 1247 OID 152263)
-- Name: enum_subscription_plans_type; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.enum_subscription_plans_type AS ENUM (
    'subscription',
    'listing',
    'boost'
);


ALTER TYPE public.enum_subscription_plans_type OWNER TO postgres;

--
-- TOC entry 1735 (class 1247 OID 151396)
-- Name: lead_status; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.lead_status AS ENUM (
    'pending',
    'viewed'
);


ALTER TYPE public.lead_status OWNER TO postgres;

--
-- TOC entry 1708 (class 1247 OID 151306)
-- Name: listing_property_type; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.listing_property_type AS ENUM (
    'apartment',
    'house',
    'villa',
    'land',
    'office',
    'shop',
    'warehouse',
    'other'
);


ALTER TYPE public.listing_property_type OWNER TO postgres;

--
-- TOC entry 1714 (class 1247 OID 151330)
-- Name: listing_status; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.listing_status AS ENUM (
    'draft',
    'pending',
    'active',
    'rejected',
    'sold',
    'rented',
    'suspended',
    'archived'
);


ALTER TYPE public.listing_status OWNER TO postgres;

--
-- TOC entry 1711 (class 1247 OID 151324)
-- Name: listing_transaction_type; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.listing_transaction_type AS ENUM (
    'sale',
    'rent'
);


ALTER TYPE public.listing_transaction_type OWNER TO postgres;

--
-- TOC entry 1879 (class 1247 OID 154048)
-- Name: notification_type; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.notification_type AS ENUM (
    'office_approved',
    'office_rejected',
    'office_pending',
    'office_updated',
    'office_license_updated',
    'listing_approved',
    'listing_rejected',
    'listing_pending',
    'subscription_activated',
    'subscription_cancelled',
    'subscription_expired',
    'subscription_changed',
    'listing_limit_warning',
    'listing_prioritization_reminder',
    'listings_archived',
    'boost_activated',
    'boost_cancelled',
    'boost_request',
    'advertisement_pending',
    'advertisement_activated',
    'advertisement_rejected',
    'advertisement_suspended',
    'advertisement_status_changed',
    'advertisement_expiration_reminder',
    'advertisement_renewal_pending',
    'advertisement_low_ctr',
    'advertisement_milestone',
    'payment_confirmed',
    'additional_listings_purchased',
    'additional_listings_activated',
    'account_suspended',
    'account_unsuspended',
    'credit_added',
    'credit_request_approved',
    'credit_request_rejected'
);


ALTER TYPE public.notification_type OWNER TO postgres;

--
-- TOC entry 1738 (class 1247 OID 151428)
-- Name: office_status; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.office_status AS ENUM (
    'pending',
    'approved',
    'rejected'
);


ALTER TYPE public.office_status OWNER TO postgres;

--
-- TOC entry 1729 (class 1247 OID 151380)
-- Name: payment_method; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.payment_method AS ENUM (
    'cash',
    'bank_transfer',
    'check'
);


ALTER TYPE public.payment_method OWNER TO postgres;

--
-- TOC entry 1732 (class 1247 OID 151388)
-- Name: payment_status; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.payment_status AS ENUM (
    'paid',
    'pending',
    'cancelled'
);


ALTER TYPE public.payment_status OWNER TO postgres;

--
-- TOC entry 1726 (class 1247 OID 151372)
-- Name: payment_type; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.payment_type AS ENUM (
    'subscription',
    'listing',
    'boosting',
    'advertisement'
);


ALTER TYPE public.payment_type OWNER TO postgres;

--
-- TOC entry 1774 (class 1247 OID 152096)
-- Name: reference_type; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.reference_type AS ENUM (
    'subscription',
    'boost',
    'listing',
    'manual',
    'refund'
);


ALTER TYPE public.reference_type OWNER TO postgres;

--
-- TOC entry 1777 (class 1247 OID 152108)
-- Name: refund_status; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.refund_status AS ENUM (
    'pending',
    'approved',
    'rejected'
);


ALTER TYPE public.refund_status OWNER TO postgres;

--
-- TOC entry 1723 (class 1247 OID 151364)
-- Name: subscription_status; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.subscription_status AS ENUM (
    'active',
    'expired',
    'pending',
    'replaced'
);


ALTER TYPE public.subscription_status OWNER TO postgres;

--
-- TOC entry 1720 (class 1247 OID 151354)
-- Name: subscription_type; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.subscription_type AS ENUM (
    'monthly',
    'yearly',
    'premium_monthly',
    'premium_yearly'
);


ALTER TYPE public.subscription_type OWNER TO postgres;

--
-- TOC entry 1705 (class 1247 OID 151298)
-- Name: user_status; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.user_status AS ENUM (
    'active',
    'suspended',
    'banned'
);


ALTER TYPE public.user_status OWNER TO postgres;

--
-- TOC entry 1702 (class 1247 OID 151291)
-- Name: user_type; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public.user_type AS ENUM (
    'regular',
    'office',
    'admin'
);


ALTER TYPE public.user_type OWNER TO postgres;

--
-- TOC entry 854 (class 1255 OID 152768)
-- Name: auto_approve_pending_listings(); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION public.auto_approve_pending_listings() RETURNS void
    LANGUAGE plpgsql
    AS $$
DECLARE
    updated_count INTEGER;
BEGIN
    -- Update listings that have been pending for more than 30 minutes
    UPDATE listings
    SET 
        status = 'active',
        updated_at = NOW()
    WHERE 
        status = 'pending' 
        AND created_at < NOW() - INTERVAL '30 minutes'
    RETURNING COUNT(*) INTO updated_count;
    
    -- Log the number of approved listings (optional)
    RAISE NOTICE 'Auto-approved % listings', updated_count;
END;
$$;


ALTER FUNCTION public.auto_approve_pending_listings() OWNER TO postgres;

--
-- TOC entry 924 (class 1255 OID 154151)
-- Name: update_ad_daily_stats(); Type: FUNCTION; Schema: public; Owner: postgres
--

CREATE FUNCTION public.update_ad_daily_stats() RETURNS void
    LANGUAGE plpgsql
    AS $$
      BEGIN
        -- Insert new records or update existing ones
        INSERT INTO ad_daily_stats (
          id, ad_id, stat_date, views, clicks, ctr, created_at, updated_at
        )
        SELECT 
          gen_random_uuid() as id,
          ad_id,
          stat_date,
          views,
          clicks,
          CASE WHEN views > 0 THEN (clicks::float / views * 100) ELSE NULL END as ctr,
          NOW() as created_at,
          NOW() as updated_at
        FROM (
          SELECT 
            advertisement_id as ad_id,
            date_trunc('day', created_at)::date as stat_date,
            COUNT(*) FILTER (WHERE src = 'views') as views,
            COUNT(*) FILTER (WHERE src = 'clicks') as clicks
          FROM (
            SELECT advertisement_id, created_at, 'views' as src FROM advertisement_views
            WHERE created_at >= CURRENT_DATE - INTERVAL '30 days'
            UNION ALL
            SELECT advertisement_id, created_at, 'clicks' as src FROM advertisement_clicks
            WHERE created_at >= CURRENT_DATE - INTERVAL '30 days'
          ) combined
          GROUP BY ad_id, stat_date
        ) stats
        ON CONFLICT (ad_id, stat_date) 
        DO UPDATE SET 
          views = EXCLUDED.views,
          clicks = EXCLUDED.clicks,
          ctr = EXCLUDED.ctr,
          updated_at = NOW();
      END;
      $$;


ALTER FUNCTION public.update_ad_daily_stats() OWNER TO postgres;



--
-- TOC entry 252 (class 1259 OID 152257)
-- Name: SequelizeMeta; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public."SequelizeMeta" (
    name character varying(255) NOT NULL
);


ALTER TABLE public."SequelizeMeta" OWNER TO postgres;

--
-- TOC entry 270 (class 1259 OID 154135)
-- Name: ad_daily_stats; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.ad_daily_stats (
    id uuid NOT NULL,
    ad_id uuid NOT NULL,
    stat_date date NOT NULL,
    views integer DEFAULT 0 NOT NULL,
    clicks integer DEFAULT 0 NOT NULL,
    ctr numeric(5,2),
    created_at timestamp with time zone NOT NULL,
    updated_at timestamp with time zone NOT NULL
);


ALTER TABLE public.ad_daily_stats OWNER TO postgres;

--
-- TOC entry 5048 (class 0 OID 0)
-- Dependencies: 270
-- Name: COLUMN ad_daily_stats.ctr; Type: COMMENT; Schema: public; Owner: postgres
--

COMMENT ON COLUMN public.ad_daily_stats.ctr IS 'Click-through rate (percentage)';


--
-- TOC entry 258 (class 1259 OID 152564)
-- Name: additional_listings; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.additional_listings (
    id uuid NOT NULL,
    user_id uuid NOT NULL,
    payment_id uuid,
    count integer DEFAULT 1 NOT NULL,
    start_date timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    end_date timestamp without time zone NOT NULL,
    is_active boolean DEFAULT true NOT NULL,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    CONSTRAINT additional_listings_count_check CHECK ((count >= 1)),
    CONSTRAINT check_end_date_after_start CHECK ((end_date > start_date))
);


ALTER TABLE public.additional_listings OWNER TO postgres;

--
-- TOC entry 267 (class 1259 OID 153520)
-- Name: advertisement_clicks; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.advertisement_clicks (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    advertisement_id uuid NOT NULL,
    user_id uuid,
    session_id character varying,
    ip_address character varying,
    user_agent text,
    referrer_url character varying,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP
);


ALTER TABLE public.advertisement_clicks OWNER TO postgres;

--
-- TOC entry 268 (class 1259 OID 153792)
-- Name: advertisement_impressions; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.advertisement_impressions (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    advertisement_id uuid NOT NULL,
    user_id uuid,
    session_id character varying,
    "position" character varying NOT NULL,
    page_url character varying,
    created_at timestamp without time zone DEFAULT now()
);


ALTER TABLE public.advertisement_impressions OWNER TO postgres;

--
-- TOC entry 5049 (class 0 OID 0)
-- Dependencies: 268
-- Name: COLUMN advertisement_impressions.session_id; Type: COMMENT; Schema: public; Owner: postgres
--

COMMENT ON COLUMN public.advertisement_impressions.session_id IS 'Session ID for anonymous users';


--
-- TOC entry 5050 (class 0 OID 0)
-- Dependencies: 268
-- Name: COLUMN advertisement_impressions."position"; Type: COMMENT; Schema: public; Owner: postgres
--

COMMENT ON COLUMN public.advertisement_impressions."position" IS 'Position where ad was displayed';


--
-- TOC entry 266 (class 1259 OID 153498)
-- Name: advertisement_views; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.advertisement_views (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    advertisement_id uuid NOT NULL,
    user_id uuid,
    session_id character varying,
    ip_address character varying,
    user_agent text,
    page_url character varying,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP
);


ALTER TABLE public.advertisement_views OWNER TO postgres;

--
-- TOC entry 265 (class 1259 OID 153457)
-- Name: advertisements; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.advertisements (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    user_id uuid NOT NULL,
    office_id uuid,
    title character varying(100) NOT NULL,
    contact_phone character varying(20) NOT NULL,
    image_url character varying NOT NULL,
    redirect_url character varying,
    size character varying NOT NULL,
    "position" character varying,
    status public.advertisement_status_enum DEFAULT 'pending'::public.advertisement_status_enum,
    start_date timestamp without time zone NOT NULL,
    end_date timestamp without time zone NOT NULL,
    views integer DEFAULT 0,
    clicks integer DEFAULT 0,
    payment_id uuid,
    notes text,
    is_renewed boolean DEFAULT false,
    previous_ad_id uuid,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    display_times jsonb,
    display_days jsonb,
    max_impressions integer,
    max_impressions_per_user integer DEFAULT 5,
    priority integer DEFAULT 5 NOT NULL,
    rotation_weight double precision DEFAULT 1.0 NOT NULL,
    activated_at timestamp without time zone,
    impression_limit_notified boolean DEFAULT false,
    expiration_notified boolean DEFAULT false,
    CONSTRAINT advertisements_size_check CHECK (((size)::text = ANY ((ARRAY['small'::character varying, 'medium'::character varying, 'large'::character varying])::text[]))),
    CONSTRAINT advertisements_status_check CHECK (((status)::text = ANY (ARRAY[('pending'::character varying)::text, ('active'::character varying)::text, ('expired'::character varying)::text, ('rejected'::character varying)::text, ('suspended'::character varying)::text])))
);


ALTER TABLE public.advertisements OWNER TO postgres;

--
-- TOC entry 5051 (class 0 OID 0)
-- Dependencies: 265
-- Name: COLUMN advertisements.display_times; Type: COMMENT; Schema: public; Owner: postgres
--

COMMENT ON COLUMN public.advertisements.display_times IS 'Time slots when ad should display (null = all times)';


--
-- TOC entry 5052 (class 0 OID 0)
-- Dependencies: 265
-- Name: COLUMN advertisements.display_days; Type: COMMENT; Schema: public; Owner: postgres
--

COMMENT ON COLUMN public.advertisements.display_days IS 'Days of week to display (null = all days)';


--
-- TOC entry 5053 (class 0 OID 0)
-- Dependencies: 265
-- Name: COLUMN advertisements.max_impressions; Type: COMMENT; Schema: public; Owner: postgres
--

COMMENT ON COLUMN public.advertisements.max_impressions IS 'Maximum impressions for this ad (null = unlimited)';


--
-- TOC entry 5054 (class 0 OID 0)
-- Dependencies: 265
-- Name: COLUMN advertisements.max_impressions_per_user; Type: COMMENT; Schema: public; Owner: postgres
--

COMMENT ON COLUMN public.advertisements.max_impressions_per_user IS 'Maximum times a single user should see this ad';


--
-- TOC entry 5055 (class 0 OID 0)
-- Dependencies: 265
-- Name: COLUMN advertisements.priority; Type: COMMENT; Schema: public; Owner: postgres
--

COMMENT ON COLUMN public.advertisements.priority IS 'Priority level 1-10, higher gets more exposure';


--
-- TOC entry 5056 (class 0 OID 0)
-- Dependencies: 265
-- Name: COLUMN advertisements.rotation_weight; Type: COMMENT; Schema: public; Owner: postgres
--

COMMENT ON COLUMN public.advertisements.rotation_weight IS 'Weighting factor for random rotation';


--
-- TOC entry 5057 (class 0 OID 0)
-- Dependencies: 265
-- Name: COLUMN advertisements.activated_at; Type: COMMENT; Schema: public; Owner: postgres
--

COMMENT ON COLUMN public.advertisements.activated_at IS 'When ad was activated';


--
-- TOC entry 5058 (class 0 OID 0)
-- Dependencies: 265
-- Name: COLUMN advertisements.impression_limit_notified; Type: COMMENT; Schema: public; Owner: postgres
--

COMMENT ON COLUMN public.advertisements.impression_limit_notified IS 'Whether user was notified about impression limit';


--
-- TOC entry 5059 (class 0 OID 0)
-- Dependencies: 265
-- Name: COLUMN advertisements.expiration_notified; Type: COMMENT; Schema: public; Owner: postgres
--

COMMENT ON COLUMN public.advertisements.expiration_notified IS 'Whether user was notified about expiration';


--
-- TOC entry 274 (class 1259 OID 161498)
-- Name: boost_performances; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.boost_performances (
    id uuid NOT NULL,
    boost_id uuid NOT NULL,
    day date NOT NULL,
    views integer DEFAULT 0 NOT NULL,
    expected_views integer DEFAULT 0 NOT NULL,
    performance_percentage numeric(5,2) DEFAULT 0 NOT NULL,
    cost_per_view numeric(10,4),
    created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
);


ALTER TABLE public.boost_performances OWNER TO postgres;

--
-- TOC entry 246 (class 1259 OID 151613)
-- Name: boosts; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.boosts (
    id uuid DEFAULT public.uuid_generate_v4() NOT NULL,
    listing_id uuid NOT NULL,
    payment_id uuid,
    type public.boost_type NOT NULL,
    start_date timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    end_date timestamp without time zone NOT NULL,
    is_active boolean DEFAULT false NOT NULL,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    priority_level integer DEFAULT 1 NOT NULL,
    view_target integer DEFAULT 0 NOT NULL,
    is_underperforming boolean DEFAULT false NOT NULL,
    last_performance_check timestamp with time zone,
    performance_alerts_sent integer DEFAULT 0 NOT NULL,
    is_homepage_featured boolean DEFAULT false NOT NULL,
    CONSTRAINT boosts_check CHECK ((end_date > start_date))
);


ALTER TABLE public.boosts OWNER TO postgres;

--
-- TOC entry 251 (class 1259 OID 152185)
-- Name: cities; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.cities (
    id uuid DEFAULT public.uuid_generate_v4() NOT NULL,
    name_en character varying NOT NULL,
    name_ar character varying NOT NULL,
    province_en character varying NOT NULL,
    province_ar character varying NOT NULL,
    country_en character varying DEFAULT 'Syria'::character varying NOT NULL,
    country_ar character varying DEFAULT 'سوريا'::character varying NOT NULL,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP
);


ALTER TABLE public.cities OWNER TO postgres;

--
-- TOC entry 256 (class 1259 OID 152477)
-- Name: credit_requests; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.credit_requests (
    id uuid NOT NULL,
    user_id uuid NOT NULL,
    amount numeric(10,2) NOT NULL,
    payment_method character varying(100) DEFAULT 'Sham Cash'::character varying NOT NULL,
    reference_number character varying(100),
    status public.enum_credit_requests_status DEFAULT 'pending'::public.enum_credit_requests_status NOT NULL,
    notes text,
    admin_id uuid,
    processed_at timestamp with time zone,
    created_at timestamp with time zone NOT NULL,
    updated_at timestamp with time zone NOT NULL
);


ALTER TABLE public.credit_requests OWNER TO postgres;

--
-- TOC entry 271 (class 1259 OID 154159)
-- Name: credit_reservations; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.credit_reservations (
    id uuid NOT NULL,
    user_id uuid NOT NULL,
    amount numeric(10,2) NOT NULL,
    description text NOT NULL,
    reference_type character varying(50),
    reference_id uuid,
    status public.enum_credit_reservations_status DEFAULT 'pending'::public.enum_credit_reservations_status,
    created_at timestamp with time zone NOT NULL,
    updated_at timestamp with time zone NOT NULL
);


ALTER TABLE public.credit_reservations OWNER TO postgres;

--
-- TOC entry 250 (class 1259 OID 152131)
-- Name: credit_transactions; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.credit_transactions (
    id uuid NOT NULL,
    user_id uuid NOT NULL,
    amount numeric(10,2) NOT NULL,
    balance_after numeric(10,2) NOT NULL,
    type public.credit_transaction_type NOT NULL,
    description character varying(255) NOT NULL,
    admin_id uuid,
    reference_id uuid,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    user_credit_id uuid NOT NULL,
    reference_code character varying(50),
    payment_id uuid,
    balance_before numeric(10,2) NOT NULL,
    reference_type public.credit_reference_type_enum DEFAULT 'manual'::public.credit_reference_type_enum NOT NULL,
    credit_type public.enum_credit_transactions_credit_type DEFAULT 'regular'::public.enum_credit_transactions_credit_type NOT NULL,
    CONSTRAINT chk_add_transactions_positive CHECK ((((type = 'add'::public.credit_transaction_type) AND (amount > (0)::numeric)) OR ((type = 'deduct'::public.credit_transaction_type) AND (amount < (0)::numeric)) OR ((type = 'refund'::public.credit_transaction_type) AND (amount > (0)::numeric)))),
    CONSTRAINT chk_transaction_amount_not_zero CHECK ((amount <> (0)::numeric)),
    CONSTRAINT credit_transactions_balance_after_check CHECK ((balance_after >= (0)::numeric))
);


ALTER TABLE public.credit_transactions OWNER TO postgres;

--
-- TOC entry 276 (class 1259 OID 161644)
-- Name: device_registrations; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.device_registrations (
    id uuid NOT NULL,
    device_id character varying(255) NOT NULL,
    user_id uuid NOT NULL,
    registration_date timestamp with time zone NOT NULL,
    last_login_date timestamp with time zone,
    device_info text,
    ip_address character varying(50),
    created_at timestamp with time zone NOT NULL,
    updated_at timestamp with time zone NOT NULL
);


ALTER TABLE public.device_registrations OWNER TO postgres;

--
-- TOC entry 243 (class 1259 OID 151503)
-- Name: listing_images; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.listing_images (
    id uuid DEFAULT public.uuid_generate_v4() NOT NULL,
    listing_id uuid NOT NULL,
    url character varying(255) NOT NULL,
    is_main boolean DEFAULT false NOT NULL,
    sort_order integer DEFAULT 0 NOT NULL,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
);


ALTER TABLE public.listing_images OWNER TO postgres;

--
-- TOC entry 264 (class 1259 OID 153287)
-- Name: listing_leads; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.listing_leads (
    id uuid NOT NULL,
    listing_id uuid NOT NULL,
    user_id uuid,
    ip_address character varying(45) NOT NULL,
    session_id character varying(255) NOT NULL,
    user_agent text,
    contact_type public.contact_type_enum NOT NULL,
    created_at timestamp without time zone NOT NULL
);


ALTER TABLE public.listing_leads OWNER TO postgres;

--
-- TOC entry 261 (class 1259 OID 152775)
-- Name: listing_priorities; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.listing_priorities (
    id uuid NOT NULL,
    user_id uuid NOT NULL,
    subscription_id uuid NOT NULL,
    listing_id uuid NOT NULL,
    priority integer DEFAULT 999 NOT NULL,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
);


ALTER TABLE public.listing_priorities OWNER TO postgres;

--
-- TOC entry 244 (class 1259 OID 151517)
-- Name: listing_videos; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.listing_videos (
    id uuid DEFAULT public.uuid_generate_v4() NOT NULL,
    listing_id uuid NOT NULL,
    url character varying(255) NOT NULL,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
);


ALTER TABLE public.listing_videos OWNER TO postgres;

--
-- TOC entry 242 (class 1259 OID 151471)
-- Name: listings; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.listings (
    id uuid DEFAULT public.uuid_generate_v4() NOT NULL,
    user_id uuid NOT NULL,
    office_id uuid,
    title character varying(150) NOT NULL,
    description text NOT NULL,
    property_type public.listing_property_type NOT NULL,
    transaction_type public.listing_transaction_type NOT NULL,
    price numeric(12,2) NOT NULL,
    area numeric(10,2) NOT NULL,
    rooms integer,
    bathrooms integer,
    area_location character varying(100) NOT NULL,
    address character varying(255) NOT NULL,
    latitude numeric(10,8),
    longitude numeric(11,8),
    features jsonb DEFAULT '{}'::jsonb NOT NULL,
    proximities jsonb,
    status public.listing_status DEFAULT 'pending'::public.listing_status NOT NULL,
    rejection_reason text,
    show_phone boolean DEFAULT true NOT NULL,
    is_boosted boolean DEFAULT false NOT NULL,
    boost_type public.boost_type,
    boost_expiry timestamp without time zone,
    views integer DEFAULT 0 NOT NULL,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    city_id uuid NOT NULL,
    neighborhood_id uuid,
    archive_reason character varying(50),
    floor integer,
    salon integer,
    quality_score numeric(4,2) DEFAULT 0 NOT NULL,
    homepage_featured_until timestamp with time zone,
    CONSTRAINT listings_area_check CHECK ((area > (0)::numeric)),
    CONSTRAINT listings_bathrooms_check CHECK (((bathrooms IS NULL) OR (bathrooms >= 0))),
    CONSTRAINT listings_bedrooms_check CHECK (((rooms IS NULL) OR (rooms >= 0))),
    CONSTRAINT listings_latitude_check CHECK (((latitude IS NULL) OR ((latitude >= ('-90'::integer)::numeric) AND (latitude <= (90)::numeric)))),
    CONSTRAINT listings_longitude_check CHECK (((longitude IS NULL) OR ((longitude >= ('-180'::integer)::numeric) AND (longitude <= (180)::numeric)))),
    CONSTRAINT listings_price_check CHECK ((price > (0)::numeric))
);


ALTER TABLE public.listings OWNER TO postgres;

--
-- TOC entry 259 (class 1259 OID 152592)
-- Name: neighborhoods; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.neighborhoods (
    id uuid DEFAULT public.uuid_generate_v4() NOT NULL,
    city_id uuid NOT NULL,
    name_en character varying NOT NULL,
    name_ar character varying NOT NULL,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
    updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP
);


ALTER TABLE public.neighborhoods OWNER TO postgres;

--
-- TOC entry 247 (class 1259 OID 151655)
-- Name: notifications; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.notifications (
    id uuid DEFAULT public.uuid_generate_v4() NOT NULL,
    user_id uuid NOT NULL,
    type public.notification_type NOT NULL,
    content text NOT NULL,
    read boolean DEFAULT false NOT NULL,
    entity_type character varying(50),
    entity_id uuid,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    content_params jsonb DEFAULT '{}'::jsonb NOT NULL
);


ALTER TABLE public.notifications OWNER TO postgres;

--
-- TOC entry 269 (class 1259 OID 154042)
-- Name: notifications_backup; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.notifications_backup (
    id uuid,
    user_id uuid,
    type text,
    content text,
    content_params jsonb,
    read boolean,
    entity_type character varying(50),
    entity_id uuid,
    created_at timestamp without time zone
);


ALTER TABLE public.notifications_backup OWNER TO postgres;

--
-- TOC entry 241 (class 1259 OID 151451)
-- Name: offices; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.offices (
    id uuid DEFAULT public.uuid_generate_v4() NOT NULL,
    user_id uuid NOT NULL,
    name character varying(100) NOT NULL,
    location character varying(100) NOT NULL,
    address character varying(255) NOT NULL,
    description text,
    phone character varying(20) NOT NULL,
    email character varying(100),
    website character varying(255),
    logo character varying(255),
    license_number character varying(50) NOT NULL,
    license_file character varying(255),
    status public.office_status DEFAULT 'pending'::public.office_status NOT NULL,
    rejection_reason text,
    is_premium boolean DEFAULT false NOT NULL,
    average_rating double precision,
    rating_count integer DEFAULT 0 NOT NULL,
    properties_count integer DEFAULT 0 NOT NULL,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    CONSTRAINT offices_average_rating_check CHECK (((average_rating IS NULL) OR ((average_rating >= (1)::double precision) AND (average_rating <= (5)::double precision))))
);


ALTER TABLE public.offices OWNER TO postgres;

--
-- TOC entry 255 (class 1259 OID 152337)
-- Name: payments; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.payments (
    id uuid NOT NULL,
    user_id uuid NOT NULL,
    amount numeric(10,2) NOT NULL,
    currency character varying(3) DEFAULT 'USD'::character varying NOT NULL,
    type public.enum_payments_type NOT NULL,
    entity_type public.enum_payments_entity_type NOT NULL,
    entity_id uuid,
    receipt_number character varying(50),
    reference_code character varying(50),
    method public.enum_payments_method NOT NULL,
    status public.enum_payments_status DEFAULT 'pending'::public.enum_payments_status NOT NULL,
    notes text,
    admin_id uuid,
    created_at timestamp with time zone NOT NULL,
    updated_at timestamp with time zone NOT NULL
);


ALTER TABLE public.payments OWNER TO postgres;

--
-- TOC entry 260 (class 1259 OID 152769)
-- Name: pending_listings_for_approval; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW public.pending_listings_for_approval AS
 SELECT id,
    title,
    status,
    created_at,
    (now() - (created_at)::timestamp with time zone) AS pending_time,
        CASE
            WHEN ((now() - (created_at)::timestamp with time zone) > '00:30:00'::interval) THEN true
            ELSE false
        END AS ready_for_auto_approval
   FROM public.listings
  WHERE (status = 'pending'::public.listing_status);


ALTER VIEW public.pending_listings_for_approval OWNER TO postgres;

--
-- TOC entry 249 (class 1259 OID 151685)
-- Name: ratings; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.ratings (
    id uuid DEFAULT public.uuid_generate_v4() NOT NULL,
    office_id uuid NOT NULL,
    user_id uuid NOT NULL,
    rating integer NOT NULL,
    comment text,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    CONSTRAINT ratings_comment_check CHECK ((length(comment) <= 1000)),
    CONSTRAINT ratings_rating_check CHECK (((rating >= 1) AND (rating <= 5)))
);


ALTER TABLE public.ratings OWNER TO postgres;

--
-- TOC entry 263 (class 1259 OID 152822)
-- Name: scheduled_jobs; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.scheduled_jobs (
    id uuid NOT NULL,
    type character varying(50) NOT NULL,
    data text NOT NULL,
    trigger_at timestamp without time zone NOT NULL,
    processed boolean DEFAULT false NOT NULL,
    result jsonb,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    recurring boolean DEFAULT false NOT NULL,
    recurrence_pattern character varying,
    retries integer DEFAULT 0 NOT NULL
);


ALTER TABLE public.scheduled_jobs OWNER TO postgres;

--
-- TOC entry 262 (class 1259 OID 152803)
-- Name: scheduled_notifications; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.scheduled_notifications (
    id uuid NOT NULL,
    user_id uuid NOT NULL,
    type character varying(50) NOT NULL,
    content text NOT NULL,
    content_params jsonb,
    trigger_at timestamp without time zone NOT NULL,
    processed boolean DEFAULT false NOT NULL,
    entity_type character varying(50),
    entity_id uuid,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    retries integer DEFAULT 0 NOT NULL,
    retries_failed boolean DEFAULT false NOT NULL
);


ALTER TABLE public.scheduled_notifications OWNER TO postgres;

--
-- TOC entry 248 (class 1259 OID 151670)
-- Name: session_tokens; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.session_tokens (
    id uuid DEFAULT public.uuid_generate_v4() NOT NULL,
    user_id uuid NOT NULL,
    token_hash character varying(255) NOT NULL,
    expires_at timestamp without time zone NOT NULL,
    ip_address character varying(45),
    user_agent text,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
);


ALTER TABLE public.session_tokens OWNER TO postgres;

--
-- TOC entry 273 (class 1259 OID 154215)
-- Name: social_media_posts; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.social_media_posts (
    id uuid NOT NULL,
    listing_id uuid NOT NULL,
    platform character varying(50) NOT NULL,
    post_id character varying(255),
    post_url character varying(1000),
    status public.enum_social_media_posts_status DEFAULT 'pending'::public.enum_social_media_posts_status NOT NULL,
    content text,
    media_urls jsonb DEFAULT '[]'::jsonb,
    error text,
    published_at timestamp with time zone,
    created_at timestamp with time zone NOT NULL,
    updated_at timestamp with time zone NOT NULL
);


ALTER TABLE public.social_media_posts OWNER TO postgres;

--
-- TOC entry 253 (class 1259 OID 152269)
-- Name: subscription_plans; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.subscription_plans (
    id uuid NOT NULL,
    name character varying(100) NOT NULL,
    code character varying(50) NOT NULL,
    type public.enum_subscription_plans_type NOT NULL,
    user_type character varying(20) NOT NULL,
    "interval" character varying(20) NOT NULL,
    price numeric(10,2) NOT NULL,
    currency character varying(3) DEFAULT 'USD'::character varying NOT NULL,
    features jsonb DEFAULT '{}'::jsonb NOT NULL,
    active boolean DEFAULT true NOT NULL,
    created_at timestamp with time zone NOT NULL,
    updated_at timestamp with time zone NOT NULL
);


ALTER TABLE public.subscription_plans OWNER TO postgres;

--
-- TOC entry 257 (class 1259 OID 152501)
-- Name: subscriptions; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.subscriptions (
    id uuid NOT NULL,
    office_id uuid NOT NULL,
    payment_id uuid,
    type character varying(15) NOT NULL,
    status character varying(10) DEFAULT 'active'::character varying NOT NULL,
    start_date timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    end_date timestamp without time zone NOT NULL,
    listings_allowed integer DEFAULT 17 NOT NULL,
    is_renewed boolean DEFAULT false NOT NULL,
    previous_subscription_id uuid,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    notes text,
    CONSTRAINT subscriptions_status_check CHECK (((status)::text = ANY (ARRAY[('active'::character varying)::text, ('expired'::character varying)::text, ('cancelled'::character varying)::text, ('replaced'::character varying)::text]))),
    CONSTRAINT subscriptions_type_check CHECK (((type)::text = ANY ((ARRAY['monthly'::character varying, 'yearly'::character varying, 'premium_monthly'::character varying, 'premium_yearly'::character varying])::text[])))
);


ALTER TABLE public.subscriptions OWNER TO postgres;

--
-- TOC entry 275 (class 1259 OID 161619)
-- Name: suspension_history; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.suspension_history (
    id uuid NOT NULL,
    user_id uuid NOT NULL,
    admin_id uuid,
    start_date timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    end_date timestamp without time zone,
    reason text NOT NULL,
    was_automated boolean DEFAULT false NOT NULL,
    suspension_data text,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
);


ALTER TABLE public.suspension_history OWNER TO postgres;

--
-- TOC entry 254 (class 1259 OID 152285)
-- Name: user_credits; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.user_credits (
    id uuid NOT NULL,
    user_id uuid NOT NULL,
    balance numeric(10,2) DEFAULT 0 NOT NULL,
    lifetime_added numeric(10,2) DEFAULT 0 NOT NULL,
    lifetime_spent numeric(10,2) DEFAULT 0 NOT NULL,
    created_at timestamp with time zone NOT NULL,
    updated_at timestamp with time zone NOT NULL,
    pending_credits numeric(10,2) DEFAULT 0 NOT NULL,
    CONSTRAINT check_pending_credits CHECK (((pending_credits >= (0)::numeric) AND (pending_credits <= (balance * (2)::numeric)))),
    CONSTRAINT check_positive_balance CHECK ((balance >= (0)::numeric)),
    CONSTRAINT chk_balance_non_negative CHECK ((balance >= (0)::numeric)),
    CONSTRAINT chk_lifetime_consistency CHECK (((lifetime_added >= (0)::numeric) AND (lifetime_spent >= (0)::numeric)))
);


ALTER TABLE public.user_credits OWNER TO postgres;

--
-- TOC entry 272 (class 1259 OID 154176)
-- Name: user_notification_preferences; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.user_notification_preferences (
    id uuid NOT NULL,
    user_id uuid NOT NULL,
    notification_type character varying(50) NOT NULL,
    category character varying(50) NOT NULL,
    enabled boolean DEFAULT true NOT NULL,
    created_at timestamp with time zone NOT NULL,
    updated_at timestamp with time zone NOT NULL
);


ALTER TABLE public.user_notification_preferences OWNER TO postgres;

--
-- TOC entry 5060 (class 0 OID 0)
-- Dependencies: 272
-- Name: COLUMN user_notification_preferences.notification_type; Type: COMMENT; Schema: public; Owner: postgres
--

COMMENT ON COLUMN public.user_notification_preferences.notification_type IS 'Type of notification (email, in-app)';


--
-- TOC entry 5061 (class 0 OID 0)
-- Dependencies: 272
-- Name: COLUMN user_notification_preferences.category; Type: COMMENT; Schema: public; Owner: postgres
--

COMMENT ON COLUMN public.user_notification_preferences.category IS 'Category of notification (expiration, performance, milestone, etc.)';


--
-- TOC entry 240 (class 1259 OID 151435)
-- Name: users; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.users (
    id uuid DEFAULT public.uuid_generate_v4() NOT NULL,
    name character varying(100) NOT NULL,
    email character varying(100) NOT NULL,
    password_hash character varying(255),
    phone character varying(20),
    type public.user_type DEFAULT 'regular'::public.user_type NOT NULL,
    avatar character varying(255),
    status public.user_status DEFAULT 'active'::public.user_status NOT NULL,
    suspended_until timestamp without time zone,
    suspension_reason text,
    login_attempts integer DEFAULT 0 NOT NULL,
    last_login_attempt timestamp without time zone,
    reset_token character varying(255),
    reset_token_expiry timestamp without time zone,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    language character varying(5) DEFAULT 'en'::character varying NOT NULL,
    google_id character varying(255),
    email_verified boolean DEFAULT false NOT NULL,
    CONSTRAINT check_login_attempts CHECK (((login_attempts >= 0) AND (login_attempts <= 5)))
);


ALTER TABLE public.users OWNER TO postgres;

--
-- TOC entry 245 (class 1259 OID 151529)
-- Name: view_logs; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.view_logs (
    id uuid DEFAULT public.uuid_generate_v4() NOT NULL,
    listing_id uuid NOT NULL,
    user_id uuid,
    session_id character varying(255) NOT NULL,
    ip_address character varying(45) NOT NULL,
    user_agent text,
    referrer text,
    created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL
);


ALTER TABLE public.view_logs OWNER TO postgres;

--
-- TOC entry 4692 (class 2606 OID 152261)
-- Name: SequelizeMeta SequelizeMeta_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public."SequelizeMeta"
    ADD CONSTRAINT "SequelizeMeta_pkey" PRIMARY KEY (name);


--
-- TOC entry 4797 (class 2606 OID 154141)
-- Name: ad_daily_stats ad_daily_stats_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.ad_daily_stats
    ADD CONSTRAINT ad_daily_stats_pkey PRIMARY KEY (id);


--
-- TOC entry 4733 (class 2606 OID 152575)
-- Name: additional_listings additional_listings_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.additional_listings
    ADD CONSTRAINT additional_listings_pkey PRIMARY KEY (id);


--
-- TOC entry 4785 (class 2606 OID 153528)
-- Name: advertisement_clicks advertisement_clicks_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.advertisement_clicks
    ADD CONSTRAINT advertisement_clicks_pkey PRIMARY KEY (id);


--
-- TOC entry 4790 (class 2606 OID 153800)
-- Name: advertisement_impressions advertisement_impressions_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.advertisement_impressions
    ADD CONSTRAINT advertisement_impressions_pkey PRIMARY KEY (id);


--
-- TOC entry 4780 (class 2606 OID 153506)
-- Name: advertisement_views advertisement_views_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.advertisement_views
    ADD CONSTRAINT advertisement_views_pkey PRIMARY KEY (id);


--
-- TOC entry 4772 (class 2606 OID 153472)
-- Name: advertisements advertisements_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.advertisements
    ADD CONSTRAINT advertisements_pkey PRIMARY KEY (id);


--
-- TOC entry 4823 (class 2606 OID 161507)
-- Name: boost_performances boost_performances_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.boost_performances
    ADD CONSTRAINT boost_performances_pkey PRIMARY KEY (id);


--
-- TOC entry 4654 (class 2606 OID 151623)
-- Name: boosts boosts_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.boosts
    ADD CONSTRAINT boosts_pkey PRIMARY KEY (id);


--
-- TOC entry 4688 (class 2606 OID 152198)
-- Name: cities cities_name_en_province_en_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.cities
    ADD CONSTRAINT cities_name_en_province_en_key UNIQUE (name_en, province_en);


--
-- TOC entry 4690 (class 2606 OID 152196)
-- Name: cities cities_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.cities
    ADD CONSTRAINT cities_pkey PRIMARY KEY (id);


--
-- TOC entry 4718 (class 2606 OID 152485)
-- Name: credit_requests credit_requests_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.credit_requests
    ADD CONSTRAINT credit_requests_pkey PRIMARY KEY (id);


--
-- TOC entry 4803 (class 2606 OID 154166)
-- Name: credit_reservations credit_reservations_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.credit_reservations
    ADD CONSTRAINT credit_reservations_pkey PRIMARY KEY (id);


--
-- TOC entry 4677 (class 2606 OID 152137)
-- Name: credit_transactions credit_transactions_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.credit_transactions
    ADD CONSTRAINT credit_transactions_pkey PRIMARY KEY (id);


--
-- TOC entry 4832 (class 2606 OID 161652)
-- Name: device_registrations device_registrations_device_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.device_registrations
    ADD CONSTRAINT device_registrations_device_id_key UNIQUE (device_id);


--
-- TOC entry 4836 (class 2606 OID 161650)
-- Name: device_registrations device_registrations_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.device_registrations
    ADD CONSTRAINT device_registrations_pkey PRIMARY KEY (id);


--
-- TOC entry 4642 (class 2606 OID 151511)
-- Name: listing_images listing_images_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.listing_images
    ADD CONSTRAINT listing_images_pkey PRIMARY KEY (id);


--
-- TOC entry 4770 (class 2606 OID 153293)
-- Name: listing_leads listing_leads_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.listing_leads
    ADD CONSTRAINT listing_leads_pkey PRIMARY KEY (id);


--
-- TOC entry 4750 (class 2606 OID 152782)
-- Name: listing_priorities listing_priorities_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.listing_priorities
    ADD CONSTRAINT listing_priorities_pkey PRIMARY KEY (id);


--
-- TOC entry 4752 (class 2606 OID 152784)
-- Name: listing_priorities listing_priorities_user_id_subscription_id_listing_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.listing_priorities
    ADD CONSTRAINT listing_priorities_user_id_subscription_id_listing_id_key UNIQUE (user_id, subscription_id, listing_id);


--
-- TOC entry 4645 (class 2606 OID 151523)
-- Name: listing_videos listing_videos_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.listing_videos
    ADD CONSTRAINT listing_videos_pkey PRIMARY KEY (id);


--
-- TOC entry 4638 (class 2606 OID 151492)
-- Name: listings listings_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.listings
    ADD CONSTRAINT listings_pkey PRIMARY KEY (id);


--
-- TOC entry 4741 (class 2606 OID 152605)
-- Name: neighborhoods neighborhoods_city_id_name_ar_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.neighborhoods
    ADD CONSTRAINT neighborhoods_city_id_name_ar_key UNIQUE (city_id, name_ar);


--
-- TOC entry 4743 (class 2606 OID 152603)
-- Name: neighborhoods neighborhoods_city_id_name_en_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.neighborhoods
    ADD CONSTRAINT neighborhoods_city_id_name_en_key UNIQUE (city_id, name_en);


--
-- TOC entry 4745 (class 2606 OID 152601)
-- Name: neighborhoods neighborhoods_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.neighborhoods
    ADD CONSTRAINT neighborhoods_pkey PRIMARY KEY (id);


--
-- TOC entry 4664 (class 2606 OID 151664)
-- Name: notifications notifications_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

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


--
-- TOC entry 4623 (class 2606 OID 151465)
-- Name: offices offices_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.offices
    ADD CONSTRAINT offices_pkey PRIMARY KEY (id);


--
-- TOC entry 4709 (class 2606 OID 152345)
-- Name: payments payments_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.payments
    ADD CONSTRAINT payments_pkey PRIMARY KEY (id);


--
-- TOC entry 4673 (class 2606 OID 151698)
-- Name: ratings ratings_office_id_user_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.ratings
    ADD CONSTRAINT ratings_office_id_user_id_key UNIQUE (office_id, user_id);


--
-- TOC entry 4675 (class 2606 OID 151696)
-- Name: ratings ratings_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.ratings
    ADD CONSTRAINT ratings_pkey PRIMARY KEY (id);


--
-- TOC entry 4764 (class 2606 OID 152831)
-- Name: scheduled_jobs scheduled_jobs_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.scheduled_jobs
    ADD CONSTRAINT scheduled_jobs_pkey PRIMARY KEY (id);


--
-- TOC entry 4758 (class 2606 OID 152812)
-- Name: scheduled_notifications scheduled_notifications_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.scheduled_notifications
    ADD CONSTRAINT scheduled_notifications_pkey PRIMARY KEY (id);


--
-- TOC entry 4668 (class 2606 OID 151679)
-- Name: session_tokens session_tokens_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.session_tokens
    ADD CONSTRAINT session_tokens_pkey PRIMARY KEY (id);


--
-- TOC entry 4816 (class 2606 OID 154223)
-- Name: social_media_posts social_media_posts_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.social_media_posts
    ADD CONSTRAINT social_media_posts_pkey PRIMARY KEY (id);


--
-- TOC entry 4696 (class 2606 OID 152280)
-- Name: subscription_plans subscription_plans_code_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.subscription_plans
    ADD CONSTRAINT subscription_plans_code_key UNIQUE (code);


--
-- TOC entry 4698 (class 2606 OID 152278)
-- Name: subscription_plans subscription_plans_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.subscription_plans
    ADD CONSTRAINT subscription_plans_pkey PRIMARY KEY (id);


--
-- TOC entry 4728 (class 2606 OID 152513)
-- Name: subscriptions subscriptions_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.subscriptions
    ADD CONSTRAINT subscriptions_pkey PRIMARY KEY (id);


--
-- TOC entry 4829 (class 2606 OID 161629)
-- Name: suspension_history suspension_history_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.suspension_history
    ADD CONSTRAINT suspension_history_pkey PRIMARY KEY (id);


--
-- TOC entry 4800 (class 2606 OID 154148)
-- Name: ad_daily_stats unique_ad_stat_date; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.ad_daily_stats
    ADD CONSTRAINT unique_ad_stat_date UNIQUE (ad_id, stat_date);


--
-- TOC entry 4808 (class 2606 OID 154188)
-- Name: user_notification_preferences unique_user_notification_preference; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.user_notification_preferences
    ADD CONSTRAINT unique_user_notification_preference UNIQUE (user_id, notification_type, category);


--
-- TOC entry 4702 (class 2606 OID 152292)
-- Name: user_credits user_credits_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.user_credits
    ADD CONSTRAINT user_credits_pkey PRIMARY KEY (id);


--
-- TOC entry 4705 (class 2606 OID 152294)
-- Name: user_credits user_credits_user_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.user_credits
    ADD CONSTRAINT user_credits_user_id_key UNIQUE (user_id);


--
-- TOC entry 4812 (class 2606 OID 154181)
-- Name: user_notification_preferences user_notification_preferences_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.user_notification_preferences
    ADD CONSTRAINT user_notification_preferences_pkey PRIMARY KEY (id);


--
-- TOC entry 4612 (class 2606 OID 151450)
-- Name: users users_email_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.users
    ADD CONSTRAINT users_email_key UNIQUE (email);


--
-- TOC entry 4614 (class 2606 OID 161677)
-- Name: users users_google_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.users
    ADD CONSTRAINT users_google_id_key UNIQUE (google_id);


--
-- TOC entry 4617 (class 2606 OID 151448)
-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.users
    ADD CONSTRAINT users_pkey PRIMARY KEY (id);


--
-- TOC entry 4651 (class 2606 OID 151537)
-- Name: view_logs view_logs_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.view_logs
    ADD CONSTRAINT view_logs_pkey PRIMARY KEY (id);


--
-- TOC entry 4795 (class 1259 OID 154149)
-- Name: ad_daily_stats_ad_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ad_daily_stats_ad_id ON public.ad_daily_stats USING btree (ad_id);


--
-- TOC entry 4798 (class 1259 OID 154150)
-- Name: ad_daily_stats_stat_date; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ad_daily_stats_stat_date ON public.ad_daily_stats USING btree (stat_date);


--
-- TOC entry 4729 (class 1259 OID 153095)
-- Name: additional_listings_end_date; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX additional_listings_end_date ON public.additional_listings USING btree (end_date);


--
-- TOC entry 4730 (class 1259 OID 153094)
-- Name: additional_listings_is_active; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX additional_listings_is_active ON public.additional_listings USING btree (is_active);


--
-- TOC entry 4731 (class 1259 OID 153093)
-- Name: additional_listings_payment_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX additional_listings_payment_id ON public.additional_listings USING btree (payment_id);


--
-- TOC entry 4734 (class 1259 OID 153092)
-- Name: additional_listings_user_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX additional_listings_user_id ON public.additional_listings USING btree (user_id);


--
-- TOC entry 4819 (class 1259 OID 161513)
-- Name: boost_performances_boost_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX boost_performances_boost_id ON public.boost_performances USING btree (boost_id);


--
-- TOC entry 4820 (class 1259 OID 161515)
-- Name: boost_performances_boost_id_day; Type: INDEX; Schema: public; Owner: postgres
--

CREATE UNIQUE INDEX boost_performances_boost_id_day ON public.boost_performances USING btree (boost_id, day);


--
-- TOC entry 4821 (class 1259 OID 161514)
-- Name: boost_performances_day; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX boost_performances_day ON public.boost_performances USING btree (day);


--
-- TOC entry 4652 (class 1259 OID 161828)
-- Name: boosts_homepage_featured_active_idx; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX boosts_homepage_featured_active_idx ON public.boosts USING btree (is_homepage_featured, is_active);


--
-- TOC entry 4715 (class 1259 OID 152498)
-- Name: credit_requests_admin_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX credit_requests_admin_id ON public.credit_requests USING btree (admin_id);


--
-- TOC entry 4716 (class 1259 OID 152500)
-- Name: credit_requests_created_at; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX credit_requests_created_at ON public.credit_requests USING btree (created_at);


--
-- TOC entry 4719 (class 1259 OID 152499)
-- Name: credit_requests_reference_number; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX credit_requests_reference_number ON public.credit_requests USING btree (reference_number);


--
-- TOC entry 4720 (class 1259 OID 152497)
-- Name: credit_requests_status; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX credit_requests_status ON public.credit_requests USING btree (status);


--
-- TOC entry 4721 (class 1259 OID 152496)
-- Name: credit_requests_user_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX credit_requests_user_id ON public.credit_requests USING btree (user_id);


--
-- TOC entry 4801 (class 1259 OID 154175)
-- Name: credit_reservations_created_at; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX credit_reservations_created_at ON public.credit_reservations USING btree (created_at);


--
-- TOC entry 4804 (class 1259 OID 154173)
-- Name: credit_reservations_reference_type_reference_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX credit_reservations_reference_type_reference_id ON public.credit_reservations USING btree (reference_type, reference_id);


--
-- TOC entry 4805 (class 1259 OID 154174)
-- Name: credit_reservations_status; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX credit_reservations_status ON public.credit_reservations USING btree (status);


--
-- TOC entry 4806 (class 1259 OID 154172)
-- Name: credit_reservations_user_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX credit_reservations_user_id ON public.credit_reservations USING btree (user_id);


--
-- TOC entry 4678 (class 1259 OID 152464)
-- Name: credit_transactions_type; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX credit_transactions_type ON public.credit_transactions USING btree (type);


--
-- TOC entry 4679 (class 1259 OID 152463)
-- Name: credit_transactions_user_credit_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX credit_transactions_user_credit_id ON public.credit_transactions USING btree (user_credit_id);


--
-- TOC entry 4830 (class 1259 OID 161658)
-- Name: device_registrations_device_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE UNIQUE INDEX device_registrations_device_id ON public.device_registrations USING btree (device_id);


--
-- TOC entry 4833 (class 1259 OID 161663)
-- Name: device_registrations_device_id_unique; Type: INDEX; Schema: public; Owner: postgres
--

CREATE UNIQUE INDEX device_registrations_device_id_unique ON public.device_registrations USING btree (device_id);


--
-- TOC entry 4834 (class 1259 OID 161665)
-- Name: device_registrations_ip_address_idx; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX device_registrations_ip_address_idx ON public.device_registrations USING btree (ip_address);


--
-- TOC entry 4837 (class 1259 OID 161659)
-- Name: device_registrations_user_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX device_registrations_user_id ON public.device_registrations USING btree (user_id);


--
-- TOC entry 4838 (class 1259 OID 161664)
-- Name: device_registrations_user_id_idx; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX device_registrations_user_id_idx ON public.device_registrations USING btree (user_id);


--
-- TOC entry 4786 (class 1259 OID 153539)
-- Name: idx_ad_clicks_ad_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_ad_clicks_ad_id ON public.advertisement_clicks USING btree (advertisement_id);


--
-- TOC entry 4787 (class 1259 OID 153541)
-- Name: idx_ad_clicks_created; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_ad_clicks_created ON public.advertisement_clicks USING btree (created_at);


--
-- TOC entry 4788 (class 1259 OID 153540)
-- Name: idx_ad_clicks_session; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_ad_clicks_session ON public.advertisement_clicks USING btree (session_id);


--
-- TOC entry 4791 (class 1259 OID 153811)
-- Name: idx_ad_impressions_ad_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_ad_impressions_ad_id ON public.advertisement_impressions USING btree (advertisement_id);


--
-- TOC entry 4792 (class 1259 OID 153814)
-- Name: idx_ad_impressions_created; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_ad_impressions_created ON public.advertisement_impressions USING btree (created_at);


--
-- TOC entry 4793 (class 1259 OID 153813)
-- Name: idx_ad_impressions_session; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_ad_impressions_session ON public.advertisement_impressions USING btree (session_id);


--
-- TOC entry 4794 (class 1259 OID 153812)
-- Name: idx_ad_impressions_user_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_ad_impressions_user_id ON public.advertisement_impressions USING btree (user_id);


--
-- TOC entry 4781 (class 1259 OID 153517)
-- Name: idx_ad_views_ad_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_ad_views_ad_id ON public.advertisement_views USING btree (advertisement_id);


--
-- TOC entry 4782 (class 1259 OID 153519)
-- Name: idx_ad_views_created; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_ad_views_created ON public.advertisement_views USING btree (created_at);


--
-- TOC entry 4783 (class 1259 OID 153518)
-- Name: idx_ad_views_session; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_ad_views_session ON public.advertisement_views USING btree (session_id);


--
-- TOC entry 4735 (class 1259 OID 152589)
-- Name: idx_additional_listings_end_date; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_additional_listings_end_date ON public.additional_listings USING btree (end_date);


--
-- TOC entry 4736 (class 1259 OID 152588)
-- Name: idx_additional_listings_is_active; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_additional_listings_is_active ON public.additional_listings USING btree (is_active);


--
-- TOC entry 4737 (class 1259 OID 152587)
-- Name: idx_additional_listings_payment_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_additional_listings_payment_id ON public.additional_listings USING btree (payment_id);


--
-- TOC entry 4738 (class 1259 OID 152586)
-- Name: idx_additional_listings_user_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_additional_listings_user_id ON public.additional_listings USING btree (user_id);


--
-- TOC entry 4773 (class 1259 OID 153497)
-- Name: idx_advertisements_dates; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_advertisements_dates ON public.advertisements USING btree (start_date, end_date);


--
-- TOC entry 4774 (class 1259 OID 153494)
-- Name: idx_advertisements_office_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_advertisements_office_id ON public.advertisements USING btree (office_id);


--
-- TOC entry 4775 (class 1259 OID 153791)
-- Name: idx_advertisements_priority; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_advertisements_priority ON public.advertisements USING btree (priority);


--
-- TOC entry 4776 (class 1259 OID 153496)
-- Name: idx_advertisements_size; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_advertisements_size ON public.advertisements USING btree (size);


--
-- TOC entry 4777 (class 1259 OID 153851)
-- Name: idx_advertisements_status; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_advertisements_status ON public.advertisements USING btree (status);


--
-- TOC entry 4778 (class 1259 OID 153493)
-- Name: idx_advertisements_user_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_advertisements_user_id ON public.advertisements USING btree (user_id);


--
-- TOC entry 4655 (class 1259 OID 151744)
-- Name: idx_boosts_end_date; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_boosts_end_date ON public.boosts USING btree (end_date);


--
-- TOC entry 4656 (class 1259 OID 151743)
-- Name: idx_boosts_is_active; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_boosts_is_active ON public.boosts USING btree (is_active);


--
-- TOC entry 4657 (class 1259 OID 151742)
-- Name: idx_boosts_listing_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_boosts_listing_id ON public.boosts USING btree (listing_id);


--
-- TOC entry 4680 (class 1259 OID 152175)
-- Name: idx_credit_transactions_admin_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_credit_transactions_admin_id ON public.credit_transactions USING btree (admin_id);


--
-- TOC entry 4681 (class 1259 OID 152178)
-- Name: idx_credit_transactions_created_at; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_credit_transactions_created_at ON public.credit_transactions USING btree (created_at);


--
-- TOC entry 4682 (class 1259 OID 161894)
-- Name: idx_credit_transactions_reference; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_credit_transactions_reference ON public.credit_transactions USING btree (reference_type, user_id, created_at);


--
-- TOC entry 4683 (class 1259 OID 152176)
-- Name: idx_credit_transactions_type; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_credit_transactions_type ON public.credit_transactions USING btree (type);


--
-- TOC entry 4684 (class 1259 OID 161893)
-- Name: idx_credit_transactions_user_date; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_credit_transactions_user_date ON public.credit_transactions USING btree (user_id, created_at);


--
-- TOC entry 4685 (class 1259 OID 152174)
-- Name: idx_credit_transactions_user_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_credit_transactions_user_id ON public.credit_transactions USING btree (user_id);


--
-- TOC entry 4639 (class 1259 OID 151725)
-- Name: idx_listing_images_listing_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_listing_images_listing_id ON public.listing_images USING btree (listing_id);


--
-- TOC entry 4640 (class 1259 OID 151726)
-- Name: idx_listing_images_listing_main; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_listing_images_listing_main ON public.listing_images USING btree (listing_id, is_main);


--
-- TOC entry 4765 (class 1259 OID 153306)
-- Name: idx_listing_leads_created_at; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_listing_leads_created_at ON public.listing_leads USING btree (created_at);


--
-- TOC entry 4766 (class 1259 OID 153307)
-- Name: idx_listing_leads_ip_listing; Type: INDEX; Schema: public; Owner: postgres
--

CREATE UNIQUE INDEX idx_listing_leads_ip_listing ON public.listing_leads USING btree (ip_address, listing_id);


--
-- TOC entry 4767 (class 1259 OID 153304)
-- Name: idx_listing_leads_listing_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_listing_leads_listing_id ON public.listing_leads USING btree (listing_id);


--
-- TOC entry 4768 (class 1259 OID 153305)
-- Name: idx_listing_leads_user_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_listing_leads_user_id ON public.listing_leads USING btree (user_id);


--
-- TOC entry 4746 (class 1259 OID 152802)
-- Name: idx_listing_priorities_listing_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_listing_priorities_listing_id ON public.listing_priorities USING btree (listing_id);


--
-- TOC entry 4747 (class 1259 OID 152801)
-- Name: idx_listing_priorities_subscription_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_listing_priorities_subscription_id ON public.listing_priorities USING btree (subscription_id);


--
-- TOC entry 4748 (class 1259 OID 152800)
-- Name: idx_listing_priorities_user_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_listing_priorities_user_id ON public.listing_priorities USING btree (user_id);


--
-- TOC entry 4643 (class 1259 OID 151727)
-- Name: idx_listing_videos_listing_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_listing_videos_listing_id ON public.listing_videos USING btree (listing_id);


--
-- TOC entry 4624 (class 1259 OID 161494)
-- Name: idx_listings_boost_type; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_listings_boost_type ON public.listings USING btree (boost_type);


--
-- TOC entry 4625 (class 1259 OID 152205)
-- Name: idx_listings_city_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_listings_city_id ON public.listings USING btree (city_id);


--
-- TOC entry 4626 (class 1259 OID 151723)
-- Name: idx_listings_is_boosted; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_listings_is_boosted ON public.listings USING btree (is_boosted);


--
-- TOC entry 4627 (class 1259 OID 151717)
-- Name: idx_listings_office_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_listings_office_id ON public.listings USING btree (office_id);


--
-- TOC entry 4628 (class 1259 OID 151722)
-- Name: idx_listings_price; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_listings_price ON public.listings USING btree (price);


--
-- TOC entry 4629 (class 1259 OID 151719)
-- Name: idx_listings_property_type; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_listings_property_type ON public.listings USING btree (property_type);


--
-- TOC entry 4630 (class 1259 OID 161493)
-- Name: idx_listings_quality_score; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_listings_quality_score ON public.listings USING btree (quality_score);


--
-- TOC entry 4631 (class 1259 OID 151724)
-- Name: idx_listings_spatial; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_listings_spatial ON public.listings USING gist (public.st_makepoint((longitude)::double precision, (latitude)::double precision));


--
-- TOC entry 4632 (class 1259 OID 151718)
-- Name: idx_listings_status; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_listings_status ON public.listings USING btree (status);


--
-- TOC entry 4633 (class 1259 OID 151720)
-- Name: idx_listings_transaction_type; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_listings_transaction_type ON public.listings USING btree (transaction_type);


--
-- TOC entry 4634 (class 1259 OID 151716)
-- Name: idx_listings_user_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_listings_user_id ON public.listings USING btree (user_id);


--
-- TOC entry 4658 (class 1259 OID 152903)
-- Name: idx_notifications_content_params; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_notifications_content_params ON public.notifications USING gin (content_params);


--
-- TOC entry 4659 (class 1259 OID 151751)
-- Name: idx_notifications_entity; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_notifications_entity ON public.notifications USING btree (entity_type, entity_id);


--
-- TOC entry 4660 (class 1259 OID 151749)
-- Name: idx_notifications_read; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_notifications_read ON public.notifications USING btree (read);


--
-- TOC entry 4661 (class 1259 OID 151748)
-- Name: idx_notifications_user_id; Type: INDEX; Schema: public; Owner: postgres
--

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


--
-- TOC entry 4662 (class 1259 OID 151750)
-- Name: idx_notifications_user_read; Type: INDEX; Schema: public; Owner: postgres
--

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


--
-- TOC entry 4618 (class 1259 OID 151715)
-- Name: idx_offices_is_premium; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_offices_is_premium ON public.offices USING btree (is_premium);


--
-- TOC entry 4619 (class 1259 OID 151714)
-- Name: idx_offices_location; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_offices_location ON public.offices USING btree (location);


--
-- TOC entry 4620 (class 1259 OID 151713)
-- Name: idx_offices_status; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_offices_status ON public.offices USING btree (status);


--
-- TOC entry 4621 (class 1259 OID 151712)
-- Name: idx_offices_user_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_offices_user_id ON public.offices USING btree (user_id);


--
-- TOC entry 4669 (class 1259 OID 151754)
-- Name: idx_ratings_office_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_ratings_office_id ON public.ratings USING btree (office_id);


--
-- TOC entry 4670 (class 1259 OID 151756)
-- Name: idx_ratings_rating; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_ratings_rating ON public.ratings USING btree (rating);


--
-- TOC entry 4671 (class 1259 OID 151755)
-- Name: idx_ratings_user_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_ratings_user_id ON public.ratings USING btree (user_id);


--
-- TOC entry 4759 (class 1259 OID 152834)
-- Name: idx_scheduled_jobs_processed; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_scheduled_jobs_processed ON public.scheduled_jobs USING btree (processed);


--
-- TOC entry 4760 (class 1259 OID 152833)
-- Name: idx_scheduled_jobs_trigger_at; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_scheduled_jobs_trigger_at ON public.scheduled_jobs USING btree (trigger_at);


--
-- TOC entry 4761 (class 1259 OID 153554)
-- Name: idx_scheduled_jobs_trigger_processed; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_scheduled_jobs_trigger_processed ON public.scheduled_jobs USING btree (trigger_at, processed);


--
-- TOC entry 4762 (class 1259 OID 152832)
-- Name: idx_scheduled_jobs_type; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_scheduled_jobs_type ON public.scheduled_jobs USING btree (type);


--
-- TOC entry 4753 (class 1259 OID 152821)
-- Name: idx_scheduled_notifications_entity; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_scheduled_notifications_entity ON public.scheduled_notifications USING btree (entity_type, entity_id);


--
-- TOC entry 4754 (class 1259 OID 152820)
-- Name: idx_scheduled_notifications_processed; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_scheduled_notifications_processed ON public.scheduled_notifications USING btree (processed);


--
-- TOC entry 4755 (class 1259 OID 152819)
-- Name: idx_scheduled_notifications_trigger_at; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_scheduled_notifications_trigger_at ON public.scheduled_notifications USING btree (trigger_at);


--
-- TOC entry 4756 (class 1259 OID 152818)
-- Name: idx_scheduled_notifications_user_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_scheduled_notifications_user_id ON public.scheduled_notifications USING btree (user_id);


--
-- TOC entry 4665 (class 1259 OID 151753)
-- Name: idx_session_tokens_expires_at; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_session_tokens_expires_at ON public.session_tokens USING btree (expires_at);


--
-- TOC entry 4666 (class 1259 OID 151752)
-- Name: idx_session_tokens_user_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_session_tokens_user_id ON public.session_tokens USING btree (user_id);


--
-- TOC entry 4722 (class 1259 OID 152533)
-- Name: idx_subscriptions_end_date; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_subscriptions_end_date ON public.subscriptions USING btree (end_date);


--
-- TOC entry 4723 (class 1259 OID 152529)
-- Name: idx_subscriptions_office_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_subscriptions_office_id ON public.subscriptions USING btree (office_id);


--
-- TOC entry 4724 (class 1259 OID 152530)
-- Name: idx_subscriptions_payment_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_subscriptions_payment_id ON public.subscriptions USING btree (payment_id);


--
-- TOC entry 4725 (class 1259 OID 152532)
-- Name: idx_subscriptions_status; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_subscriptions_status ON public.subscriptions USING btree (status);


--
-- TOC entry 4726 (class 1259 OID 152531)
-- Name: idx_subscriptions_type; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_subscriptions_type ON public.subscriptions USING btree (type);


--
-- TOC entry 4824 (class 1259 OID 161641)
-- Name: idx_suspension_history_admin_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_suspension_history_admin_id ON public.suspension_history USING btree (admin_id);


--
-- TOC entry 4825 (class 1259 OID 161643)
-- Name: idx_suspension_history_end_date; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_suspension_history_end_date ON public.suspension_history USING btree (end_date);


--
-- TOC entry 4826 (class 1259 OID 161642)
-- Name: idx_suspension_history_start_date; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_suspension_history_start_date ON public.suspension_history USING btree (start_date);


--
-- TOC entry 4827 (class 1259 OID 161640)
-- Name: idx_suspension_history_user_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_suspension_history_user_id ON public.suspension_history USING btree (user_id);


--
-- TOC entry 4686 (class 1259 OID 161888)
-- Name: idx_unique_promotional_credit_per_user; Type: INDEX; Schema: public; Owner: postgres
--

CREATE UNIQUE INDEX idx_unique_promotional_credit_per_user ON public.credit_transactions USING btree (user_id, reference_type) WHERE ((reference_type = 'promotional_welcome'::public.credit_reference_type_enum) AND (type = 'add'::public.credit_transaction_type));


--
-- TOC entry 4607 (class 1259 OID 151709)
-- Name: idx_users_email; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_users_email ON public.users USING btree (email);


--
-- TOC entry 4608 (class 1259 OID 152184)
-- Name: idx_users_language; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_users_language ON public.users USING btree (language);


--
-- TOC entry 4609 (class 1259 OID 151711)
-- Name: idx_users_status; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_users_status ON public.users USING btree (status);


--
-- TOC entry 4610 (class 1259 OID 151710)
-- Name: idx_users_type; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_users_type ON public.users USING btree (type);


--
-- TOC entry 4646 (class 1259 OID 151731)
-- Name: idx_view_logs_created_at; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_view_logs_created_at ON public.view_logs USING btree (created_at);


--
-- TOC entry 4647 (class 1259 OID 151728)
-- Name: idx_view_logs_listing_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_view_logs_listing_id ON public.view_logs USING btree (listing_id);


--
-- TOC entry 4648 (class 1259 OID 151730)
-- Name: idx_view_logs_session_listing; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_view_logs_session_listing ON public.view_logs USING btree (listing_id, session_id);


--
-- TOC entry 4649 (class 1259 OID 151729)
-- Name: idx_view_logs_user_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX idx_view_logs_user_id ON public.view_logs USING btree (user_id);


--
-- TOC entry 4635 (class 1259 OID 161827)
-- Name: listings_homepage_featured_until_idx; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX listings_homepage_featured_until_idx ON public.listings USING btree (homepage_featured_until);


--
-- TOC entry 4636 (class 1259 OID 152617)
-- Name: listings_neighborhood_id_idx; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX listings_neighborhood_id_idx ON public.listings USING btree (neighborhood_id);


--
-- TOC entry 4739 (class 1259 OID 152611)
-- Name: neighborhoods_city_id_idx; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX neighborhoods_city_id_idx ON public.neighborhoods USING btree (city_id);


--
-- TOC entry 4706 (class 1259 OID 152456)
-- Name: payments_created_at; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX payments_created_at ON public.payments USING btree (created_at);


--
-- TOC entry 4707 (class 1259 OID 152452)
-- Name: payments_entity_type_entity_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX payments_entity_type_entity_id ON public.payments USING btree (entity_type, entity_id);


--
-- TOC entry 4710 (class 1259 OID 152454)
-- Name: payments_receipt_number; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX payments_receipt_number ON public.payments USING btree (receipt_number);


--
-- TOC entry 4711 (class 1259 OID 152455)
-- Name: payments_reference_code; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX payments_reference_code ON public.payments USING btree (reference_code);


--
-- TOC entry 4712 (class 1259 OID 152453)
-- Name: payments_status; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX payments_status ON public.payments USING btree (status);


--
-- TOC entry 4713 (class 1259 OID 152451)
-- Name: payments_type; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX payments_type ON public.payments USING btree (type);


--
-- TOC entry 4714 (class 1259 OID 152450)
-- Name: payments_user_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX payments_user_id ON public.payments USING btree (user_id);


--
-- TOC entry 4814 (class 1259 OID 154229)
-- Name: social_media_posts_listing_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX social_media_posts_listing_id ON public.social_media_posts USING btree (listing_id);


--
-- TOC entry 4817 (class 1259 OID 154230)
-- Name: social_media_posts_platform_status; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX social_media_posts_platform_status ON public.social_media_posts USING btree (platform, status);


--
-- TOC entry 4818 (class 1259 OID 154231)
-- Name: social_media_posts_published_at; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX social_media_posts_published_at ON public.social_media_posts USING btree (published_at);


--
-- TOC entry 4693 (class 1259 OID 152284)
-- Name: subscription_plans_active; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX subscription_plans_active ON public.subscription_plans USING btree (active);


--
-- TOC entry 4694 (class 1259 OID 152281)
-- Name: subscription_plans_code; Type: INDEX; Schema: public; Owner: postgres
--

CREATE UNIQUE INDEX subscription_plans_code ON public.subscription_plans USING btree (code);


--
-- TOC entry 4699 (class 1259 OID 152282)
-- Name: subscription_plans_type; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX subscription_plans_type ON public.subscription_plans USING btree (type);


--
-- TOC entry 4700 (class 1259 OID 152283)
-- Name: subscription_plans_user_type; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX subscription_plans_user_type ON public.subscription_plans USING btree (user_type);


--
-- TOC entry 4703 (class 1259 OID 152449)
-- Name: user_credits_user_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE UNIQUE INDEX user_credits_user_id ON public.user_credits USING btree (user_id);


--
-- TOC entry 4809 (class 1259 OID 154191)
-- Name: user_notification_preferences_category; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX user_notification_preferences_category ON public.user_notification_preferences USING btree (category);


--
-- TOC entry 4810 (class 1259 OID 154190)
-- Name: user_notification_preferences_notification_type; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX user_notification_preferences_notification_type ON public.user_notification_preferences USING btree (notification_type);


--
-- TOC entry 4813 (class 1259 OID 154189)
-- Name: user_notification_preferences_user_id; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX user_notification_preferences_user_id ON public.user_notification_preferences USING btree (user_id);


--
-- TOC entry 4615 (class 1259 OID 161679)
-- Name: users_google_id_unique; Type: INDEX; Schema: public; Owner: postgres
--

CREATE UNIQUE INDEX users_google_id_unique ON public.users USING btree (google_id) WHERE (google_id IS NOT NULL);


--
-- TOC entry 4885 (class 2606 OID 154142)
-- Name: ad_daily_stats ad_daily_stats_ad_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.ad_daily_stats
    ADD CONSTRAINT ad_daily_stats_ad_id_fkey FOREIGN KEY (ad_id) REFERENCES public.advertisements(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 4866 (class 2606 OID 152581)
-- Name: additional_listings additional_listings_payment_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.additional_listings
    ADD CONSTRAINT additional_listings_payment_id_fkey FOREIGN KEY (payment_id) REFERENCES public.payments(id) ON UPDATE CASCADE ON DELETE SET NULL;


--
-- TOC entry 4867 (class 2606 OID 152576)
-- Name: additional_listings additional_listings_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.additional_listings
    ADD CONSTRAINT additional_listings_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 4881 (class 2606 OID 153529)
-- Name: advertisement_clicks advertisement_clicks_advertisement_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.advertisement_clicks
    ADD CONSTRAINT advertisement_clicks_advertisement_id_fkey FOREIGN KEY (advertisement_id) REFERENCES public.advertisements(id);


--
-- TOC entry 4882 (class 2606 OID 153534)
-- Name: advertisement_clicks advertisement_clicks_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.advertisement_clicks
    ADD CONSTRAINT advertisement_clicks_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id);


--
-- TOC entry 4883 (class 2606 OID 153801)
-- Name: advertisement_impressions advertisement_impressions_advertisement_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.advertisement_impressions
    ADD CONSTRAINT advertisement_impressions_advertisement_id_fkey FOREIGN KEY (advertisement_id) REFERENCES public.advertisements(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 4884 (class 2606 OID 153806)
-- Name: advertisement_impressions advertisement_impressions_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.advertisement_impressions
    ADD CONSTRAINT advertisement_impressions_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON UPDATE CASCADE ON DELETE SET NULL;


--
-- TOC entry 4879 (class 2606 OID 153507)
-- Name: advertisement_views advertisement_views_advertisement_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.advertisement_views
    ADD CONSTRAINT advertisement_views_advertisement_id_fkey FOREIGN KEY (advertisement_id) REFERENCES public.advertisements(id);


--
-- TOC entry 4880 (class 2606 OID 153512)
-- Name: advertisement_views advertisement_views_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.advertisement_views
    ADD CONSTRAINT advertisement_views_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id);


--
-- TOC entry 4875 (class 2606 OID 153478)
-- Name: advertisements advertisements_office_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.advertisements
    ADD CONSTRAINT advertisements_office_id_fkey FOREIGN KEY (office_id) REFERENCES public.offices(id);


--
-- TOC entry 4876 (class 2606 OID 153483)
-- Name: advertisements advertisements_payment_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.advertisements
    ADD CONSTRAINT advertisements_payment_id_fkey FOREIGN KEY (payment_id) REFERENCES public.payments(id);


--
-- TOC entry 4877 (class 2606 OID 153488)
-- Name: advertisements advertisements_previous_ad_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.advertisements
    ADD CONSTRAINT advertisements_previous_ad_id_fkey FOREIGN KEY (previous_ad_id) REFERENCES public.advertisements(id);


--
-- TOC entry 4878 (class 2606 OID 153473)
-- Name: advertisements advertisements_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.advertisements
    ADD CONSTRAINT advertisements_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id);


--
-- TOC entry 4889 (class 2606 OID 161508)
-- Name: boost_performances boost_performances_boost_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.boost_performances
    ADD CONSTRAINT boost_performances_boost_id_fkey FOREIGN KEY (boost_id) REFERENCES public.boosts(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 4849 (class 2606 OID 151624)
-- Name: boosts boosts_listing_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.boosts
    ADD CONSTRAINT boosts_listing_id_fkey FOREIGN KEY (listing_id) REFERENCES public.listings(id) ON DELETE CASCADE;


--
-- TOC entry 4861 (class 2606 OID 152491)
-- Name: credit_requests credit_requests_admin_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.credit_requests
    ADD CONSTRAINT credit_requests_admin_id_fkey FOREIGN KEY (admin_id) REFERENCES public.users(id) ON UPDATE CASCADE ON DELETE SET NULL;


--
-- TOC entry 4862 (class 2606 OID 152486)
-- Name: credit_requests credit_requests_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.credit_requests
    ADD CONSTRAINT credit_requests_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 4886 (class 2606 OID 154167)
-- Name: credit_reservations credit_reservations_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.credit_reservations
    ADD CONSTRAINT credit_reservations_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 4854 (class 2606 OID 152143)
-- Name: credit_transactions credit_transactions_admin_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.credit_transactions
    ADD CONSTRAINT credit_transactions_admin_id_fkey FOREIGN KEY (admin_id) REFERENCES public.users(id) ON UPDATE CASCADE ON DELETE SET NULL;


--
-- TOC entry 4855 (class 2606 OID 152465)
-- Name: credit_transactions credit_transactions_payment_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.credit_transactions
    ADD CONSTRAINT credit_transactions_payment_id_fkey FOREIGN KEY (payment_id) REFERENCES public.payments(id) ON UPDATE CASCADE ON DELETE SET NULL;


--
-- TOC entry 4856 (class 2606 OID 152458)
-- Name: credit_transactions credit_transactions_user_credit_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.credit_transactions
    ADD CONSTRAINT credit_transactions_user_credit_id_fkey FOREIGN KEY (user_credit_id) REFERENCES public.user_credits(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 4857 (class 2606 OID 152138)
-- Name: credit_transactions credit_transactions_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.credit_transactions
    ADD CONSTRAINT credit_transactions_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 4892 (class 2606 OID 161653)
-- Name: device_registrations device_registrations_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.device_registrations
    ADD CONSTRAINT device_registrations_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 4845 (class 2606 OID 151512)
-- Name: listing_images listing_images_listing_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.listing_images
    ADD CONSTRAINT listing_images_listing_id_fkey FOREIGN KEY (listing_id) REFERENCES public.listings(id) ON DELETE CASCADE;


--
-- TOC entry 4873 (class 2606 OID 153294)
-- Name: listing_leads listing_leads_listing_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.listing_leads
    ADD CONSTRAINT listing_leads_listing_id_fkey FOREIGN KEY (listing_id) REFERENCES public.listings(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 4874 (class 2606 OID 153299)
-- Name: listing_leads listing_leads_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.listing_leads
    ADD CONSTRAINT listing_leads_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON UPDATE CASCADE ON DELETE SET NULL;


--
-- TOC entry 4869 (class 2606 OID 152795)
-- Name: listing_priorities listing_priorities_listing_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.listing_priorities
    ADD CONSTRAINT listing_priorities_listing_id_fkey FOREIGN KEY (listing_id) REFERENCES public.listings(id) ON DELETE CASCADE;


--
-- TOC entry 4870 (class 2606 OID 152790)
-- Name: listing_priorities listing_priorities_subscription_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.listing_priorities
    ADD CONSTRAINT listing_priorities_subscription_id_fkey FOREIGN KEY (subscription_id) REFERENCES public.subscriptions(id) ON DELETE CASCADE;


--
-- TOC entry 4871 (class 2606 OID 152785)
-- Name: listing_priorities listing_priorities_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.listing_priorities
    ADD CONSTRAINT listing_priorities_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;


--
-- TOC entry 4846 (class 2606 OID 151524)
-- Name: listing_videos listing_videos_listing_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.listing_videos
    ADD CONSTRAINT listing_videos_listing_id_fkey FOREIGN KEY (listing_id) REFERENCES public.listings(id) ON DELETE CASCADE;


--
-- TOC entry 4840 (class 2606 OID 152200)
-- Name: listings listings_city_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.listings
    ADD CONSTRAINT listings_city_id_fkey FOREIGN KEY (city_id) REFERENCES public.cities(id) ON UPDATE CASCADE ON DELETE SET NULL;


--
-- TOC entry 4841 (class 2606 OID 161758)
-- Name: listings listings_city_id_fkey1; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.listings
    ADD CONSTRAINT listings_city_id_fkey1 FOREIGN KEY (city_id) REFERENCES public.cities(id) ON UPDATE CASCADE ON DELETE RESTRICT;


--
-- TOC entry 4842 (class 2606 OID 152612)
-- Name: listings listings_neighborhood_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.listings
    ADD CONSTRAINT listings_neighborhood_id_fkey FOREIGN KEY (neighborhood_id) REFERENCES public.neighborhoods(id) ON UPDATE CASCADE ON DELETE SET NULL;


--
-- TOC entry 4843 (class 2606 OID 151498)
-- Name: listings listings_office_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.listings
    ADD CONSTRAINT listings_office_id_fkey FOREIGN KEY (office_id) REFERENCES public.offices(id) ON DELETE SET NULL;


--
-- TOC entry 4844 (class 2606 OID 151493)
-- Name: listings listings_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.listings
    ADD CONSTRAINT listings_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;


--
-- TOC entry 4868 (class 2606 OID 152606)
-- Name: neighborhoods neighborhoods_city_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.neighborhoods
    ADD CONSTRAINT neighborhoods_city_id_fkey FOREIGN KEY (city_id) REFERENCES public.cities(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 4850 (class 2606 OID 151665)
-- Name: notifications notifications_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.notifications
    ADD CONSTRAINT notifications_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;


--
-- TOC entry 4839 (class 2606 OID 151466)
-- Name: offices offices_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.offices
    ADD CONSTRAINT offices_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;


--
-- TOC entry 4859 (class 2606 OID 152351)
-- Name: payments payments_admin_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.payments
    ADD CONSTRAINT payments_admin_id_fkey FOREIGN KEY (admin_id) REFERENCES public.users(id) ON UPDATE CASCADE ON DELETE SET NULL;


--
-- TOC entry 4860 (class 2606 OID 152346)
-- Name: payments payments_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.payments
    ADD CONSTRAINT payments_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 4852 (class 2606 OID 151699)
-- Name: ratings ratings_office_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.ratings
    ADD CONSTRAINT ratings_office_id_fkey FOREIGN KEY (office_id) REFERENCES public.offices(id) ON DELETE CASCADE;


--
-- TOC entry 4853 (class 2606 OID 151704)
-- Name: ratings ratings_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.ratings
    ADD CONSTRAINT ratings_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;


--
-- TOC entry 4872 (class 2606 OID 152813)
-- Name: scheduled_notifications scheduled_notifications_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.scheduled_notifications
    ADD CONSTRAINT scheduled_notifications_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;


--
-- TOC entry 4851 (class 2606 OID 151680)
-- Name: session_tokens session_tokens_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.session_tokens
    ADD CONSTRAINT session_tokens_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;


--
-- TOC entry 4888 (class 2606 OID 154224)
-- Name: social_media_posts social_media_posts_listing_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.social_media_posts
    ADD CONSTRAINT social_media_posts_listing_id_fkey FOREIGN KEY (listing_id) REFERENCES public.listings(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 4863 (class 2606 OID 152514)
-- Name: subscriptions subscriptions_office_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.subscriptions
    ADD CONSTRAINT subscriptions_office_id_fkey FOREIGN KEY (office_id) REFERENCES public.offices(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 4864 (class 2606 OID 152519)
-- Name: subscriptions subscriptions_payment_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.subscriptions
    ADD CONSTRAINT subscriptions_payment_id_fkey FOREIGN KEY (payment_id) REFERENCES public.payments(id) ON UPDATE CASCADE ON DELETE SET NULL;


--
-- TOC entry 4865 (class 2606 OID 152524)
-- Name: subscriptions subscriptions_previous_subscription_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.subscriptions
    ADD CONSTRAINT subscriptions_previous_subscription_id_fkey FOREIGN KEY (previous_subscription_id) REFERENCES public.subscriptions(id);


--
-- TOC entry 4890 (class 2606 OID 161635)
-- Name: suspension_history suspension_history_admin_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.suspension_history
    ADD CONSTRAINT suspension_history_admin_id_fkey FOREIGN KEY (admin_id) REFERENCES public.users(id);


--
-- TOC entry 4891 (class 2606 OID 161630)
-- Name: suspension_history suspension_history_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.suspension_history
    ADD CONSTRAINT suspension_history_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id);


--
-- TOC entry 4858 (class 2606 OID 152295)
-- Name: user_credits user_credits_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.user_credits
    ADD CONSTRAINT user_credits_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 4887 (class 2606 OID 154182)
-- Name: user_notification_preferences user_notification_preferences_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.user_notification_preferences
    ADD CONSTRAINT user_notification_preferences_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- TOC entry 4847 (class 2606 OID 151538)
-- Name: view_logs view_logs_listing_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.view_logs
    ADD CONSTRAINT view_logs_listing_id_fkey FOREIGN KEY (listing_id) REFERENCES public.listings(id) ON DELETE CASCADE;


--
-- TOC entry 4848 (class 2606 OID 151543)
-- Name: view_logs view_logs_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.view_logs
    ADD CONSTRAINT view_logs_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE SET NULL;


-- Completed on 2025-05-26 20:05:16

--
--

