- 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.
37 lines
No EOL
1.1 KiB
SQL
37 lines
No EOL
1.1 KiB
SQL
-- Servizio Interessi Table
|
|
CREATE TABLE IF NOT EXISTS public.servizio_interessi (
|
|
"annuncioId" integer NOT NULL,
|
|
"userId" UUID NOT NULL
|
|
);
|
|
-- Unique Constraint
|
|
DO $$ BEGIN IF NOT EXISTS (
|
|
SELECT 1
|
|
FROM pg_constraint
|
|
WHERE conname = 'unique_interest'
|
|
) THEN
|
|
ALTER TABLE public.servizio_interessi
|
|
ADD CONSTRAINT unique_interest UNIQUE ("annuncioId", "userId");
|
|
END IF;
|
|
END $$;
|
|
-- Foreign Key to Annunci
|
|
DO $$ BEGIN IF NOT EXISTS (
|
|
SELECT 1 FROM pg_constraint
|
|
WHERE conname = 'interesse_annuncio'
|
|
) THEN
|
|
ALTER TABLE public.servizio_interessi
|
|
ADD CONSTRAINT interesse_annuncio
|
|
FOREIGN KEY ("annuncioId") REFERENCES public.annunci (id)
|
|
ON UPDATE CASCADE ON DELETE CASCADE;
|
|
END IF;
|
|
END $$;
|
|
-- Foreign Key to Users
|
|
DO $$ BEGIN IF NOT EXISTS (
|
|
SELECT 1 FROM pg_constraint
|
|
WHERE conname = 'interesse_user'
|
|
) THEN
|
|
ALTER TABLE public.servizio_interessi
|
|
ADD CONSTRAINT interesse_user
|
|
FOREIGN KEY ("userId") REFERENCES public.users (id)
|
|
ON UPDATE CASCADE ON DELETE CASCADE;
|
|
END IF;
|
|
END $$; |