flywaydb

公式サイト:flywaydb.org

プロパティモード::(事前にクラスパスを生成し、移行パターン:ファイル、構成に依存し、自動組立FlywayPropertiesの導入による生産に適していません)

設定スクリプトとスクリプトファイルディレクトリの移行:

クラスパスを生成し、サービスを開始します。スクリプトファイルについて

 

輸入依存度:

        <依存性>
            <のgroupId> org.flywaydb </のgroupId>
            <たartifactId>フライウェイコア</たartifactId>
        </依存>

サービスを再起動し、正常に移行ログを出力します。

2020-02-21 17:47:06.329 [ INFO] [main] org.flywaydb.core.internal.license.VersionPrinter:49 : Flyway Community Edition 6.2.3 by Redgate 
2020-02-21 17:47:07.148 [ INFO] [main] org.flywaydb.core.internal.database.DatabaseFactory:49 : Database: jdbc:mysql://127.0.0.1:3306/springtest (MySQL 5.7) 
2020-02-21 17:47:07.243 [ INFO] [main] org.flywaydb.core.internal.command.DbValidate:49 : Successfully validated 1 migration (execution time 00:00.037s) 
2020-02-21 17:47:07.284 [ INFO] [main] org.flywaydb.core.internal.schemahistory.JdbcTableSchemaHistory:49 : Creating Schema History table `springtest`.`flyway_schema_history` ... 
2020-02-21 17:47:07.369 [ INFO] [main] org.flywaydb.core.internal.command.DbMigrate:49 : Current version of schema `springtest`: << Empty Schema >> 
2020-02-21 17:47:07.379 [ INFO] [main] org.flywaydb.core.internal.command.DbMigrate:49 : Migrating schema `springtest` to version 1 - Create table 
2020-02-21 17:47:07.433 [ INFO] [main] org.flywaydb.core.internal.command.DbMigrate:49 : Successfully applied 1 migration to schema `springtest` (execution time 00:00.083s) 

 

第二の方法:( @BeanカスタムFlywayPropertiesを介して、開始後は、検索パスのSQLスクリプトを指定するには、データベースのマッピングを生成することができます)

@Bean方法:

@ConditionalOnWebApplication
@ConditionalOnProperty(prefix = "event", name = "enabled", havingValue = "true", matchIfMissing = true)
@MapperScan(basePackages = "ik.starriver.log.mapper*")
public class ApplicationAutoConfiguration {

    private final static String DATASOURCE_PREIFX = "spring.datasource";

    private final static Integer SERVER_PORT = 9000; // 0 是操作系统可用随机端口
    private final static String DATABASE_URL = "jdbc:mysql://127.0.0.1:3306/springtest?serverTimezone=UTC";
    private final static String DATABASE_USERNAME = "root";
    private final static String DATABASE_PASSWORD = "123456";
    private final static Integer DATABASE_MAX_TOTAL = 20;
    private final static Integer DATABASE_MAX_IDLE = 5;
    private final static String DATABASE_DRIVER_CLASS_NAME = "com.mysql.cj.jdbc.Driver";
    private final static String DATABASE_VALIDATION_QUERY = "SELECT 1";
    private final static String JPA_DATABASE_PLATFORM = "org.hibernate.dialect.MySQL5InnoDBDialect";
    private final static String SQL_SESSION_FACTORY_BEAN_TYPE_ENUMS_PACKAGE = "ik.starriver.log.enums";
    private final static String SQL_SESSION_FACTORY_BEAN_TYPE_ALIASES_PACKAGE = "ik.starriver.log.entity";
    private final static String HIBERNATE_PROPERTIES_DDLAUTO = "create";  //init schema: create          //validate
    private final static String LOCATION_PATTERN = "classpath*:/mapper*/*.xml";
    //    private final static List<String> FLYWAYDB_LOCATIONS = new ArrayList<>(Collections.singletonList(locations));
    private final static String[] locations = {
            "filesystem:src/main/resources/db/migration",
            "classpath:/db/migration*"
    };
    private final static List<String> FLYWAYDB_LOCATIONS = Arrays.asList(locations);   
    @Bean
    @Primary
    public FlywayProperties flywayProperties() {
        FlywayProperties flywayProperties = new FlywayProperties();
        flywayProperties.setUrl(DATABASE_URL);
        flywayProperties.setUser(DATABASE_USERNAME);
        flywayProperties.setPassword(DATABASE_PASSWORD);
        flywayProperties.setLocations(FLYWAYDB_LOCATIONS);
        flywayProperties.setEnabled(true);
//        flywayProperties.setBaselineOnMigrate(true);
        return flywayProperties;
    }

}

