Clean left over data migration after removal of TrackingIds table

9f4de526dd removed TrackingIds table.
766e4415b0 tries to swap primary key from
tracking_id to tracking_key in data migration method.

But because the table was removed from the Schema the TrackingIds is not
picked by gwtorm for the upgrade (ALTER TABLE add tracking_key statement).

In Schema_70 the migration step tries to execute:

  UPDATE tracking_ids SET tracking_key = tracking_id

and is failing because the column tracking_key wasn't created.

To rectify this, remove the migrate data method entirely in Schema_70.

Bug: Issue 2382
Change-Id: I1d7b6deb50be8595626d210a4350683d8b996de5
This commit is contained in:
David Ostrovsky
2014-01-10 15:22:46 +09:00
committed by David Pursehouse
parent c73bcab298
commit 2d6629742c

View File

@@ -14,48 +14,12 @@
package com.google.gerrit.server.schema;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gwtorm.jdbc.JdbcSchema;
import com.google.gwtorm.schema.sql.DialectPostgreSQL;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import java.sql.SQLException;
import java.sql.Statement;
public class Schema_70 extends SchemaVersion {
@Inject
protected Schema_70(Provider<Schema_69> prior) {
super(prior);
}
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException,
SQLException {
Statement stmt = ((JdbcSchema) db).getConnection().createStatement();
try {
stmt.executeUpdate("UPDATE tracking_ids SET tracking_key = tracking_id");
execute(stmt, "DROP INDEX tracking_ids_byTrkId");
if (((JdbcSchema) db).getDialect() instanceof DialectPostgreSQL) {
execute(stmt, "ALTER TABLE tracking_ids DROP CONSTRAINT tracking_ids_pkey");
} else {
execute(stmt, "ALTER TABLE tracking_ids DROP PRIMARY KEY");
}
stmt.execute("ALTER TABLE tracking_ids"
+ " ADD PRIMARY KEY (change_id, tracking_key, tracking_system)");
stmt.execute("CREATE INDEX tracking_ids_byTrkKey"
+ " ON tracking_ids (tracking_key)");
} finally {
stmt.close();
}
}
private static final void execute(Statement stmt, String command) {
try {
stmt.execute(command);
} catch (SQLException e) {
// ignore
}
}
}