Remove leftover Change indexes and open field

These were just to support the queries that were previously removed
from ChangeAccess. Upgrade the schema to get rid of them.

Change-Id: I32b7adc37c0899b9821df2bfa261a39525b370f9
This commit is contained in:
Dave Borowitz
2015-01-15 12:44:29 -05:00
parent f9c88308de
commit e4e8315cc6
3 changed files with 92 additions and 7 deletions

View File

@@ -442,9 +442,7 @@ public final class Change {
@Column(id = 8)
protected Branch.NameKey dest;
/** Is the change currently open? Set to {@link #status}.isOpen(). */
@Column(id = 9)
protected boolean open;
// DELETED: id = 9 (open)
/** Current state code; see {@link Status}. */
@Column(id = 10)
@@ -498,7 +496,6 @@ public final class Change {
lastUpdatedOn = other.lastUpdatedOn;
owner = other.owner;
dest = other.dest;
open = other.open;
status = other.status;
currentPatchSetId = other.currentPatchSetId;
subject = other.subject;
@@ -590,8 +587,7 @@ public final class Change {
return Status.forCode(status);
}
public void setStatus(final Status newStatus) {
open = newStatus.isOpen();
public void setStatus(Status newStatus) {
status = newStatus.getCode();
}

View File

@@ -32,7 +32,7 @@ import java.util.List;
/** A version of the database schema. */
public abstract class SchemaVersion {
/** The current schema version. */
public static final Class<Schema_104> C = Schema_104.class;
public static final Class<Schema_105> C = Schema_105.class;
public static int getBinaryVersion() {
return guessVersion(C);

View File

@@ -0,0 +1,89 @@
// Copyright (C) 2015 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.schema;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gwtorm.jdbc.JdbcSchema;
import com.google.gwtorm.schema.sql.SqlDialect;
import com.google.gwtorm.server.OrmException;
import com.google.gwtorm.server.StatementExecutor;
import com.google.inject.Inject;
import com.google.inject.Provider;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class Schema_105 extends SchemaVersion {
private static final String TABLE = "changes";
@Inject
Schema_105(Provider<Schema_104> prior) {
super(prior);
}
@Override
protected void migrateData(ReviewDb db, UpdateUI ui)
throws SQLException, OrmException {
JdbcSchema schema = (JdbcSchema) db;
SqlDialect dialect = schema.getDialect();
Map<String, OrmException> errors = new HashMap<>();
try (StatementExecutor e = newExecutor(db)) {
for (String index : listChangesIndexes(schema)) {
ui.message("Dropping index " + index + " on table " + TABLE);
try {
dialect.dropIndex(e, TABLE, index);
} catch (OrmException err) {
errors.put(index, err);
}
}
}
for (String index : listChangesIndexes(schema)) {
String msg = "Failed to drop index " + index;
OrmException err = errors.get(index);
if (err != null) {
msg += ": " + err.getMessage();
}
ui.message(msg);
}
}
private Set<String> listChangesIndexes(JdbcSchema schema)
throws SQLException {
// List of all changes indexes ever created or dropped, found with the
// following command:
// find g* -name \*.sql | xargs git log -i -p -S' index changes_' | grep -io ' index changes_\w*' | cut -d' ' -f3 | tr A-Z a-z | sort -u
// Used rather than listIndexes as we're not sure whether it might include
// primary key indexes.
Set<String> allChanges = ImmutableSet.of(
"changes_allclosed",
"changes_allopen",
"changes_bybranchclosed",
"changes_byownerclosed",
"changes_byowneropen",
"changes_byproject",
"changes_byprojectopen",
"changes_key",
"changes_submitted");
return Sets.intersection(
schema.getDialect().listIndexes(schema.getConnection(), TABLE),
allChanges);
}
}