Fix rails upgrade bugs and change from sqlite3 to pg.