infoalloggi-monorepo/apps/db/migrations/005_annunci.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

91 lines
No EOL
2.3 KiB
SQL

-- Annunci
CREATE TABLE IF NOT EXISTS public.annunci (
id integer NOT NULL,
codice TEXT NOT NULL,
locatore TEXT,
numero TEXT,
idlocatore TEXT,
indirizzo TEXT,
civico TEXT,
comune TEXT,
cap TEXT,
provincia TEXT,
regione TEXT,
lat TEXT,
lon TEXT,
indirizzo_secondario TEXT,
civico_secondario TEXT,
lat_secondario TEXT,
lon_secondario TEXT,
tipo TEXT,
categorie TEXT [],
prezzo integer DEFAULT 0 NOT NULL,
anno TEXT,
classe TEXT,
mq numeric,
piano TEXT,
piano_palazzo integer,
unita_condominio integer,
numero_vani integer,
numero_camere integer,
numero_bagni integer,
numero_balconi integer,
numero_terrazzi integer,
numero_box integer,
numero_postiauto integer,
accessori TEXT [],
titolo_it TEXT,
desc_it TEXT,
titolo_en TEXT,
desc_en TEXT,
stato TEXT,
web boolean,
caratteristiche json,
homepage boolean,
url_video TEXT [],
email TEXT,
creato_il TIMESTAMP WITHOUT TIME ZONE,
modificato_il TIMESTAMP WITHOUT TIME ZONE,
consegna integer,
disponibile_da date,
permanenza INTEGER[],
persone TEXT [],
updated_at TIMESTAMP WITHOUT TIME ZONE
);
COMMENT ON COLUMN public.annunci.caratteristiche IS '@type(Caratteristiche, ''src/utils/kanel-types.ts'', false, false, true)';
-- Sequence for id
DO $$ BEGIN
IF NOT EXISTS (
SELECT 1 FROM pg_sequences
WHERE schemaname = 'public' AND sequencename = 'annunci_id_seq'
) THEN
CREATE SEQUENCE public.annunci_id_seq
AS integer START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1;
END IF;
END $$;
ALTER SEQUENCE public.annunci_id_seq OWNED BY public.annunci.id;
-- Set default for id
ALTER TABLE public.annunci
ALTER COLUMN id
SET DEFAULT nextval(
'public.annunci_id_seq'::regclass
);
-- Primary Key
DO $$ BEGIN ALTER TABLE public.annunci
ADD CONSTRAINT annunci_pkey PRIMARY KEY (id);
EXCEPTION
WHEN invalid_table_definition THEN
RAISE NOTICE 'Primary key already exists. Ignoring...';
END $$;
-- Unique Codice
DO $$ BEGIN IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'annunci_codice_key'
) THEN
ALTER TABLE public.annunci
ADD CONSTRAINT annunci_codice_key UNIQUE (codice);
END IF;
END $$;