mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-30 19:00:48 +00:00
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:
parent
5c878ccc70
commit
95a7cb2b8b
2 changed files with 35 additions and 0 deletions
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue