CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

CREATE TABLE IF NOT EXISTS public.badges(
    id uuid PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    description TEXT,
    color VARCHAR(32)
);

CREATE TABLE IF NOT EXISTS public.users_badges(
    user_id BIGINT NOT NULL,
    badge_id uuid NOT NULL,
    constraint users_badges_pkey primary key (user_id, badge_id),
    CONSTRAINT "user_id_badge_id_fkey" FOREIGN KEY ("user_id")  REFERENCES "public"."users" ("user_id") ON DELETE CASCADE,
    CONSTRAINT "badge_id_user_id_fkey" FOREIGN KEY ("badge_id")  REFERENCES "public"."badges" ("id") ON DELETE CASCADE
);