Fix #840 Migration of unique/index keys in PgSQL

My second try to fix issue #840.