apply upgrade fixes for postgre and sqlite

Signed-off-by: Suki <suki@missallsunday.com>
apply suggested fixes for legacy attachments on postgre and sqlite

Signed-off-by: Suki <suki@missallsunday.com>