--
-- PostgreSQL database dump
--

-- Dumped from database version 16.0
-- Dumped by pg_dump version 16.0

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

--
-- Name: adminpack; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS adminpack WITH SCHEMA pg_catalog;


--
-- Name: EXTENSION adminpack; Type: COMMENT; Schema: -; Owner: 
--

COMMENT ON EXTENSION adminpack IS 'administrative functions for PostgreSQL';


--
-- Name: BanType; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public."BanType" AS ENUM (
    'ip',
    'email',
    'phone',
    'cf'
);


ALTER TYPE public."BanType" OWNER TO postgres;

--
-- Name: GenericStatusEnum; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public."GenericStatusEnum" AS ENUM (
    'pending',
    'success',
    'failed'
);


ALTER TYPE public."GenericStatusEnum" OWNER TO postgres;

--
-- Name: OrderTypeEnum; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public."OrderTypeEnum" AS ENUM (
    'Acconto',
    'Saldo',
    'Consulenza',
    'Altro'
);


ALTER TYPE public."OrderTypeEnum" OWNER TO postgres;

--
-- Name: PaymentStatusEnum; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public."PaymentStatusEnum" AS ENUM (
    'processing',
    'success',
    'failed'
);


ALTER TYPE public."PaymentStatusEnum" OWNER TO postgres;

--
-- Name: TipologiaPosizioneEnum; Type: TYPE; Schema: public; Owner: postgres
--

CREATE TYPE public."TipologiaPosizioneEnum" AS ENUM (
    'Transitorio',
    'Stabile'
);


ALTER TYPE public."TipologiaPosizioneEnum" OWNER TO postgres;

SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- Name: annunci; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.annunci (
    id integer NOT NULL,
    codice text NOT NULL,
    locatore text,
    numero text,
    idlocatore text,
    indirizzo text,
    civico text,
    comune text,
    cap text,
    provincia text,
    regione text,
    lat text,
    lon text,
    indirizzo_secondario text,
    civico_secondario text,
    lat_secondario text,
    lon_secondario text,
    tipo text,
    categorie text[],
    prezzo integer DEFAULT 0 NOT NULL,
    anno text,
    classe text,
    mq numeric,
    piano text,
    piano_palazzo integer,
    unita_condominio integer,
    numero_vani integer,
    numero_camere integer,
    numero_bagni integer,
    numero_balconi integer,
    numero_terrazzi integer,
    numero_box integer,
    numero_postiauto integer,
    accessori text[],
    titolo_it text,
    desc_it text,
    titolo_en text,
    desc_en text,
    stato text,
    web boolean,
    caratteristiche json,
    homepage boolean,
    url_video text[],
    email text,
    creato_il timestamp without time zone,
    modificato_il timestamp without time zone,
    consegna integer,
    disponibile_da date,
    permanenza integer[],
    persone text[],
    updated_at timestamp without time zone
);


ALTER TABLE public.annunci OWNER TO postgres;

--
-- Name: COLUMN annunci.caratteristiche; Type: COMMENT; Schema: public; Owner: postgres
--

COMMENT ON COLUMN public.annunci.caratteristiche IS '@type(Caratteristiche, ''src/utils/kanel-types.ts'', false, false, true)';


--
-- Name: annunci_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.annunci_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.annunci_id_seq OWNER TO postgres;

--
-- Name: annunci_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.annunci_id_seq OWNED BY public.annunci.id;


--
-- Name: banlist; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.banlist (
    id integer NOT NULL,
    value text NOT NULL,
    type public."BanType" NOT NULL
);


ALTER TABLE public.banlist OWNER TO postgres;

--
-- Name: banlist_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.banlist_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.banlist_id_seq OWNER TO postgres;

--
-- Name: banlist_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.banlist_id_seq OWNED BY public.banlist.id;


