'Update the container_stat policy_index and status_changed_at.'

def set_storage_policy_index(self, policy_index, timestamp=None):

    if (timestamp is None):
        timestamp = Timestamp.now().internal
    def _setit(conn):
        conn.execute('\n                                                                INSERT    OR    IGNORE    INTO    policy_stat    (storage_policy_index)\n                                                                VALUES    (?)\n                                                    ', (policy_index,))
        conn.execute('\n                                                                UPDATE    container_stat\n                                                                SET    storage_policy_index    =    ?,\n                                                                                status_changed_at    =    MAX(?,    status_changed_at)\n                                                                WHERE    storage_policy_index    <>    ?\n                                                ', (policy_index, timestamp, policy_index))
        conn.commit()
    with self.get() as conn:
        try:
            _setit(conn)
        except sqlite3.OperationalError as err:
            if (not any(((msg in str(err)) for msg in ('no    such    column:    storage_policy_index', 'no    such    table:    policy_stat')))):
                raise
            self._migrate_add_storage_policy(conn)
            _setit(conn)
    self._storage_policy_index = policy_index
