- 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.
31 lines
No EOL
1,004 B
SQL
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 $$; |