Migration from Update.TASK long type to Update.TASK_UUID string type

pull/14/head
Sam Bosley 12 years ago
parent ddb2d4ff66
commit 594f1976bb

@ -46,9 +46,14 @@ public class Update extends RemoteModel {
TABLE, REMOTE_ID_PROPERTY_NAME);
/** Associated Task remote-id (if any) */
@Deprecated // We changed uuids to strings
public static final LongProperty TASK = new LongProperty(
TABLE, "task");
/** Associated Task uuidid (if any) */
public static final StringProperty TASK_UUID = new StringProperty(
TABLE, "taskUuid");
/** Associated Task local-id (if any) */
public static final LongProperty TASK_LOCAL = new LongProperty(
TABLE, "taskLocal");
@ -134,6 +139,7 @@ public class Update extends RemoteModel {
defaultValues.put(REMOTE_ID.name, 0);
defaultValues.put(UUID.name, NO_UUID);
defaultValues.put(TASK.name, 0);
defaultValues.put(TASK_UUID.name, NO_UUID);
defaultValues.put(TASK_LOCAL.name, 0);
defaultValues.put(TAGS.name, "");
defaultValues.put(TAGS_LOCAL.name, 0);

@ -349,7 +349,7 @@ public class TagUpdatesFragment extends ListFragment {
private String getPictureHashForUpdate(Update u) {
String s = u.getValue(Update.TASK).toString() + u.getValue(Update.CREATION_DATE);
String s = u.getValue(Update.TASK_UUID) + u.getValue(Update.CREATION_DATE);
return s;
}

@ -281,8 +281,8 @@ public final class ActFmSyncService {
params.add("tag_id"); params.add(tagId);
}
if(update.getValue(Update.TASK) > 0) {
params.add("task_id"); params.add(update.getValue(Update.TASK));
if(!RemoteModel.NO_UUID.equals(update.getValue(Update.TASK_UUID))) {
params.add("task_id"); params.add(update.getValue(Update.TASK_UUID));
}
MultipartEntity picture = null;
if (imageData != null) {
@ -1017,12 +1017,12 @@ public final class ActFmSyncService {
Criterion criterion = null;
if (task.containsNonNullValue(Task.REMOTE_ID)) {
criterion = Criterion.and(Update.REMOTE_ID.eq(0),
Criterion.or(Update.TASK.eq(task.getValue(Task.REMOTE_ID)), Update.TASK_LOCAL.eq(task.getId())));
Criterion.or(Update.TASK_UUID.eq(task.getValue(Task.UUID)), Update.TASK_LOCAL.eq(task.getId())));
} else
return;
Update template = new Update();
template.setValue(Update.TASK, task.getValue(Task.REMOTE_ID)); //$NON-NLS-1$
template.setValue(Update.TASK_UUID, task.getValue(Task.UUID)); //$NON-NLS-1$
updateDao.update(criterion, template);
TodorooCursor<Update> cursor = updateDao.query(Query.select(Update.ID, Update.PICTURE).where(criterion));
@ -1453,7 +1453,7 @@ public final class ActFmSyncService {
model.setValue(Update.CREATION_DATE, readDate(json, "created_at"));
String tagIds = "," + json.optString("tag_ids", "") + ",";
model.setValue(Update.TAGS, tagIds);
model.setValue(Update.TASK, json.optLong("task_id", 0));
model.setValue(Update.TASK_UUID, Long.toString(json.optLong("task_id", 0)));
}
public static void readUser(JSONObject user, AbstractModel model, LongProperty idProperty,

@ -61,6 +61,7 @@ import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.dao.UpdateDao;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.SyncFlags;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.Update;
@ -290,7 +291,7 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
}
else {
updates = updateDao.query(Query.select(Update.PROPERTIES).where(Criterion.or(
Update.TASK.eq(task.getValue(Task.UUID)), Update.TASK_LOCAL.eq(task.getId()))));
Update.TASK_UUID.eq(task.getValue(Task.UUID)), Update.TASK_LOCAL.eq(task.getId()))));
}
try {
Update update = new Update();
@ -439,8 +440,8 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
update.setValue(Update.MESSAGE, message);
update.setValue(Update.ACTION_CODE, actionCode);
update.setValue(Update.USER_ID, 0L);
if(task.containsNonNullValue(Task.REMOTE_ID))
update.setValue(Update.TASK, task.getValue(Task.REMOTE_ID));
if(task.containsNonNullValue(Task.UUID) && !RemoteModel.NO_UUID.equals(task.getValue(Task.UUID)))
update.setValue(Update.TASK_UUID, task.getValue(Task.UUID));
update.setValue(Update.TASK_LOCAL, task.getId());
update.setValue(Update.CREATION_DATE, DateUtilities.now());
update.setValue(Update.TARGET_NAME, task.getValue(Task.TITLE));

@ -42,6 +42,7 @@ public class Astrid44SyncMigrator {
DependencyInjectionService.getInstance().inject(this);
}
@SuppressWarnings("deprecation")
public void performMigration() {
if (Preferences.getBoolean(PREF_MIGRATED_TASKS_TO_TAGS, false))
return;
@ -75,13 +76,20 @@ public class Astrid44SyncMigrator {
// Then ensure that every remote model has a remote id, by generating one using the uuid generator for all those without one
// --------------
Query tagsWithoutUUIDQuery = Query.select(TagData.ID, TagData.REMOTE_ID).where(Criterion.all);
assertUUIDsExist(tagsWithoutUUIDQuery, new TagData(), tagDataDao);
assertUUIDsExist(tagsWithoutUUIDQuery, new TagData(), tagDataDao, null);
Query tasksWithoutUUIDQuery = Query.select(Task.ID, Task.REMOTE_ID).where(Criterion.all);
assertUUIDsExist(tasksWithoutUUIDQuery, new Task(), taskDao);
Query updatesWithoutUUIDQuery = Query.select(Update.ID, Update.REMOTE_ID).where(Criterion.all);
assertUUIDsExist(updatesWithoutUUIDQuery, new Update(), updateDao);
assertUUIDsExist(tasksWithoutUUIDQuery, new Task(), taskDao, null);
Query updatesWithoutUUIDQuery = Query.select(Update.ID, Update.REMOTE_ID, Update.TASK).where(Criterion.all);
assertUUIDsExist(updatesWithoutUUIDQuery, new Update(), updateDao, new UUIDAssertionExtras<Update>() {
@Override
public void beforeSave(Update instance) {
// Migrate Update.TASK long to Update.TASK_UUID string
if (instance.getValue(Update.TASK) != 0)
instance.setValue(Update.TASK_UUID, Long.toString(instance.getValue(Update.TASK)));
}
});
// --------------
@ -129,7 +137,11 @@ public class Astrid44SyncMigrator {
Preferences.setBoolean(PREF_MIGRATED_TASKS_TO_TAGS, true);
}
private <TYPE extends RemoteModel> void assertUUIDsExist(Query query, TYPE instance, DatabaseDao<TYPE> dao) {
private interface UUIDAssertionExtras<TYPE extends RemoteModel> {
void beforeSave(TYPE instance);
}
private <TYPE extends RemoteModel> void assertUUIDsExist(Query query, TYPE instance, DatabaseDao<TYPE> dao, UUIDAssertionExtras<TYPE> extras) {
TodorooCursor<TYPE> cursor = dao.query(query);
try {
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
@ -143,6 +155,9 @@ public class Astrid44SyncMigrator {
// Migrate remote id to uuid field
instance.setValue(RemoteModel.UUID_PROPERTY, Long.toString(instance.getValue(RemoteModel.REMOTE_ID_PROPERTY)));
}
if (extras != null)
extras.beforeSave(instance);
dao.saveExisting(instance);
}
} finally {

@ -361,7 +361,7 @@ public class UpdateAdapter extends CursorAdapter {
if (TASK_LINK_TYPE.equals(linkType)) {
long taskId = update.getValue(Update.TASK_LOCAL);
if (taskId <= 0) {
Task local = PluginServices.getTaskService().fetchByUUID(Long.toString(update.getValue(Update.TASK)), Task.ID);
Task local = PluginServices.getTaskService().fetchByUUID(update.getValue(Update.TASK_UUID), Task.ID);
if (local != null)
taskId = local.getId();
}

@ -128,7 +128,7 @@ public class Database extends AbstractDatabase {
sql.append("CREATE INDEX IF NOT EXISTS up_tid ON ").
append(Update.TABLE).append('(').
append(Update.TASK.name).
append(Update.TASK_UUID.name).
append(')');
database.execSQL(sql.toString());
sql.setLength(0);
@ -348,6 +348,7 @@ public class Database extends AbstractDatabase {
database.execSQL(addColumnSql(Update.TABLE, Update.PROOF_TEXT, visitor, null));
database.execSQL(addColumnSql(Update.TABLE, Update.PUSHED_AT, visitor, null));
database.execSQL(addColumnSql(Update.TABLE, Update.UUID, visitor, null));
database.execSQL(addColumnSql(Update.TABLE, Update.TASK_UUID, visitor, null));
database.execSQL(addColumnSql(Metadata.TABLE, Metadata.DELETION_DATE, visitor, "0"));
database.execSQL(addColumnSql(User.TABLE, User.PUSHED_AT, visitor, null));
} catch (SQLiteException e) {

@ -196,7 +196,7 @@ public class ImageDiskCache extends DiskCache<String, Bitmap> {
}
public static String getPictureHash(Update update) {
return String.format("%s%s%s", CACHED_IDENTIFIER, update.getValue(Update.TASK), update.getValue(Update.CREATION_DATE));
return String.format("%s%s%s", CACHED_IDENTIFIER, update.getValue(Update.TASK_UUID), update.getValue(Update.CREATION_DATE));
}

Loading…
Cancel
Save