Chat history sqlite fixes

This prevents lines from being cut and cleans up the database to prevent large growth