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

ALTER TABLE public."EntityDoi"
    RENAME "ID" TO id;
	
ALTER TABLE public."EntityDoi"
    RENAME "EntityType" TO entity_type;
	
ALTER TABLE public."EntityDoi"
    RENAME "RepositoryId" TO repository_id;
	
ALTER TABLE public."EntityDoi"
    RENAME "Doi" TO doi;
	
ALTER TABLE public."EntityDoi"
    RENAME "CreatedAt" TO created_at;
	
ALTER TABLE public."EntityDoi"
    RENAME "UpdatedAt" TO updated_at;

ALTER TABLE public."EntityDoi"
    RENAME "EntityId" TO entity_id;
	
ALTER TABLE public."EntityDoi"
    ADD COLUMN is_active smallint NOT NULL DEFAULT 1


INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.002', '2023-10-19 12:00:00.000000+02', now(), 'Align Entity Doi table.');

END$$;