Fix migration for photos and events.

Make their ids the primary constraint.

Reduce the amount of db commits made in the
photos/events API.