use of com.google.gwtorm.server.StatementExecutor in project gerrit by GerritCodeReview.
the class SchemaUpdaterTest method update.
@Test
public void update() throws OrmException, FileNotFoundException, IOException {
db.create();
final Path site = Paths.get(UUID.randomUUID().toString());
final SitePaths paths = new SitePaths(site);
SchemaUpdater u = Guice.createInjector(new FactoryModule() {
@Override
protected void configure() {
TypeLiteral<SchemaFactory<ReviewDb>> schemaFactory = new TypeLiteral<SchemaFactory<ReviewDb>>() {
};
bind(schemaFactory).to(NotesMigrationSchemaFactory.class);
bind(Key.get(schemaFactory, ReviewDbFactory.class)).toInstance(db);
bind(SitePaths.class).toInstance(paths);
Config cfg = new Config();
cfg.setString("user", null, "name", "Gerrit Code Review");
cfg.setString("user", null, "email", "gerrit@localhost");
//
bind(Config.class).annotatedWith(//
GerritServerConfig.class).toInstance(cfg);
//
bind(PersonIdent.class).annotatedWith(//
GerritPersonIdent.class).toProvider(GerritPersonIdentProvider.class);
bind(AllProjectsName.class).toInstance(new AllProjectsName("All-Projects"));
bind(AllUsersName.class).toInstance(new AllUsersName("All-Users"));
bind(GitRepositoryManager.class).toInstance(new InMemoryRepositoryManager());
//
bind(String.class).annotatedWith(//
AnonymousCowardName.class).toProvider(AnonymousCowardNameProvider.class);
bind(DataSourceType.class).to(InMemoryH2Type.class);
bind(SystemGroupBackend.class);
install(new ConfigNotesMigration.Module());
}
}).getInstance(SchemaUpdater.class);
for (SchemaVersion s = u.getLatestSchemaVersion(); s.getVersionNbr() > 1; s = s.getPrior()) {
try {
assertThat(s.getPrior().getVersionNbr()).named("schema %s has prior version %s. Not true that", s.getVersionNbr(), s.getPrior().getVersionNbr()).isEqualTo(s.getVersionNbr() - 1);
} catch (ProvisionException e) {
// version.
break;
}
}
u.update(new UpdateUI() {
@Override
public void message(String msg) {
}
@Override
public boolean yesno(boolean def, String msg) {
return def;
}
@Override
public boolean isBatch() {
return true;
}
@Override
public void pruneSchema(StatementExecutor e, List<String> pruneList) throws OrmException {
for (String sql : pruneList) {
e.execute(sql);
}
}
});
db.assertSchemaVersion();
final SystemConfig sc = db.getSystemConfig();
assertThat(sc.sitePath).isEqualTo(paths.site_path.toAbsolutePath().toString());
}
use of com.google.gwtorm.server.StatementExecutor in project gerrit by GerritCodeReview.
the class Schema_145 method migrateData.
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
JdbcSchema schema = (JdbcSchema) db;
SqlDialect dialect = schema.getDialect();
try (StatementExecutor e = newExecutor(db)) {
try {
dialect.dropIndex(e, "account_external_ids", "account_external_ids_byEmail");
} catch (OrmException ex) {
// Ignore. The index did not exist.
}
e.execute("CREATE INDEX account_external_ids_byEmail" + " ON account_external_ids" + " (email_address)");
}
}
use of com.google.gwtorm.server.StatementExecutor in project gerrit by GerritCodeReview.
the class Schema_89 method migrateData.
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
SqlDialect dialect = ((JdbcSchema) db).getDialect();
try (StatementExecutor e = newExecutor(db)) {
dialect.dropIndex(e, "patch_set_approvals", "patch_set_approvals_openByUser");
dialect.dropIndex(e, "patch_set_approvals", "patch_set_approvals_closedByU");
}
}
use of com.google.gwtorm.server.StatementExecutor in project gerrit by GerritCodeReview.
the class Schema_102 method migrateData.
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
JdbcSchema schema = (JdbcSchema) db;
SqlDialect dialect = schema.getDialect();
try (StatementExecutor e = newExecutor(db)) {
// Drop left over indexes that were missed to be removed in schema 84.
// See "Delete SQL index support" commit for more details:
// d4ae3a16d5e1464574bd04f429a63eb9c02b3b43
Pattern pattern = Pattern.compile("^changes_(allOpen|allClosed|byBranchClosed)$", Pattern.CASE_INSENSITIVE);
String table = "changes";
Set<String> listIndexes = dialect.listIndexes(schema.getConnection(), table);
for (String index : listIndexes) {
if (pattern.matcher(index).matches()) {
dialect.dropIndex(e, table, index);
}
}
dialect.dropIndex(e, table, "changes_byProjectOpen");
if (dialect instanceof DialectPostgreSQL) {
e.execute("CREATE INDEX changes_byProjectOpen" + " ON " + table + " (dest_project_name, last_updated_on)" + " WHERE open = 'Y'");
} else {
e.execute("CREATE INDEX changes_byProjectOpen" + " ON " + table + " (open, dest_project_name, last_updated_on)");
}
}
}
use of com.google.gwtorm.server.StatementExecutor in project gerrit by GerritCodeReview.
the class Schema_105 method migrateData.
@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);
}
}
Aggregations