// Add eve_life_id column

ALTER TABLE lineageServer_lives ADD eve_life_id INT NOT NULL AFTER generation;

UPDATE lineageServer_lives SET eve_life_id = -1;

UPDATE lineageServer_lives SET eve_life_id = 0 where parent_id = -1;



// add death_cause string

ALTER TABLE lineageServer_lives ADD death_cause VARCHAR(254) NOT NULL AFTER killer_id;

UPDATE lineageServer_lives SET death_cause = "";





// added deepest descendant info



ALTER TABLE lineageServer_lives ADD deepest_descendant_generation INT NOT NULL AFTER eve_life_id;

ALTER TABLE lineageServer_lives ADD deepest_descendant_life_id INT NOT NULL AFTER deepest_descendant_generation;

UPDATE lineageServer_lives set deepest_descendant_generation = -1, deepest_descendant_life_id = -1;




// add index for lives.name (so name search is faster)

ALTER TABLE lineageServer_lives ADD INDEX name ( name );



// add email hash, and compute it for all

ALTER TABLE lineageServer_users ADD email_sha1 VARCHAR(40) NOT NULL AFTER email;

ALTER TABLE lineageServer_users ADD INDEX email_sha1 ( email_sha1 );

UPDATE lineageServer_users SET email_sha1 = sha1( email );


// index for log
ALTER TABLE lineageServer_log ADD INDEX entry_time ( entry_time );




ALTER TABLE lineageServer_lives ADD INDEX ( deepest_descendant_generation, death_time );




ALTER TABLE lineageServer_lives ADD lineage_depth INT NOT NULL AFTER deepest_descendant_life_id;

ALTER TABLE lineageServer_lives ADD INDEX lineage_depth ( lineage_depth );


ALTER TABLE lineageServer_lives ADD INDEX ( lineage_depth, death_time );



UPDATE lineageServer_lives set lineage_depth = deepest_descendant_generation - generation WHERE deepest_descendant_generation != -1 and generation != -1;


ALTER TABLE lineageServer_lives ADD INDEX eve_life_id ( eve_life_id );



ALTER TABLE lineageServer_lives ADD INDEX ( user_id, death_time );



// expand last_words field

ALTER TABLE lineageServer_lives MODIFY COLUMN last_words VARCHAR(254) NOT NULL;



ALTER TABLE lineageServer_lives ADD INDEX ( eve_life_id, death_time );