Reset Embedded H2 database periodically

前端 未结 6 1010
青春惊慌失措
青春惊慌失措 2021-02-01 13:17

I\'m setting up a new version of my application in a demo server and would love to find a way of resetting the database daily. I guess I can always have a cron job executing dro

6条回答
  •  不思量自难忘°
    2021-02-01 13:29

    Thre is special syntax in Spring for database manipulation within unit tests

    @Sql(scripts = "classpath:drop_all.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
    @Sql(scripts = {"classpath:create.sql", "classpath:init.sql"}, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
    public class UnitTest {}
    

    In this example we execute drop_all.sql script (where we dropp all required tables) after every test method. In this example we execute create.sql script (where we create all required tables) and init.sql script (where we init all required tables before each test method.

提交回复
热议问题