6103: Add persona tables on CR database upgrade.

This commit is contained in:
Raman Arora 2020-04-10 12:56:02 -04:00
parent dd2ceabe21
commit 837cd5110c
3 changed files with 53 additions and 3 deletions

View File

@ -0,0 +1,47 @@
/*
* Central Repository
*
* Copyright 2020 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* 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 org.sleuthkit.autopsy.centralrepository.datamodel;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import org.sleuthkit.datamodel.CaseDbSchemaVersionNumber;
/**
* This class updates CR schema to 1.5
*
*/
public class CentralRepoDbUpgrader14To15 implements CentralRepoDbUpgrader {
@Override
public void upgradeSchema(CaseDbSchemaVersionNumber dbSchemaVersion, Connection connection) throws CentralRepoException, SQLException {
if (dbSchemaVersion.compareTo(new CaseDbSchemaVersionNumber(1, 5)) < 0) {
try (Statement statement = connection.createStatement();) {
CentralRepoPlatforms selectedPlatform = CentralRepoDbManager.getSavedDbChoice().getDbPlatform();
// create persona tables and insert default data
RdbmsCentralRepoFactory.createPersonaTables(statement, selectedPlatform);
RdbmsCentralRepoFactory.insertDefaultPersonaTablesContent(connection, selectedPlatform);
}
}
}
}

View File

@ -3787,6 +3787,9 @@ abstract class RdbmsCentralRepo implements CentralRepository {
// Upgrade to 1.4
(new CentralRepoDbUpgrader13To14()).upgradeSchema(dbSchemaVersion, conn);
// Upgrade to 1.5
(new CentralRepoDbUpgrader14To15()).upgradeSchema(dbSchemaVersion, conn);
updateSchemaVersion(conn);
conn.commit();
logger.log(Level.INFO, String.format("Central Repository schema updated to version %s", SOFTWARE_CR_DB_SCHEMA_VERSION));

View File

@ -169,7 +169,7 @@ public class RdbmsCentralRepoFactory {
}
}
// create Persona tables.
createPersonaTables(stmt);
createPersonaTables(stmt, selectedPlatform);
} catch (SQLException ex) {
LOGGER.log(Level.SEVERE, "Error initializing db schema.", ex); // NON-NLS
return false;
@ -606,7 +606,7 @@ public class RdbmsCentralRepoFactory {
*
* @return True if success, False otherwise.
*/
private boolean createPersonaTables(Statement stmt) throws SQLException {
static boolean createPersonaTables(Statement stmt, CentralRepoPlatforms selectedPlatform) throws SQLException {
stmt.execute(getCreateConfidenceTableStatement(selectedPlatform));
stmt.execute(getCreateExaminersTableStatement(selectedPlatform));
@ -806,7 +806,7 @@ public class RdbmsCentralRepoFactory {
*
* @return True if success, false otherwise.
*/
private static boolean insertDefaultPersonaTablesContent(Connection conn, CentralRepoPlatforms selectedPlatform) {
static boolean insertDefaultPersonaTablesContent(Connection conn, CentralRepoPlatforms selectedPlatform) {
try (Statement stmt = conn.createStatement()) {
// populate the confidence table