Fix infinite loop
Checks if api tables exists before apllaying patch