Add the database code for historical data