Introduce a tag_id history field for better keeping track of history entries that correspond to particular tags

pull/14/head
Sam Bosley 12 years ago
parent 9c5eff5368
commit 5ac4e10b1d

@ -63,6 +63,11 @@ public class History extends AbstractModel {
public static final StringProperty TASK = new StringProperty(
TABLE, "task");
/** Associated tag id */
public static final StringProperty TAG_ID = new StringProperty(
TABLE, "tag_id");
/** Default values container */
private static final ContentValues defaultValues = new ContentValues();
@ -74,9 +79,10 @@ public class History extends AbstractModel {
static {
defaultValues.put(UUID.name, 0L);
defaultValues.put(CREATED_AT.name, 0L);
defaultValues.put(USER_UUID.name, "0");
defaultValues.put(USER_UUID.name, RemoteModel.NO_UUID);
defaultValues.put(OLD_VALUE.name, "");
defaultValues.put(NEW_VALUE.name, "");
defaultValues.put(TAG_ID.name, RemoteModel.NO_UUID);
defaultValues.put(TASK.name, "");
}

@ -107,7 +107,7 @@ public class FetchHistory<TYPE extends RemoteModel> {
History history = new History();
history.setValue(History.TABLE_ID, table);
history.setValue(History.TARGET_ID, uuid);
history.setValue(History.UUID, historyJson.optString("id"));
history.setValue(History.UUID, historyJson.optString("id") + ":" + uuid);
history.setValue(History.USER_UUID, historyJson.optString("user_id"));
history.setValue(History.COLUMN, historyJson.optString("column"));
history.setValue(History.OLD_VALUE, historyJson.optString("prev"));
@ -124,6 +124,8 @@ public class FetchHistory<TYPE extends RemoteModel> {
taskObj.put(uuid);
taskObj.put(taskTitle);
history.setValue(History.TASK, taskObj.toString());
} else if (NameMaps.TABLE_ID_TAGS.equals(table)) {
history.setValue(History.TAG_ID, uuid);
}
if (historyDao.update(History.UUID.eq(history.getValue(History.UUID)), history) <= 0) {

@ -53,7 +53,7 @@ public class Database extends AbstractDatabase {
* Database version number. This variable must be updated when database
* tables are updated, as it determines whether a database needs updating.
*/
public static final int VERSION = 32;
public static final int VERSION = 33;
/**
* Database name (must be unique)
@ -350,14 +350,12 @@ public class Database extends AbstractDatabase {
}
case 28:
case 29:
tryExecSQL("DROP TABLE " + History.TABLE.name);
tryExecSQL(createTableSql(visitor, TaskOutstanding.TABLE.name, TaskOutstanding.PROPERTIES));
tryExecSQL(createTableSql(visitor, TagOutstanding.TABLE.name, TagOutstanding.PROPERTIES));
tryExecSQL(createTableSql(visitor, TaskAttachmentOutstanding.TABLE.name, TagOutstanding.PROPERTIES));
tryExecSQL(createTableSql(visitor, TagMetadata.TABLE.name, TagMetadata.PROPERTIES));
tryExecSQL(createTableSql(visitor, UserActivity.TABLE.name, UserActivity.PROPERTIES));
tryExecSQL(createTableSql(visitor, UserActivityOutstanding.TABLE.name, UserActivityOutstanding.PROPERTIES));
tryExecSQL(createTableSql(visitor, History.TABLE.name, History.PROPERTIES));
tryExecSQL(createTableSql(visitor, TaskAttachment.TABLE.name, TaskAttachment.PROPERTIES));
tryExecSQL(createTableSql(visitor, TaskListMetadata.TABLE.name, TaskListMetadata.PROPERTIES));
tryExecSQL(createTableSql(visitor, TaskListMetadataOutstanding.TABLE.name, TaskListMetadataOutstanding.PROPERTIES));
@ -386,6 +384,10 @@ public class Database extends AbstractDatabase {
case 31:
tryExecSQL(addColumnSql(Task.TABLE, Task.HISTORY_HAS_MORE, visitor, null));
tryExecSQL(addColumnSql(TagData.TABLE, TagData.HISTORY_HAS_MORE, visitor, null));
case 32:
tryExecSQL("DROP TABLE " + History.TABLE.name);
tryExecSQL(createTableSql(visitor, History.TABLE.name, History.PROPERTIES));
return true;
}

@ -23,7 +23,6 @@ import com.todoroo.andlib.sql.Order;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.astrid.actfm.sync.ActFmSyncService;
import com.todoroo.astrid.actfm.sync.messages.NameMaps;
import com.todoroo.astrid.adapter.UpdateAdapter;
import com.todoroo.astrid.api.PermaSql;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
@ -174,9 +173,7 @@ public class TagDataService {
if (tagData == null)
historyCriterion = Criterion.none;
else
historyCriterion = Criterion.or(Criterion.and(History.TABLE_ID.eq(NameMaps.TABLE_ID_TAGS), History.TARGET_ID.eq(tagData.getUuid())),
Criterion.and(History.TABLE_ID.eq(NameMaps.TABLE_ID_TASKS), History.TARGET_ID.in(Query.select(TaskToTagMetadata.TASK_UUID)
.from(Metadata.TABLE).where(Criterion.and(MetadataCriteria.withKey(TaskToTagMetadata.KEY), TaskToTagMetadata.TAG_UUID.eq(tagData.getUuid()))))));
historyCriterion = History.TAG_ID.eq(tagData.getUuid());
Query historyQuery = Query.select(AndroidUtilities.addToArray(UpdateAdapter.HISTORY_PROPERTIES, userProperties)).from(History.TABLE)
.where(historyCriterion)

Loading…
Cancel
Save