create or replace PROCEDURE delete_version(IN version_id text)
language plpgsql
as
$$
begin
    call empty_version(version_id);
    delete from versionbackupelement where versionbackupconfid in (select versionbackupconfid from versionbackupconfiguration where versionid = version_id);
    delete from versionbackupconfiguration where versionid = version_id;
    delete from version where versionid = version_id;
end;
$$;

COMMIT;