- 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.
38 lines
No EOL
1.2 KiB
SQL
38 lines
No EOL
1.2 KiB
SQL
-- Users
|
|
CREATE TABLE IF NOT EXISTS public.users (
|
|
id UUID DEFAULT gen_random_uuid () NOT NULL,
|
|
username TEXT NOT NULL,
|
|
email TEXT NOT NULL,
|
|
"isAdmin" boolean DEFAULT FALSE NOT NULL,
|
|
"isBlocked" boolean DEFAULT FALSE NOT NULL,
|
|
PASSWORD TEXT NOT NULL,
|
|
nome TEXT NOT NULL,
|
|
cognome TEXT NOT NULL,
|
|
created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT now() NOT NULL,
|
|
reset_password_token TEXT,
|
|
reset_password_expires TIMESTAMP WITHOUT TIME ZONE,
|
|
telefono TEXT NOT NULL,
|
|
"isAdminMade" boolean DEFAULT FALSE,
|
|
"isVerified" boolean DEFAULT FALSE NOT NULL,
|
|
"verificationToken" TEXT,
|
|
"verificationTokenExpires" TIMESTAMP WITHOUT TIME ZONE,
|
|
salt TEXT NOT NULL
|
|
);
|
|
-- Primary Key
|
|
DO $$ BEGIN
|
|
ALTER TABLE public.users
|
|
ADD CONSTRAINT users_pkey PRIMARY KEY (id);
|
|
EXCEPTION
|
|
WHEN invalid_table_definition THEN
|
|
RAISE NOTICE 'Primary key already exists. Ignoring...';
|
|
END $$;
|
|
-- Unique Email
|
|
DO $$ BEGIN IF NOT EXISTS (
|
|
SELECT 1
|
|
FROM pg_constraint
|
|
WHERE conname = 'users_email_key'
|
|
) THEN
|
|
ALTER TABLE public.users
|
|
ADD CONSTRAINT users_email_key UNIQUE (email);
|
|
END IF;
|
|
END $$; |