Fix memory leak in database migration
Fix invalid check for fread error on extracting zip
Remove lots of dead code
Add check for datatype overflows
use native datatype indices instead of fixed 16bit/32bit ones