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');

--
-- Name: GenericStatusEnum; Type: TYPE; Schema: public; Owner: postgres
--
CREATE TYPE public."GenericStatusEnum" AS ENUM ('pending', 'success', 'failed');

--
-- Name: OrderTypeEnum; Type: TYPE; Schema: public; Owner: postgres
--
CREATE TYPE public."OrderTypeEnum" AS ENUM (
    'Acconto',
    'Saldo',
    'Consulenza',
    'Altro'
);

--
-- Name: PaymentStatusEnum; Type: TYPE; Schema: public; Owner: postgres
--
CREATE TYPE public."PaymentStatusEnum" AS ENUM ('processing', 'success', 'failed');

--
-- Name: TipologiaPosizioneEnum; Type: TYPE; Schema: public; Owner: postgres
--
CREATE TYPE public."TipologiaPosizioneEnum" AS ENUM ('Transitorio', 'Stabile');

--
-- 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
);

--
-- 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;

--
-- 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
);

--
-- 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;

--
-- 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 []
);

--
-- Name: chats_etichette; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.chats_etichette (
    chatid UUID NOT NULL,
    etichettaid integer NOT NULL
);

--
-- 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
);

--
-- 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;

--
-- 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
);

--
-- 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;

--
-- 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
);

--
-- 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;

--
-- 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 );

--
-- 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
);

--
-- 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
);

--
-- 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
);

--
-- 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
);

--
-- 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
);

--
-- 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
);

--
-- 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
);

--
-- 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
);

--
-- Name: servizio_interessi; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.servizio_interessi (
    "annuncioId" integer NOT NULL,
    "userId" UUID NOT NULL
);

--
-- Name: testi_e_stringhe; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.testi_e_stringhe (
    stinga_id TEXT NOT NULL,
    stringa_value TEXT
);

--
-- 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
);

--
-- 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
);

--
-- 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
);

--
-- 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;