Added first pass of moving 'done' logic to output.

The middle keeps track of the items which have changed due to
updates to the OSM elements, i.e: a way is marked pending because
a node that it uses has changed. However, the output also made
some decisions about what to track by passing a `pending` flag to
some methods, and calling `ways_done` or `relations_done` for some
elements.

We want to have multiple outputs for the same middle, so we need
these decisions to be made for each individual output. This commit
is the first step, by moving all the custom 'done' tracking to the
output types via a shared, provisional tracker, which will be
written properly in the next pass.
Actually, the gazetteer output doesn't need this.
Implemented pgsql ID tracker.
Moved more logic for done/pending status into output.

NOTE: tests don't yet pass - there are 3 failures in the regression
suite. Note sure yet what's causing these.
Deallocate ways and relations in `stop()`.

Previously was deallocating at least some parts during
`iterate_ways` and `iterate_relations`, which meant that any
attempt after that to read ways or relations data returned that
they weren't present.
Simulate deleting ways after iteration for compatibilty.
Add index on id for lookup speed. Still not as fast as before, sadly.
merge from mla branch