--
-- Name: banners; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.banners (
    idbanner text NOT NULL,
    titolo text,
    testo text,
    is_unskippable boolean NOT NULL,
    has_cta boolean NOT NULL,
    cta_href text,
    cta_icon text,
    cta_text text,
    color text,
    is_active boolean NOT NULL,
    show_public boolean NOT NULL,
    show_private boolean NOT NULL,
    hide_duration integer
);


ALTER TABLE public.banners OWNER TO postgres;

--
-- Name: chats; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.chats (
    chatid uuid DEFAULT gen_random_uuid() NOT NULL,
    created_at timestamp without time zone NOT NULL,
    user_ref uuid NOT NULL,
    tags text[]
);


ALTER TABLE public.chats OWNER TO postgres;

--
-- Name: chats_etichette; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.chats_etichette (
    chatid uuid NOT NULL,
    etichettaid integer NOT NULL
);


ALTER TABLE public.chats_etichette OWNER TO postgres;

--
-- Name: emails; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.emails (
    id_email integer NOT NULL,
    user_id uuid NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    data json NOT NULL
);


ALTER TABLE public.emails OWNER TO postgres;

--
-- Name: emails_id_email_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.emails_id_email_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.emails_id_email_seq OWNER TO postgres;

--
-- Name: emails_id_email_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.emails_id_email_seq OWNED BY public.emails.id_email;


--
-- Name: etichette; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.etichette (
    id_etichetta integer NOT NULL,
    title text NOT NULL,
    color_hex character varying(7) NOT NULL
);


ALTER TABLE public.etichette OWNER TO postgres;

--
-- Name: etichette_id_etichetta_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.etichette_id_etichetta_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.etichette_id_etichetta_seq OWNER TO postgres;

--
-- Name: etichette_id_etichetta_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.etichette_id_etichetta_seq OWNED BY public.etichette.id_etichetta;


--
-- Name: event_queue; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.event_queue (
    event_id integer NOT NULL,
    lock_expires timestamp with time zone NOT NULL,
    data jsonb,
    status text DEFAULT 'pending'::text NOT NULL
);


ALTER TABLE public.event_queue OWNER TO postgres;

--
-- Name: event_queue_event_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.event_queue_event_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE public.event_queue_event_id_seq OWNER TO postgres;

--
-- Name: event_queue_event_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.event_queue_event_id_seq OWNED BY public.event_queue.event_id;


--
-- Name: flags; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.flags (
    id text NOT NULL,
    value text NOT NULL
);


ALTER TABLE public.flags OWNER TO postgres;

--
-- Name: images_refs; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.images_refs (
    codice text NOT NULL,
    ordine integer NOT NULL,
    img text NOT NULL,
    thumb text NOT NULL,
    og_url text NOT NULL
);


ALTER TABLE public.images_refs OWNER TO postgres;

--
-- Name: messages; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.messages (
    messageid uuid DEFAULT gen_random_uuid() NOT NULL,
    chatid uuid NOT NULL,
    message text,
    "time" timestamp without time zone NOT NULL,
    isread boolean DEFAULT false NOT NULL,
    sender uuid NOT NULL
);


ALTER TABLE public.messages OWNER TO postgres;

--
-- Name: ordini; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.ordini (
    ordine_id uuid DEFAULT gen_random_uuid() NOT NULL,
    userid uuid NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    packid text NOT NULL,
    servizio_id uuid NOT NULL,
    type public."OrderTypeEnum" NOT NULL,
    "isActive" boolean DEFAULT false NOT NULL
);


ALTER TABLE public.ordini OWNER TO postgres;

--
-- Name: payments; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.payments (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    userid uuid NOT NULL,
    amount_cent integer NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    paymentmethod text,
    paymentname text NOT NULL,
    paid_at timestamp without time zone,
    intent_id text,
    paymentstatus public."PaymentStatusEnum",
    servizio_id uuid NOT NULL,
    ordine_id uuid NOT NULL
);


ALTER TABLE public.payments OWNER TO postgres;

