- 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.
29 lines
No EOL
786 B
SQL
29 lines
No EOL
786 B
SQL
-- Image Refs
|
|
CREATE TABLE IF NOT EXISTS public.images_refs (
|
|
codice TEXT NOT NULL,
|
|
ordine integer NOT NULL,
|
|
img TEXT NOT NULL,
|
|
thumb TEXT NOT NULL,
|
|
og_url TEXT NOT NULL
|
|
);
|
|
-- Unique Codice and Ordine
|
|
DO $$ BEGIN IF NOT EXISTS (
|
|
SELECT 1
|
|
FROM pg_constraint
|
|
WHERE conname = 'img_cod_order'
|
|
) THEN
|
|
ALTER TABLE public.images_refs
|
|
ADD CONSTRAINT img_cod_order UNIQUE (codice, ordine);
|
|
END IF;
|
|
END $$;
|
|
-- Foreign Key to Annunci
|
|
DO $$ BEGIN IF NOT EXISTS (
|
|
SELECT 1 FROM pg_constraint
|
|
WHERE conname = 'cod_image'
|
|
) THEN
|
|
ALTER TABLE public.images_refs
|
|
ADD CONSTRAINT cod_image
|
|
FOREIGN KEY (codice) REFERENCES public.annunci (codice)
|
|
ON UPDATE CASCADE ON DELETE CASCADE;
|
|
END IF;
|
|
END $$; |