CREATE TABLE public.projects (
	id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
	tenant_id uuid NOT NULL REFERENCES public.tenants(id) ON DELETE CASCADE,
	name text NOT NULL,
	created_at timestamptz NOT NULL DEFAULT now(),
	CONSTRAINT projects_name_not_blank_check CHECK (btrim(name) <> '')
);

CREATE INDEX projects_tenant_id_idx ON public.projects (tenant_id);

CREATE TABLE public.project_quotas (
	project_id uuid PRIMARY KEY REFERENCES public.projects(id) ON DELETE CASCADE,
	max_vcpu integer NOT NULL DEFAULT 8,
	max_ram_mb integer NOT NULL DEFAULT 16384,
	max_disk_gb integer NOT NULL DEFAULT 200,
	max_vms integer NOT NULL DEFAULT 10,
	created_at timestamptz NOT NULL DEFAULT now(),
	updated_at timestamptz NOT NULL DEFAULT now(),
	CONSTRAINT project_quotas_max_vcpu_check CHECK (max_vcpu >= 0),
	CONSTRAINT project_quotas_max_ram_mb_check CHECK (max_ram_mb >= 0),
	CONSTRAINT project_quotas_max_disk_gb_check CHECK (max_disk_gb >= 0),
	CONSTRAINT project_quotas_max_vms_check CHECK (max_vms >= 0)
);
