- Created tables for `chats_etichette`, `messages`, `servizio`, `servizio_interessi`, `servizio_annunci`, `prezziario`, `ordini`, `payments`, and `banlist`. - Established primary and foreign key constraints for data integrity. - Introduced enums for various types including `TipologiaPosizioneEnum`, `OrderTypeEnum`, and `PaymentStatusEnum`. - Seeded initial data for banners, labels, flags, pricing, strings, and users. - Implemented unique constraints where necessary to prevent duplicate entries.
35 lines
No EOL
1.1 KiB
SQL
35 lines
No EOL
1.1 KiB
SQL
-- Chats Etichette
|
|
CREATE TABLE IF NOT EXISTS public.chats_etichette (
|
|
chatid UUID NOT NULL,
|
|
etichettaid integer NOT NULL
|
|
);
|
|
-- Primary Key
|
|
DO $$ BEGIN
|
|
ALTER TABLE public.chats_etichette
|
|
ADD CONSTRAINT chats_etichette_pkey PRIMARY KEY (chatid, etichettaid);
|
|
EXCEPTION
|
|
WHEN invalid_table_definition THEN
|
|
RAISE NOTICE 'Primary key already exists. Ignoring...';
|
|
END $$;
|
|
-- Foreign Key to Chats
|
|
DO $$ BEGIN IF NOT EXISTS (
|
|
SELECT 1 FROM pg_constraint
|
|
WHERE conname = 'chat_etichetta_fkey'
|
|
) THEN
|
|
ALTER TABLE public.chats_etichette
|
|
ADD CONSTRAINT chat_etichetta_fkey
|
|
FOREIGN KEY (chatid) REFERENCES public.chats (chatid)
|
|
ON UPDATE CASCADE ON DELETE CASCADE;
|
|
END IF;
|
|
END $$;
|
|
-- Foreign Key to Etichette
|
|
DO $$ BEGIN IF NOT EXISTS (
|
|
SELECT 1 FROM pg_constraint
|
|
WHERE conname = 'etichetta_chetich_fkey'
|
|
) THEN
|
|
ALTER TABLE public.chats_etichette
|
|
ADD CONSTRAINT etichetta_chetich_fkey
|
|
FOREIGN KEY (etichettaid) REFERENCES public.etichette (id_etichetta)
|
|
ON UPDATE CASCADE ON DELETE CASCADE;
|
|
END IF;
|
|
END $$; |