- 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.
26 lines
No EOL
764 B
SQL
26 lines
No EOL
764 B
SQL
-- Chats
|
|
CREATE TABLE IF NOT EXISTS public.chats (
|
|
chatid UUID DEFAULT gen_random_uuid () NOT NULL,
|
|
created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL,
|
|
user_ref UUID NOT NULL,
|
|
tags TEXT []
|
|
);
|
|
-- Primary Key
|
|
DO $$ BEGIN
|
|
ALTER TABLE public.chats
|
|
ADD CONSTRAINT chats_pkey PRIMARY KEY (chatid);
|
|
EXCEPTION
|
|
WHEN invalid_table_definition THEN
|
|
RAISE NOTICE 'Primary key already exists. Ignoring...';
|
|
END $$;
|
|
-- Foreign Key to Users
|
|
DO $$ BEGIN IF NOT EXISTS (
|
|
SELECT 1 FROM pg_constraint
|
|
WHERE conname = 'userchats'
|
|
) THEN
|
|
ALTER TABLE public.chats
|
|
ADD CONSTRAINT userchats
|
|
FOREIGN KEY (user_ref) REFERENCES public.users (id)
|
|
ON UPDATE CASCADE ON DELETE CASCADE;
|
|
END IF;
|
|
END $$; |