サービスを開始し、成功した移行スクリプトをログ出力します。

2020-02-21 17:55:21.605 [ INFO] [main] org.flywaydb.core.internal.license.VersionPrinter:49 : Flyway Community Edition 6.2.3 by Redgate 
2020-02-21 17:55:21.724 [ WARN] [main] org.flywaydb.core.internal.scanner.classpath.ClassPathScanner:53 : Unable to resolve location classpath:db/migration* 
2020-02-21 17:55:22.596 [ INFO] [main] org.flywaydb.core.internal.database.DatabaseFactory:49 : Database: jdbc:mysql://127.0.0.1:3306/springtest (MySQL 5.7) 
2020-02-21 17:55:22.671 [ INFO] [main] org.flywaydb.core.internal.command.DbValidate:49 : Successfully validated 1 migration (execution time 00:00.031s) 
2020-02-21 17:55:22.711 [ INFO] [main] org.flywaydb.core.internal.schemahistory.JdbcTableSchemaHistory:49 : Creating Schema History table `springtest`.`flyway_schema_history` ... 
2020-02-21 17:55:22.816 [ INFO] [main] org.flywaydb.core.internal.command.DbMigrate:49 : Current version of schema `springtest`: << Empty Schema >> 
2020-02-21 17:55:22.838 [ INFO] [main] org.flywaydb.core.internal.command.DbMigrate:49 : Migrating schema `springtest` to version 1 - Create table 
2020-02-21 17:55:22.939 [ INFO] [main] org.flywaydb.core.internal.command.DbMigrate:49 : Successfully applied 1 migration to schema `springtest` (execution time 00:00.138s) 

PS:

また、この効果を達成することができ、設定ファイルとして提供FlywayProperties

spring:
  flyway:
    enabled: true
    locations: filesystem:src/main/resources/db/migration,classpath:/db/migration
    user: root
    password: 123456
    url: jdbc:mysql://127.0.0.1:3306/springtest?serverTimezone=UTC

 

問題:

歴史の同じバージョンでスクリプトのコマンドのバージョンので、移行スクリプトの実行には至りませんでした。

D:\shen\java\webdevelop\spring\log>mvn flyway:migrate
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< ik.starriver:log >--------------------------
[INFO] Building log 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- flyway-maven-plugin:6.2.3:migrate (default-cli) @ log ---
[INFO] Flyway Community Edition 6.2.3 by Redgate
[INFO] Database: jdbc:mysql://127.0.0.1:3306/springtest (MySQL 5.7)
[INFO] Successfully validated 1 migration (execution time 00:00.045s)
[INFO] Current version of schema `springtest`: 1
[INFO] Schema `springtest` is up to date. No migration necessary.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.777 s
[INFO] Finished at: 2020-02-21T17:32:48+08:00
[INFO] ------------------------------------------------------------------------

 

 

PS:

使用PropertyMapperは、負荷プロファイルクラスのプロパティのプロパティに対応します

