Add check for last_accessed column in case adding failed due to an error rather than because it already exists

This commit is contained in:
Winston Li 2016-09-04 10:50:51 +01:00 committed by Michael Mazour
parent 5c878ccc70
commit 95a7cb2b8b
2 changed files with 35 additions and 0 deletions

View file

@ -1,5 +1,6 @@
package uk.ac.ic.wlgitbridge.bridge.db.sqlite;
import com.google.common.base.Preconditions;
import uk.ac.ic.wlgitbridge.bridge.db.DBInitException;
import uk.ac.ic.wlgitbridge.bridge.db.DBStore;
import uk.ac.ic.wlgitbridge.bridge.db.ProjectState;
@ -143,6 +144,9 @@ public class SqliteDBStore implements DBStore {
new CreateIndexURLIndexStore(),
new CreateProjectsIndexLastAccessed()
).forEach(this::update);
/* In the case of needing to change the schema, we need to check that
ProjectsAddLastAccessed didn't just fail */
Preconditions.checkState(query(new LastAccessedColumnExists()));
}
private void update(SQLUpdate update) {

View file

@ -0,0 +1,31 @@
package uk.ac.ic.wlgitbridge.bridge.db.sqlite.query;
import uk.ac.ic.wlgitbridge.bridge.db.sqlite.SQLQuery;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* Created by winston on 04/09/2016.
*/
public class LastAccessedColumnExists implements SQLQuery<Boolean> {
private static final String LAST_ACCESSED_COLUMN_EXISTS =
"PRAGMA table_info(`projects`)";
@Override
public String getSQL() {
return LAST_ACCESSED_COLUMN_EXISTS;
}
@Override
public Boolean processResultSet(ResultSet resultSet) throws SQLException {
while (resultSet.next()) {
if (resultSet.getString(2).equals("last_accessed")) {
return true;
}
}
return false;
}
}