From 8ab4072504dd5409f094d30d0913f42bcb9969a4 Mon Sep 17 00:00:00 2001 From: mohitdeuex Date: Wed, 26 Jul 2023 16:40:52 +0530 Subject: [PATCH] Change ignoreFileChksum to force --- bootstrap/bootstrap_storage.sh | 14 +++++------ .../migration/api/MigrationWorkflow.java | 8 +++---- .../service/util/TablesInitializer.java | 23 +++++++++---------- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/bootstrap/bootstrap_storage.sh b/bootstrap/bootstrap_storage.sh index 9e4193c5030..179d0e09c93 100755 --- a/bootstrap/bootstrap_storage.sh +++ b/bootstrap/bootstrap_storage.sh @@ -13,12 +13,12 @@ # Resolve links - $0 may be a softlink PRG="${0}" debug="$2" -ignoreFileChecksum="$3" +force=false -if [ -n "${ignoreFileChecksum+x}" ]; then - ignoreFileChecksum=true +if [ -z "$3" ]; then + force=false else - ignoreFileChecksum=false + force=true fi while [ -h "${PRG}" ]; do @@ -60,12 +60,12 @@ execute() { if [ ${debug} ] ; then echo "Using Configuration file: ${CONFIG_FILE_PATH}" fi - ${JAVA} -Dbootstrap.dir=$BOOTSTRAP_DIR -cp ${CLASSPATH} ${TABLE_INITIALIZER_MAIN_CLASS} -c ${CONFIG_FILE_PATH} -s ${SCRIPT_ROOT_DIR} --${1} -ignoreCheckSum ${ignoreFileChecksum} -${debug} + ${JAVA} -Dbootstrap.dir=$BOOTSTRAP_DIR -cp ${CLASSPATH} ${TABLE_INITIALIZER_MAIN_CLASS} -c ${CONFIG_FILE_PATH} -s ${SCRIPT_ROOT_DIR} --${1} -force ${force} -${debug} } printUsage() { cat <<-EOF -USAGE: $0 [create|migrate|info|validate|drop|drop-create|es-drop|es-create|drop-create-all|migrate-all|repair|check-connection|rotate] [debug] [ignoreFileChecksum] +USAGE: $0 [create|migrate|info|validate|drop|drop-create|es-drop|es-create|drop-create-all|migrate-all|repair|check-connection|rotate] [debug] [force] create : Creates the tables. The target database should be empty migrate : Migrates the database to the latest version or creates the tables if the database is empty. Use "info" to see the current version and the pending migrations info : Shows the list of migrations applied and the pending migration waiting to be applied on the target database @@ -81,7 +81,7 @@ USAGE: $0 [create|migrate|info|validate|drop|drop-create|es-drop|es-create|drop- check-connection : Checks if a connection can be successfully obtained for the target database rotate : Rotate the Fernet Key defined in $FERNET_KEY debug : Enable Debugging Mode to get more info - ignoreFileChecksum : Ignore Checksum forces Server Migration for already run migration to be run again + force : Forces the server Migration to be ran, even if already ran EOF } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/migration/api/MigrationWorkflow.java b/openmetadata-service/src/main/java/org/openmetadata/service/migration/api/MigrationWorkflow.java index b70b56c719b..50467f099a8 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/migration/api/MigrationWorkflow.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/migration/api/MigrationWorkflow.java @@ -15,12 +15,12 @@ public class MigrationWorkflow { private final List migrations; private final MigrationDAO migrationDAO; private final Jdbi jdbi; - private boolean ignoreFileChecksum = false; + private final boolean forceMigrations; - public MigrationWorkflow(Jdbi jdbi, List migrationSteps, boolean ignoreFileChecksum) { + public MigrationWorkflow(Jdbi jdbi, List migrationSteps, boolean forceMigrations) { this.jdbi = jdbi; this.migrationDAO = jdbi.onDemand(MigrationDAO.class); - this.ignoreFileChecksum = ignoreFileChecksum; + this.forceMigrations = forceMigrations; // Sort Migration on the basis of version migrationSteps.sort(Comparator.comparing(MigrationStep::getMigrationVersion)); @@ -62,7 +62,7 @@ public class MigrationWorkflow { if (maxMigration.compareTo(step.getMigrationVersion()) < 0) { // This a new Step file result.add(step); - } else if (ignoreFileChecksum || !checksum.equals(step.getFileUuid())) { + } else if (forceMigrations || !checksum.equals(step.getFileUuid())) { // This migration step was ran already, if checksum is equal this step can be ignored LOG.warn( "[Migration Workflow] You are changing an older Migration File. This is not advised. Add your changes to latest Migrations."); diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/util/TablesInitializer.java b/openmetadata-service/src/main/java/org/openmetadata/service/util/TablesInitializer.java index 3725ec9cc0f..0ddaa580f03 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/util/TablesInitializer.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/util/TablesInitializer.java @@ -64,11 +64,11 @@ public final class TablesInitializer { private static final String DEBUG_MODE_ENABLED = "debug_mode"; private static final String OPTION_SCRIPT_ROOT_PATH = "script-root"; private static final String OPTION_CONFIG_FILE_PATH = "config"; - private static final String OPTION_IGNORE_SERVER_FILE_CHECKSUM = "ignoreCheckSum"; + private static final String OPTION_FORCE_MIGRATIONS = "force"; private static final String DISABLE_VALIDATE_ON_MIGRATE = "disable-validate-on-migrate"; private static final Options OPTIONS; private static boolean debugMode = false; - private static boolean ignoreServerFileChecksum = false; + private static boolean forceMigrations = false; static { OPTIONS = new Options(); @@ -76,10 +76,10 @@ public final class TablesInitializer { OPTIONS.addOption("s", OPTION_SCRIPT_ROOT_PATH, true, "Root directory of script path"); OPTIONS.addOption("c", OPTION_CONFIG_FILE_PATH, true, "Config file path"); OPTIONS.addOption( - "ignoreCheckSum", - OPTION_IGNORE_SERVER_FILE_CHECKSUM, + OPTION_FORCE_MIGRATIONS, + OPTION_FORCE_MIGRATIONS, true, - "Ignore the server checksum and rerun same file in migrate"); + "Ignore the server checksum and force migrations to be run again"); OPTIONS.addOption(null, SchemaMigrationOption.CREATE.toString(), false, "Run sql migrations from scratch"); OPTIONS.addOption(null, SchemaMigrationOption.DROP.toString(), false, "Drop all the tables in the target database"); OPTIONS.addOption( @@ -126,8 +126,8 @@ public final class TablesInitializer { if (commandLine.hasOption(DEBUG_MODE_ENABLED)) { debugMode = true; } - if (commandLine.hasOption(OPTION_IGNORE_SERVER_FILE_CHECKSUM)) { - ignoreServerFileChecksum = Boolean.parseBoolean(commandLine.getOptionValue(OPTION_IGNORE_SERVER_FILE_CHECKSUM)); + if (commandLine.hasOption(OPTION_FORCE_MIGRATIONS)) { + forceMigrations = Boolean.parseBoolean(commandLine.getOptionValue(OPTION_FORCE_MIGRATIONS)); } boolean isSchemaMigrationOptionSpecified = false; SchemaMigrationOption schemaMigrationOptionSpecified = null; @@ -275,13 +275,13 @@ public final class TablesInitializer { } flyway.migrate(); validateAndRunSystemDataMigrations( - jdbi, ConnectionType.from(config.getDataSourceFactory().getDriverClass()), ignoreServerFileChecksum); + jdbi, ConnectionType.from(config.getDataSourceFactory().getDriverClass()), forceMigrations); break; case MIGRATE: flyway.migrate(); // Validate and Run System Data Migrations validateAndRunSystemDataMigrations( - jdbi, ConnectionType.from(config.getDataSourceFactory().getDriverClass()), ignoreServerFileChecksum); + jdbi, ConnectionType.from(config.getDataSourceFactory().getDriverClass()), forceMigrations); break; case INFO: printToConsoleMandatory(dumpToAsciiTable(flyway.info().all())); @@ -331,11 +331,10 @@ public final class TablesInitializer { } } - public static void validateAndRunSystemDataMigrations( - Jdbi jdbi, ConnectionType connType, boolean ignoreFileChecksum) { + public static void validateAndRunSystemDataMigrations(Jdbi jdbi, ConnectionType connType, boolean forceMigrations) { DatasourceConfig.initialize(connType.label); List loadedMigrationFiles = getServerMigrationFiles(connType); - MigrationWorkflow workflow = new MigrationWorkflow(jdbi, loadedMigrationFiles, ignoreFileChecksum); + MigrationWorkflow workflow = new MigrationWorkflow(jdbi, loadedMigrationFiles, forceMigrations); workflow.runMigrationWorkflows(); }