--
-- Name: prezziario; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.prezziario (
    idprezziario text NOT NULL,
    prezzo_cent integer NOT NULL,
    testo_condizioni text,
    "isActive" boolean DEFAULT true NOT NULL,
    nome_it text NOT NULL,
    nome_en text NOT NULL,
    desc_it text NOT NULL,
    desc_en text NOT NULL,
    sconto integer DEFAULT 0 NOT NULL,
    "isAcconto" boolean DEFAULT false NOT NULL,
    "isSaldo" boolean DEFAULT false NOT NULL,
    "isConsulenza" boolean DEFAULT false NOT NULL,
    "isStabile" boolean DEFAULT false NOT NULL,
    "isTransitorio" boolean DEFAULT false NOT NULL
);


ALTER TABLE public.prezziario OWNER TO postgres;

--
-- Name: ratelimiter; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.ratelimiter (
    key text NOT NULL,
    request_timestamp timestamp without time zone NOT NULL,
    request_count integer NOT NULL
);


ALTER TABLE public.ratelimiter OWNER TO postgres;

--
-- Name: servizio; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.servizio (
    user_id uuid NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    tipologia public."TipologiaPosizioneEnum" NOT NULL,
    arredato boolean DEFAULT false NOT NULL,
    budget integer NOT NULL,
    n_adulti integer NOT NULL,
    n_minori integer NOT NULL,
    animali boolean DEFAULT false NOT NULL,
    fumatori boolean DEFAULT false NOT NULL,
    giardino boolean DEFAULT false NOT NULL,
    parcheggio boolean DEFAULT false NOT NULL,
    terrazzo boolean DEFAULT false NOT NULL,
    ascensore boolean DEFAULT false NOT NULL,
    pianoterra boolean DEFAULT false NOT NULL,
    motivazione_transitorio text,
    reddito text,
    "isSent" boolean DEFAULT false NOT NULL,
    servizio_id uuid DEFAULT gen_random_uuid() NOT NULL,
    decorrenza timestamp without time zone,
    "isInterrotto" boolean DEFAULT false NOT NULL,
    entromese integer,
    permanenza integer,
    "isOkAcconto" boolean DEFAULT false NOT NULL,
    "isOkSaldo" boolean DEFAULT false NOT NULL,
    "isOkConsulenza" boolean DEFAULT false NOT NULL,
    doc_personale_fronte_ref uuid,
    doc_personale_retro_ref uuid,
    doc_motivazione_ref uuid
);


ALTER TABLE public.servizio OWNER TO postgres;

--
-- Name: servizio_annunci; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.servizio_annunci (
    servizio_id uuid NOT NULL,
    annunci_id integer NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    open_contatti_at timestamp without time zone,
    doc_conferma_ref text,
    user_confirmed_at timestamp without time zone,
    accettato_conferma_at timestamp without time zone,
    caparra_causale text,
    caparra_iban text,
    caparra_importo text,
    caparra_intestazione text,
    "hasConfermaAdmin" boolean DEFAULT false NOT NULL,
    doc_contratto_ref text,
    gestionale_id integer,
    contratto_decorrenza date,
    contratto_scadenza date,
    contratto_tipo text,
    doc_registrazione_ref text,
    doc_conferma_added boolean DEFAULT false NOT NULL,
    doc_contratto_added boolean DEFAULT false NOT NULL,
    doc_registrazione_added boolean DEFAULT false NOT NULL
);


ALTER TABLE public.servizio_annunci OWNER TO postgres;

--
-- Name: servizio_interessi; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.servizio_interessi (
    "annuncioId" integer NOT NULL,
    "userId" uuid NOT NULL
);


ALTER TABLE public.servizio_interessi OWNER TO postgres;

--
-- Name: testi_e_stringhe; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.testi_e_stringhe (
    stinga_id text NOT NULL,
    stringa_value text
);


ALTER TABLE public.testi_e_stringhe OWNER TO postgres;

