Updated DB scripts to schema v3
Added to DB functions and queries