CREATE TABLE IF NOT EXISTS "public"."users" (
  "id" BIGSERIAL,
  "account_id" UUID NOT NULL DEFAULT gen_random_uuid(),
  "email" TEXT NOT NULL,
  "name" VARCHAR(120),
  "profile" JSONB DEFAULT '{}'::jsonb,
  "balance" NUMERIC(12, 2) NOT NULL DEFAULT 0,
  "active" BOOLEAN NOT NULL DEFAULT true,
  "avatar" BYTEA,
  "created_at" TIMESTAMPTZ NOT NULL DEFAULT now(),
  "version" BIGINT GENERATED ALWAYS AS IDENTITY,
  "updated_at" TIMESTAMP DEFAULT now(),
  CONSTRAINT "users_pkey" PRIMARY KEY ("id"),
  CONSTRAINT "users_email_key" UNIQUE ("email")
);

CREATE INDEX "idx_users_name" ON "public"."users" ("name");

COMMENT ON TABLE "public"."users" IS 'application users';
COMMENT ON COLUMN "public"."users"."email" IS 'login email';
