#add superseded timestamp to state change log

alter table STATE_CHANGE add column SUPERSEDED timestamp;

update STATE_CHANGE sc1
    set sc1.SUPERSEDED = (
        select sc2.TIME_STAMP from STATE_CHANGE sc2 where sc1.reviewId = sc2.reviewId and sc2.TIME_STAMP > sc1.TIME_STAMP order by sc2.id limit 1)
    where sc1.SUPERSEDED is null;
create index scl_timestamp_idx on STATE_CHANGE (TIME_STAMP);
create index scl_superseded_idx on STATE_CHANGE (SUPERSEDED);

UPDATE CRUVERSION SET version = 22 WHERE version_id = 1;