Versioning issues on session.flush

Hey, opening a pull request with some fixes related to mid-transaction flushes. Check the added tests to see what I think the expected behavior should be
- Keep the version's type as INSERT when a new object is flushed and then modified within the same single transaction. Currently there is no insert entry ever created.
- Ensure the same versioning behavior when primary keys of objects are modified after a flush, with the behavior that you get when they are modified without a flush.

Update:
- When a new object is created, flushed, then deleted (all in the same transaction), no version entry to be saved.
- Postgres triggers have also been updated.
Rather than this I think a better one would be:
```
cascade='all, delete-orphan',
passive_deletes=True
```
This uses foreign keys for deletion, but at the same time marks the in memory objects as deleted.