infoalloggi-monorepo/apps/db/migrations/26_videos_refs.up.sql
Marco Pedone f4262b8711 feat: Refactor video handling in announcements
- Updated the announcement detail component to directly use images and videos from the data structure.
- Changed the form edit component to accommodate the new media structure, replacing AnnunciWithImages with AnnunciWithMedia.
- Modified the announcements list to initialize videos as an empty array.
- Enhanced the announcement view to handle external videos and updated the footer to display them correctly.
- Introduced a new utility function to generate YouTube embed URLs.
- Updated the database schema to replace url_video with external_videos and added a new videos_refs table for video management.
- Implemented video processing logic, including downloading, transcoding, and thumbnail generation.
- Added migration scripts for the new videos_refs table and updated existing references in the database.
2025-11-18 15:20:14 +01:00

59 lines
No EOL
1.6 KiB
SQL

-- Images_refs index
CREATE INDEX IF NOT EXISTS annunci_imgs ON images_refs (codice);
-- Videos_refs Table
CREATE TABLE IF NOT EXISTS public.videos_refs (
codice TEXT COLLATE pg_catalog."default" NOT NULL,
ordine integer NOT NULL,
video TEXT COLLATE pg_catalog."default" NOT NULL,
thumb TEXT COLLATE pg_catalog."default" NOT NULL,
og_url TEXT COLLATE pg_catalog."default" NOT NULL
);
-- Unique Codice and Ordine for Videos_refs Table
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'video_cod_order'
AND conrelid = 'public.videos_refs'::regclass
) THEN
ALTER TABLE public.videos_refs
ADD CONSTRAINT video_cod_order UNIQUE (codice, ordine);
END IF;
END $$;
-- Foreign Key to Annunci for Videos_refs Table
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1 FROM pg_constraint
WHERE conname = 'cod_video'
AND conrelid = 'public.videos_refs'::regclass
) THEN
ALTER TABLE public.videos_refs
ADD CONSTRAINT cod_video
FOREIGN KEY (codice) REFERENCES public.annunci (codice)
ON UPDATE CASCADE ON DELETE CASCADE;
END IF;
END $$;
-- Index for Videos_refs Table
CREATE INDEX IF NOT EXISTS annunci_videos ON videos_refs (codice);
-- Rename url_video to external_videos in Annunci Table
DO $$
BEGIN
IF EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_name='annunci'
AND column_name='url_video'
) THEN
ALTER TABLE public.annunci
RENAME COLUMN url_video TO external_videos;
END IF;
END $$;