--
-- Name: users; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.users (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    username text NOT NULL,
    email text NOT NULL,
    "isAdmin" boolean DEFAULT false NOT NULL,
    "isBlocked" boolean DEFAULT false NOT NULL,
    password text NOT NULL,
    nome text NOT NULL,
    cognome text NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    reset_password_token text,
    reset_password_expires timestamp without time zone,
    telefono text NOT NULL,
    "isAdminMade" boolean DEFAULT false,
    "isVerified" boolean DEFAULT false NOT NULL,
    "verificationToken" text,
    "verificationTokenExpires" timestamp without time zone,
    salt text NOT NULL
);


ALTER TABLE public.users OWNER TO postgres;

--
-- Name: users_anagrafica; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.users_anagrafica (
    idanagrafica uuid DEFAULT gen_random_uuid() NOT NULL,
    userid uuid NOT NULL,
    luogo_nascita text,
    data_nascita timestamp without time zone,
    nazione_nascita text,
    codice_fiscale text,
    via_residenza text,
    civico_residenza text,
    comune_residenza text,
    provincia_residenza text,
    cap_residenza text,
    nazione_residenza text,
    sesso text,
    azienda boolean DEFAULT false NOT NULL,
    ragione_sociale text,
    sede_legale text,
    p_iva text,
    fatturazione_aziendale boolean DEFAULT false NOT NULL,
    codice_destinatario text,
    legale_rappresentante text
);


ALTER TABLE public.users_anagrafica OWNER TO postgres;

--
-- Name: users_storage; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.users_storage (
    "userId" uuid NOT NULL,
    "storageId" text NOT NULL,
    from_admin boolean DEFAULT false NOT NULL,
    user_storage_id uuid DEFAULT gen_random_uuid() NOT NULL
);


ALTER TABLE public.users_storage OWNER TO postgres;

--
-- Name: annunci id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.annunci ALTER COLUMN id SET DEFAULT nextval('public.annunci_id_seq'::regclass);


--
-- Name: banlist id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.banlist ALTER COLUMN id SET DEFAULT nextval('public.banlist_id_seq'::regclass);


--
-- Name: emails id_email; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.emails ALTER COLUMN id_email SET DEFAULT nextval('public.emails_id_email_seq'::regclass);


--
-- Name: etichette id_etichetta; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.etichette ALTER COLUMN id_etichetta SET DEFAULT nextval('public.etichette_id_etichetta_seq'::regclass);


--
-- Name: event_queue event_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.event_queue ALTER COLUMN event_id SET DEFAULT nextval('public.event_queue_event_id_seq'::regclass);


--
-- Name: annunci annunci_codice_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.annunci
    ADD CONSTRAINT annunci_codice_key UNIQUE (codice);


--
-- Name: annunci annunci_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.annunci
    ADD CONSTRAINT annunci_pkey PRIMARY KEY (id);


--
-- Name: banlist banlist_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.banlist
    ADD CONSTRAINT banlist_pkey PRIMARY KEY (id);


--
-- Name: banners banners_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.banners
    ADD CONSTRAINT banners_pkey PRIMARY KEY (idbanner);


--
-- Name: chats_etichette chats_etichette_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.chats_etichette
    ADD CONSTRAINT chats_etichette_pkey PRIMARY KEY (chatid, etichettaid);


--
-- Name: chats chats_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.chats
    ADD CONSTRAINT chats_pkey PRIMARY KEY (chatid);


--
-- Name: emails emails_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.emails
    ADD CONSTRAINT emails_pkey PRIMARY KEY (id_email);


--
-- Name: etichette etichette_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.etichette
    ADD CONSTRAINT etichette_pkey PRIMARY KEY (id_etichetta);


--
-- Name: event_queue event_queue_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.event_queue
    ADD CONSTRAINT event_queue_pkey PRIMARY KEY (event_id);


