DO $$DECLARE
   this_version CONSTANT varchar := '00.01.067';
BEGIN
   PERFORM * FROM "DBVersion" WHERE version = this_version;
   IF FOUND THEN RETURN; END IF;

	CREATE TABLE public."UsageLimit"
	(
		id uuid NOT NULL,
		label character varying NOT NULL,
		target_metric character varying NOT NULL,
		value integer NOT NULL,
		created_at timestamp without time zone NOT NULL,
		updated_at timestamp without time zone NOT NULL,
		is_active smallint NOT NULL,
		tenant uuid,
		definition xml NOT NULL,
		CONSTRAINT "UsageLimit_pkey" PRIMARY KEY (id),
		CONSTRAINT "UsageLimit_tenant_fkey" FOREIGN KEY (tenant)
			REFERENCES public."Tenant" (id) MATCH SIMPLE
			ON UPDATE NO ACTION
			ON DELETE NO ACTION
			NOT VALID
	);
   
    INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.067', '2024-11-07 12:00:00.000000+02', now(), 'Add UsageLimit table.');

END$$;