/** * Convenience method to run the changesets using Liquibase to bring the database up to a * version compatible with the code * * @throws InputRequiredException if the changelog file requires some sort of user input. The * error object will list of the user prompts and type of data for each prompt * @see #executeChangelog(String, Map) */ public static void executeChangelog() throws DatabaseUpdateException, InputRequiredException { executeChangelog(null, null); }
/** * Updates the openmrs database to the latest. This is only needed if using the API alone. <br> * <br> * The typical use-case would be: Try to {@link #startup(String, String, String, Properties)}, * if that fails, call this method to get the database up to speed. * * @param userInput (can be null) responses from the user about needed input * @throws DatabaseUpdateException if an error occurred while updating * @throws InputRequiredException if user input is required * @since 1.5 */ public static void updateDatabase(Map<String, Object> userInput) throws DatabaseUpdateException, InputRequiredException { DatabaseUpdater.executeChangelog(null, userInput); }
/** * Run changesets on database using Liquibase to get the database up to the most recent version * * @param changelog the liquibase changelog file to use (or null to use the default file) * @param userInput nullable map from question to user answer. Used if a call to update(null) * threw an {@link InputRequiredException} * @throws DatabaseUpdateException * @throws InputRequiredException */ public static void executeChangelog(String changelog, Map<String, Object> userInput) throws DatabaseUpdateException, InputRequiredException { log.debug("Executing changelog: " + changelog); executeChangelog(changelog, userInput, null); }
/** * Executes the given changelog file. This file is assumed to be on the classpath. If no file is * given, the default {@link #CHANGE_LOG_FILE} is ran. * * @param changelog The string filename of a liquibase changelog xml file to run * @param userInput nullable map from question to user answer. Used if a call to * executeChangelog(<String>, null) threw an {@link InputRequiredException} * @return A list of messages or warnings generated by the executed changesets * @throws InputRequiredException if the changelog file requires some sort of user input. The * error object will list of the user prompts and type of data for each prompt */ public static List<String> executeChangelog(String changelog, Map<String, Object> userInput, ChangeSetExecutorCallback callback) throws DatabaseUpdateException, InputRequiredException { log.debug("installing the tables into the database"); if (changelog == null) { changelog = CHANGE_LOG_FILE; } try { return executeChangelog(changelog, CONTEXT, userInput, callback, null); } catch (Exception e) { throw new DatabaseUpdateException("There was an error while updating the database to the latest. file: " + changelog + ". Error: " + e.getMessage(), e); } }
List<String> warnings = DatabaseUpdater.executeChangelog(null, null, new PrintingChangeSetExecutorCallback("Updating database tables to latest version "));
DatabaseUpdater.executeChangelog(); } else { throw new DatabaseUpdateException(
setMessage("Executing " + LIQUIBASE_SCHEMA_DATA); setExecutingTask(WizardTask.CREATE_TABLES); DatabaseUpdater.executeChangelog(LIQUIBASE_SCHEMA_DATA, null, new PrintingChangeSetExecutorCallback("OpenMRS schema file")); addExecutedTask(WizardTask.CREATE_TABLES); DatabaseUpdater.executeChangelog(LIQUIBASE_CORE_DATA, null, new PrintingChangeSetExecutorCallback("OpenMRS core data file")); wizardModel.workLog.add("Created database tables and added core data"); setCompletedPercentage(0); setExecutingTask(WizardTask.ADD_DEMO_DATA); DatabaseUpdater.executeChangelog(LIQUIBASE_DEMO_DATA, null, new PrintingChangeSetExecutorCallback("OpenMRS demo patients, users, and forms")); wizardModel.workLog.add("Added demo data"); setCompletedPercentage(0); setExecutingTask(WizardTask.UPDATE_TO_LATEST); DatabaseUpdater.executeChangelog(null, null, new PrintingChangeSetExecutorCallback( "Updating database tables to latest version ")); addExecutedTask(WizardTask.UPDATE_TO_LATEST);
/** * Execute all not run changeSets in liquibase.xml for the given module * * @param module the module being executed on */ private static void runLiquibase(Module module) { ModuleClassLoader moduleClassLoader = ModuleFactory.getModuleClassLoader(module); InputStream inStream = moduleClassLoader.getResourceAsStream(MODULE_CHANGELOG_FILENAME); boolean liquibaseFileExists = (inStream != null); if (liquibaseFileExists) { try { // run liquibase.xml by Liquibase API DatabaseUpdater.executeChangelog(MODULE_CHANGELOG_FILENAME, null, null, null, getModuleClassLoader(module)); } catch (InputRequiredException ire) { // the user would be stepped through the questions returned here. throw new ModuleException("Input during database updates is not yet implemented.", module.getName(), ire); } catch (Exception e) { throw new ModuleException("Unable to update data model using liquibase.xml.", module.getName(), e); } } }