infoalloggi-monorepo/apps/db/migrations/008_etichette.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

31 lines
No EOL
1,004 B
SQL

-- Etichette
CREATE TABLE IF NOT EXISTS public.etichette (
id_etichetta integer NOT NULL,
title TEXT NOT NULL,
color_hex character varying(7) NOT NULL
);
-- Sequence for id_etichetta
DO $$ BEGIN IF NOT EXISTS (
SELECT 1 FROM pg_sequences
WHERE schemaname = 'public' AND sequencename = 'etichette_id_etichetta_seq'
) THEN
CREATE SEQUENCE public.etichette_id_etichetta_seq
AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;
END IF;
END $$;
ALTER SEQUENCE public.etichette_id_etichetta_seq OWNED BY public.etichette.id_etichetta;
-- Set default for id_etichetta
ALTER TABLE public.etichette
ALTER COLUMN id_etichetta
SET DEFAULT nextval(
'public.etichette_id_etichetta_seq'::regclass
);
-- Primary Key
DO $$ BEGIN
ALTER TABLE public.etichette
ADD CONSTRAINT etichette_pkey PRIMARY KEY (id_etichetta);
EXCEPTION
WHEN invalid_table_definition THEN
RAISE NOTICE 'Primary key already exists. Ignoring...';
END $$;