--- title: DB Migration --- # DB Migration for py2 - py3 Number of users in search and store match: ```sql select count(*) from ezidapp_storeuser; 202 ``` searchuser ids different to storeuser ids: ```sql select a.id, b.id, a.pid from ezidapp_searchuser a join ezidapp_storeuser b on a.pid = b.pid and a.id != b.id; ``` There are entries in searchidentifier that are not in storedatacenter: ```sql select s.id, s.symbol from ezidapp_searchdatacenter s where s.symbol not in (select symbol from ezidapp_storedatacenter); +-----+--------------+ | id | symbol | +-----+--------------+ | 1 | CDL.CMU | | 196 | CDL.INVEMAR | | 174 | CDL.LCC | | 111 | CDL.MITLCP | | 200 | CDL.PITT | | 139 | CDL.PQR | | 97 | CDL.USFWS | | 124 | CDL.UTAUSTIN | | 209 | PURDUE.NUL | +-----+--------------+ ``` None of those are referenced from the searchidentifier table though: ```sql select count(*) from ezidapp_searchidentifier where datacenter_id in (1, 196, 174, 111, 200, 139, 97, 124, 209); ``` Create a temporary table with the entries: ``` create temporary table searchnotstoreusers (sid int, tid int, pid varchar(255)); ``` And populate it: ``` insert into searchnotstoreusers(sid, tid, pid) select a.id as sid, b.id as tid, a.pid as pid from ezidapp_searchuser a join ezidapp_storeuser b on a.pid = b.pid and a.id != b.id; ``` ```sql= create temporary table tmp_searchid select id, identifier, owner_id, ownergroup_id, datacenter_id, profile_id from ezidapp_searchidentifier limit 1000; ``` ```sql= select tmp_searchid.identifier, tmp_searchid.owner_id, searchnotstoreusers.sid, searchnotstoreusers.tid from tmp_searchid left join searchnotstoreusers on tmp_searchid.owner_id = searchnotstoreusers.sid limit 10; ``` ```sql= update tmp_searchid left join searchnotstoreusers on tmp_searchid.owner_id = searchnotstoreusers.sid set tmp_searchid.owner_id = searchnotstoreusers.tid; ```