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