infoalloggi-monorepo/apps/db/migrations/012_serviziointeressi.up.sql
Marco Pedone 66ef4a7fbd feat(database): Add migrations for chat labels, messages, services, interests, announcements, pricing, orders, payments, and miscellaneous data
- 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.
2025-10-29 16:59:20 +01:00

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