Optimized db schema

Added pks fks and indices.
Added if exists to new indexes
Added insert package to DB