- Created migration scripts for new tables including banlist, banners, event_queue, flags, testi_e_stringhe, and ratelimiter. - Added data seeding for banners, etichette, flags, prezziario, and testi_e_stringhe with idempotent inserts. - Initialized database with necessary extensions and user tables. - Updated servizio table to include new columns for managing service states. - Established foreign key relationships and unique constraints across various tables. - Implemented sequences for auto-incrementing primary keys in several tables.
56 lines
No EOL
1.9 KiB
SQL
56 lines
No EOL
1.9 KiB
SQL
-- Servizio Annunci
|
|
CREATE TABLE IF NOT EXISTS 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
|
|
);
|
|
-- Unique Constraint
|
|
DO $$ BEGIN IF NOT EXISTS (
|
|
SELECT 1
|
|
FROM pg_constraint
|
|
WHERE conname = 'uniq_annuncio_servizio'
|
|
) THEN
|
|
ALTER TABLE public.servizio_annunci
|
|
ADD CONSTRAINT uniq_annuncio_servizio UNIQUE (annunci_id, servizio_id);
|
|
END IF;
|
|
END $$;
|
|
-- Foreign Key to Annunci
|
|
DO $$ BEGIN IF NOT EXISTS (
|
|
SELECT 1 FROM pg_constraint
|
|
WHERE conname = 'servizio_annuncio_J_annuncio'
|
|
) THEN
|
|
ALTER TABLE public.servizio_annunci
|
|
ADD CONSTRAINT servizio_annuncio_J_annuncio
|
|
FOREIGN KEY (annunci_id) REFERENCES public.annunci (id)
|
|
ON UPDATE CASCADE ON DELETE CASCADE;
|
|
END IF;
|
|
END $$;
|
|
-- Foreign Key to Servizio
|
|
DO $$ BEGIN IF NOT EXISTS (
|
|
SELECT 1 FROM pg_constraint
|
|
WHERE conname = 'servizio_annuncio_J_servizio'
|
|
) THEN
|
|
ALTER TABLE public.servizio_annunci
|
|
ADD CONSTRAINT servizio_annuncio_J_servizio
|
|
FOREIGN KEY (servizio_id) REFERENCES public.servizio (servizio_id)
|
|
ON UPDATE CASCADE ON DELETE CASCADE;
|
|
END IF;
|
|
END $$; |