--
-- Name: images_refs img_cod_order; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.images_refs
    ADD CONSTRAINT img_cod_order UNIQUE (codice, ordine);


--
-- Name: messages messages_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.messages
    ADD CONSTRAINT messages_pkey PRIMARY KEY (messageid);


--
-- Name: ordini ordini2_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.ordini
    ADD CONSTRAINT ordini2_pkey PRIMARY KEY (ordine_id);


--
-- Name: payments payments2_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

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


--
-- Name: prezziario prezziario2_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.prezziario
    ADD CONSTRAINT prezziario2_pkey PRIMARY KEY (idprezziario);


--
-- Name: servizio servizio_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.servizio
    ADD CONSTRAINT servizio_pkey PRIMARY KEY (servizio_id);


--
-- Name: flags sitesettings_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.flags
    ADD CONSTRAINT sitesettings_pkey PRIMARY KEY (id);


--
-- Name: testi_e_stringhe testi_e_stringhe_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.testi_e_stringhe
    ADD CONSTRAINT testi_e_stringhe_pkey PRIMARY KEY (stinga_id);


--
-- Name: banlist typeval; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.banlist
    ADD CONSTRAINT typeval UNIQUE (type, value);


--
-- Name: servizio_annunci uniq_annuncio_servizio; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.servizio_annunci
    ADD CONSTRAINT uniq_annuncio_servizio UNIQUE (annunci_id, servizio_id);


--
-- Name: users_storage unique_user_storage; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.users_storage
    ADD CONSTRAINT unique_user_storage UNIQUE ("userId", "storageId");


--
-- Name: servizio_interessi uniqui_interest; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.servizio_interessi
    ADD CONSTRAINT uniqui_interest UNIQUE ("annuncioId", "userId");


--
-- Name: users users_email_key; Type: CONSTRAINT; Schema: public; Owner: postgres
--

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


--
-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

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


--
-- Name: users_storage users_storage_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.users_storage
    ADD CONSTRAINT users_storage_pkey PRIMARY KEY (user_storage_id);


--
-- Name: users_anagrafica usersanagrafica2_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.users_anagrafica
    ADD CONSTRAINT usersanagrafica2_pkey PRIMARY KEY (idanagrafica);


--
-- Name: users_anagrafica usserunique2; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.users_anagrafica
    ADD CONSTRAINT usserunique2 UNIQUE (userid);


--
-- Name: ratelimiter_key_index; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX ratelimiter_key_index ON public.ratelimiter USING btree (key);


--
-- Name: chats_etichette chat_etichetta_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.chats_etichette
    ADD CONSTRAINT chat_etichetta_fkey FOREIGN KEY (chatid) REFERENCES public.chats(chatid) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: images_refs cod_image; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.images_refs
    ADD CONSTRAINT cod_image FOREIGN KEY (codice) REFERENCES public.annunci(codice);


--
-- Name: emails email_user; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

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


--
-- Name: chats_etichette etichetta_chetich_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.chats_etichette
    ADD CONSTRAINT etichetta_chetich_fkey FOREIGN KEY (etichettaid) REFERENCES public.etichette(id_etichetta) ON UPDATE CASCADE ON DELETE CASCADE NOT VALID;


--
-- Name: servizio_interessi interesse_annuncio; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.servizio_interessi
    ADD CONSTRAINT interesse_annuncio FOREIGN KEY ("annuncioId") REFERENCES public.annunci(id) ON UPDATE CASCADE ON DELETE CASCADE NOT VALID;


--
-- Name: servizio_interessi interesse_user; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.servizio_interessi
    ADD CONSTRAINT interesse_user FOREIGN KEY ("userId") REFERENCES public.users(id) ON UPDATE CASCADE ON DELETE CASCADE NOT VALID;


--
-- Name: messages messages_chatid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.messages
    ADD CONSTRAINT messages_chatid_fkey FOREIGN KEY (chatid) REFERENCES public.chats(chatid) ON DELETE CASCADE;