private void configureProperties(FluentConfiguration configuration, FlywayProperties properties) {
			PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
			String[] locations = new LocationResolver(configuration.getDataSource())
					.resolveLocations(properties.getLocations()).toArray(new String[0]);
			map.from(locations).to(configuration::locations);
			map.from(properties.getEncoding()).to(configuration::encoding);
			map.from(properties.getConnectRetries()).to(configuration::connectRetries);
			// No method reference for compatibility with Flyway 5.x
			map.from(properties.getDefaultSchema()).to((schema) -> configuration.defaultSchema(schema));
			map.from(properties.getSchemas()).as(StringUtils::toStringArray).to(configuration::schemas);
			map.from(properties.getTable()).to(configuration::table);
			// No method reference for compatibility with Flyway 5.x
			map.from(properties.getTablespace()).whenNonNull().to((tablespace) -> configuration.tablespace(tablespace));
			map.from(properties.getBaselineDescription()).to(configuration::baselineDescription);
			map.from(properties.getBaselineVersion()).to(configuration::baselineVersion);
			map.from(properties.getInstalledBy()).to(configuration::installedBy);
			map.from(properties.getPlaceholders()).to(configuration::placeholders);
			map.from(properties.getPlaceholderPrefix()).to(configuration::placeholderPrefix);
			map.from(properties.getPlaceholderSuffix()).to(configuration::placeholderSuffix);
			map.from(properties.isPlaceholderReplacement()).to(configuration::placeholderReplacement);
			map.from(properties.getSqlMigrationPrefix()).to(configuration::sqlMigrationPrefix);
			map.from(properties.getSqlMigrationSuffixes()).as(StringUtils::toStringArray)
					.to(configuration::sqlMigrationSuffixes);
			map.from(properties.getSqlMigrationSeparator()).to(configuration::sqlMigrationSeparator);
			map.from(properties.getRepeatableSqlMigrationPrefix()).to(configuration::repeatableSqlMigrationPrefix);
			map.from(properties.getTarget()).to(configuration::target);
			map.from(properties.isBaselineOnMigrate()).to(configuration::baselineOnMigrate);
			map.from(properties.isCleanDisabled()).to(configuration::cleanDisabled);
			map.from(properties.isCleanOnValidationError()).to(configuration::cleanOnValidationError);
			map.from(properties.isGroup()).to(configuration::group);
			map.from(properties.isIgnoreMissingMigrations()).to(configuration::ignoreMissingMigrations);
			map.from(properties.isIgnoreIgnoredMigrations()).to(configuration::ignoreIgnoredMigrations);
			map.from(properties.isIgnorePendingMigrations()).to(configuration::ignorePendingMigrations);
			map.from(properties.isIgnoreFutureMigrations()).to(configuration::ignoreFutureMigrations);
			map.from(properties.isMixed()).to(configuration::mixed);
			map.from(properties.isOutOfOrder()).to(configuration::outOfOrder);
			map.from(properties.isSkipDefaultCallbacks()).to(configuration::skipDefaultCallbacks);
			map.from(properties.isSkipDefaultResolvers()).to(configuration::skipDefaultResolvers);
			configureValidateMigrationNaming(configuration, properties.isValidateMigrationNaming());
			map.from(properties.isValidateOnMigrate()).to(configuration::validateOnMigrate);
			// Pro properties
			map.from(properties.getBatch()).whenNonNull().to(configuration::batch);
			map.from(properties.getDryRunOutput()).whenNonNull().to(configuration::dryRunOutput);
			map.from(properties.getErrorOverrides()).whenNonNull().to(configuration::errorOverrides);
			map.from(properties.getLicenseKey()).whenNonNull().to(configuration::licenseKey);
			map.from(properties.getOracleSqlplus()).whenNonNull().to(configuration::oracleSqlplus);
			// No method reference for compatibility with Flyway 5.x
			map.from(properties.getOracleSqlplusWarn()).whenNonNull()
					.to((oracleSqlplusWarn) -> configuration.oracleSqlplusWarn(oracleSqlplusWarn));
			map.from(properties.getStream()).whenNonNull().to(configuration::stream);
			map.from(properties.getUndoSqlMigrationPrefix()).whenNonNull().to(configuration::undoSqlMigrationPrefix);
		}

 

公開された105元の記事 ウォン称賛33 ビュー30000 +

おすすめ

転載: blog.csdn.net/github_38596081/article/details/104431420