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

   ALTER TABLE IF EXISTS public."EntityDoi" DROP COLUMN IF EXISTS entity_type;

ALTER TABLE IF EXISTS public."EntityDoi"
    ADD COLUMN entity_type smallint NOT NULL DEFAULT 0;
	
ALTER TABLE IF EXISTS public."EntityDoi"
    ALTER COLUMN entity_type DROP DEFAULT;
        
    INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.046', '2023-12-27 12:00:00.000000+02', now(), 'Change Entity Type To Enum at Entity DOI table');

END$$;