--
-- Name: messages messages_user_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.messages
    ADD CONSTRAINT messages_user_fkey FOREIGN KEY (sender) REFERENCES public.users(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: ordini ordine2_pack_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.ordini
    ADD CONSTRAINT ordine2_pack_fkey FOREIGN KEY (packid) REFERENCES public.prezziario(idprezziario) ON UPDATE CASCADE ON DELETE CASCADE NOT VALID;


--
-- Name: ordini ordine2_servizio_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.ordini
    ADD CONSTRAINT ordine2_servizio_fkey FOREIGN KEY (servizio_id) REFERENCES public.servizio(servizio_id) ON UPDATE CASCADE ON DELETE CASCADE NOT VALID;


--
-- Name: ordini ordine2_userid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.ordini
    ADD CONSTRAINT ordine2_userid_fkey FOREIGN KEY (userid) REFERENCES public.users(id) ON UPDATE CASCADE ON DELETE CASCADE NOT VALID;


--
-- Name: payments payments2_ordine_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.payments
    ADD CONSTRAINT payments2_ordine_fkey FOREIGN KEY (ordine_id) REFERENCES public.ordini(ordine_id) ON UPDATE CASCADE ON DELETE CASCADE NOT VALID;


--
-- Name: payments payments2_servizio_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.payments
    ADD CONSTRAINT payments2_servizio_fkey FOREIGN KEY (servizio_id) REFERENCES public.servizio(servizio_id) ON UPDATE CASCADE ON DELETE CASCADE NOT VALID;


--
-- Name: payments payments2_userid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.payments
    ADD CONSTRAINT payments2_userid_fkey FOREIGN KEY (userid) REFERENCES public.users(id) ON DELETE CASCADE;


--
-- Name: servizio_annunci servizio_annuncio_J_annuncio; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.servizio_annunci
    ADD CONSTRAINT "servizio_annuncio_J_annuncio" FOREIGN KEY (annunci_id) REFERENCES public.annunci(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: servizio_annunci servizio_annuncio_J_servizio; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.servizio_annunci
    ADD CONSTRAINT "servizio_annuncio_J_servizio" FOREIGN KEY (servizio_id) REFERENCES public.servizio(servizio_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: servizio servizio_doc_fronte; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.servizio
    ADD CONSTRAINT servizio_doc_fronte FOREIGN KEY (doc_personale_fronte_ref) REFERENCES public.users_storage(user_storage_id) ON UPDATE CASCADE ON DELETE SET NULL NOT VALID;


--
-- Name: servizio servizio_doc_motivazione; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.servizio
    ADD CONSTRAINT servizio_doc_motivazione FOREIGN KEY (doc_motivazione_ref) REFERENCES public.users_storage(user_storage_id) ON UPDATE CASCADE ON DELETE SET NULL NOT VALID;


--
-- Name: servizio servizio_doc_retro; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.servizio
    ADD CONSTRAINT servizio_doc_retro FOREIGN KEY (doc_personale_retro_ref) REFERENCES public.users_storage(user_storage_id) ON UPDATE CASCADE ON DELETE SET NULL NOT VALID;


--
-- Name: servizio user_servizio; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

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


--
-- Name: chats userchats; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.chats
    ADD CONSTRAINT userchats FOREIGN KEY (user_ref) REFERENCES public.users(id) ON UPDATE CASCADE ON DELETE CASCADE NOT VALID;


--
-- Name: users_anagrafica useridfkeyanagrafica2; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.users_anagrafica
    ADD CONSTRAINT useridfkeyanagrafica2 FOREIGN KEY (userid) REFERENCES public.users(id) ON UPDATE CASCADE ON DELETE CASCADE NOT VALID;


--
-- Name: users_storage userstorage; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.users_storage
    ADD CONSTRAINT userstorage FOREIGN KEY ("userId") REFERENCES public.users(id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- PostgreSQL database dump complete
--

