- * We typically need to explicitly specify this as migration can often be generated - * when running against H2. - */ - public Platform getPlatform() { - return platform; - } - - /** - * Set the DB platform to generate migration DDL for. - */ - public void setPlatform(Platform platform) { - this.platform = platform; - } - - /** - * Return the path for normal migrations or dbinit migrations. - * - * @param dbinitMigration When true return the path for dbinit migrations. - */ - public String getMigrationPath(boolean dbinitMigration) { - return dbinitMigration ? migrationInitPath : migrationPath; - } - - /** - * Return the resource path for db migrations. - */ - public String getMigrationPath() { - return migrationPath; - } - - /** - * Set the resource path for db migrations. - *
- * The default of "dbmigration" is reasonable in most cases. You may look to set this - * to be something like "dbmigration/myapp" where myapp gives it a unique resource path - * in the case there are multiple Database applications in the single classpath. - *
- */ - public void setMigrationPath(String migrationPath) { - this.migrationPath = migrationPath; - } - - /** - * Return the relative path for the model files (defaults to model). - */ - public String getModelPath() { - return modelPath; - } - - /** - * Set the relative path for the model files. - */ - public void setModelPath(String modelPath) { - this.modelPath = modelPath; - } - - /** - * Return the model suffix (defaults to model.xml) - */ - public String getModelSuffix() { - return modelSuffix; - } - - /** - * Set the model suffix. - */ - public void setModelSuffix(String modelSuffix) { - this.modelSuffix = modelSuffix; - } - - /** - * Return the apply script suffix (defaults to sql). - */ - public String getApplySuffix() { - return applySuffix; - } - - /** - * Set the apply script suffix (defaults to sql). - */ - public void setApplySuffix(String applySuffix) { - this.applySuffix = applySuffix; - } - - /** - * Return the apply prefix. - */ - public String getApplyPrefix() { - return applyPrefix; - } - - /** - * Set the apply prefix. This might be set to "V" for use with FlywayDB. - */ - public void setApplyPrefix(String applyPrefix) { - this.applyPrefix = applyPrefix; - } - - /** - * Return the table name that holds the migration run details - * (used by DB Migration runner only). - */ - public String getMetaTable() { - return metaTable; - } - - /** - * Set the table name that holds the migration run details - * (used by DB Migration runner only). - */ - public void setMetaTable(String metaTable) { - this.metaTable = metaTable; - } - - /** - * Return a comma and equals delimited placeholders that are substituted in SQL scripts when running migration - * (used by DB Migration runner only). - */ - public String getRunPlaceholders() { - // environment properties take precedence - String placeholders = readEnvironment("ddl.migration.placeholders"); - if (placeholders != null) { - return placeholders; - } - return runPlaceholders; - } - - /** - * Set a comma and equals delimited placeholders that are substituted in SQL scripts when running migration - * (used by DB Migration runner only). - */ - public void setRunPlaceholders(String runPlaceholders) { - this.runPlaceholders = runPlaceholders; - } - - /** - * Return a map of placeholder values that are substituted in SQL scripts when running migration - * (used by DB Migration runner only). - */ - public Map- * Value can be a string containing comma delimited list of version numbers. - *
- */ - public void setPatchInsertOn(String patchInsertOn) { - this.patchInsertOn = patchInsertOn; - } - - /** - * Return migration versions that should have their checksum reset and not run. - */ - public String getPatchResetChecksumOn() { - return patchResetChecksumOn; - } - - /** - * Returns a DDL header prepend for each DDL. E.g. for copyright headers - * You can use placeholders like ${version} or ${timestamp} in properties file. - */ - public String getDdlHeader() { - if (ddlHeader != null && !ddlHeader.isEmpty()) { - ddlHeader = replace(ddlHeader, "${version}", EbeanVersion.getVersion()); - ddlHeader = replace(ddlHeader, "${timestamp}", ZonedDateTime.now().format( DateTimeFormatter.ISO_INSTANT )); - } - return ddlHeader; - } - - /** - * Set the header prepended to the DDL. - */ - public void setDdlHeader(String ddlHeader) { - this.ddlHeader = ddlHeader; - } - - /** - * Set migration versions that should have their checksum reset and not run. - *- * Value can be a string containing comma delimited list of version numbers. - *
- */ - public void setPatchResetChecksumOn(String patchResetChecksumOn) { - this.patchResetChecksumOn = patchResetChecksumOn; - } - - /** - * Return true if strict mode is used which includes a check that non-null columns have a default value. - */ - public boolean isStrictMode() { - String envValue = readEnvironment("ddl.migration.strictMode"); - if (!isEmpty(envValue)) { - return Boolean.parseBoolean(envValue.trim()); - } - return strictMode; - } - - /** - * Set to false to turn off strict mode allowing non-null columns to not have a default value. - */ - public void setStrictMode(boolean strictMode) { - this.strictMode = strictMode; - } - - /** - * Return the underlying migration runner configuration allowing for more advanced settings. - */ - public MigrationConfig getRunnerConfig() { - return runnerConfig; - } - - /** - * Load the settings from the PropertiesWrapper. - */ - public void loadSettings(PropertiesWrapper properties, String serverName) { - - migrationPath = properties.get("migration.migrationPath", migrationPath); - migrationInitPath = properties.get("migration.migrationInitPath", migrationInitPath); - modelPath = properties.get("migration.modelPath", modelPath); - applyPrefix = properties.get("migration.applyPrefix", applyPrefix); - applySuffix = properties.get("migration.applySuffix", applySuffix); - modelSuffix = properties.get("migration.modelSuffix", modelSuffix); - - platform = properties.getEnum(Platform.class, "migration.platform", platform); - patchInsertOn = properties.get("migration.patchInsertOn", patchInsertOn); - patchResetChecksumOn = properties.get("migration.patchResetChecksumOn", patchResetChecksumOn); - - runMigration = properties.getBoolean("migration.run", runMigration); - metaTable = properties.get("migration.metaTable", metaTable); - runPlaceholders = properties.get("migration.placeholders", runPlaceholders); - dbSchema = properties.get("migration.dbSchema", dbSchema); - - //Do not set user and pass from "datasource.db.username" - //There is a null test in MigrationRunner::getConnection to handle this - //String adminUser = properties.get("datasource." + serverName + ".username", dbUsername); - String adminUser = properties.get("datasource." + serverName + ".adminusername", dbUsername); - dbUsername = properties.get("migration.dbusername", adminUser); - - //String adminPwd = properties.get("datasource." + serverName + ".password", dbPassword); - String adminPwd = properties.get("datasource." + serverName + ".adminpassword", dbPassword); - dbPassword = properties.get("migration.dbpassword", adminPwd); - ddlHeader = properties.get("ddl.header", ddlHeader); - } - - /** - * Return the system or environment property. - */ - protected String readEnvironment(String key) { - - String val = System.getProperty(key); - if (val == null) { - val = System.getenv(key); - } - return val; - } - - /** - * Return true if the string is null or empty. - */ - protected boolean isEmpty(String val) { - return val == null || val.trim().isEmpty(); - } - - /** - * Create the MigrationRunner to run migrations if necessary. - */ - public MigrationRunner createRunner(ClassLoader classLoader, Properties properties) { - - runnerConfig.setMetaTable(metaTable); - runnerConfig.setApplySuffix(applySuffix); - runnerConfig.setMigrationPath(migrationPath); - runnerConfig.setMigrationInitPath(migrationInitPath); - runnerConfig.setRunPlaceholderMap(runPlaceholderMap); - runnerConfig.setRunPlaceholders(runPlaceholders); - runnerConfig.setDbUsername(getDbUsername()); - runnerConfig.setDbPassword(getDbPassword()); - runnerConfig.setDbSchema(getDbSchema()); - if (defaultDbSchema) { - runnerConfig.setSetCurrentSchema(false); - } - runnerConfig.setClassLoader(classLoader); - if (patchInsertOn != null) { - runnerConfig.setPatchInsertOn(patchInsertOn); - } - if (patchResetChecksumOn != null) { - runnerConfig.setPatchResetChecksumOn(patchResetChecksumOn); - } - if (properties != null) { - runnerConfig.load(properties); - } - return new MigrationRunner(runnerConfig); - } -} diff --git a/ebean-core/pom.xml b/ebean-core/pom.xml index f80758628..4511ccfa9 100644 --- a/ebean-core/pom.xml +++ b/ebean-core/pom.xml @@ -54,11 +54,30 @@