开发者

Flyway - drop db, create db

I have 2 files: db structure, and db data sql files. (we are not in part of project where we are creating alter files yet).

Is there a way to achieve running these files before build each time if any of them changed using maven?

The only idea I have is to rename the files (bring the version up) after each change to them making sure flyaway will pick it up.

Is there a smarter way, perhaps using API or some other 'trick'开发者_开发百科?

Thanks

--MB


You can use flyway migrate with the following configuration

validationMode=ALL
validationErrorMode=CLEAN

For each sql migration a CRC32 checksum is calculated when the sql script is executed. The validate mechanism checks if the sql migrations in the classpath still has the same checksum as the sql migration already executed in the database.

validationErrorMode=CLEAN is exclusively intended as a convenience for development. Even tough we strongly recommend not to change migration scripts once they have been checked into SCM and run, this provides a way of dealing with this case in a smooth manner. The database will be wiped clean automatically, ensuring that the next migration will bring you back to the state checked into SCM.

This configuration can be used from API, maven plugin or command line.


With newer Flyway, you would use

flyway.setInitOnMigrate(true);
flyway.setCleanOnValidationError(true);
flyway.setValidateOnMigrate(true);

To drop everything if the checksum of the file changes or the version table is missing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