javamysqlspring-bootliquibaseliquibase-sql

How to schedule mysql event with help of liquibase?


I am using liquibase to manage db for my spring boot application. Now I want to schedule one recurring event on db. But I want to use liquibase for that. My event is as follows:

CREATE EVENT IF NOT EXISTS event12 
ON SCHEDULE EVERY 10 SECOND 
STARTS CURRENT_TIMESTAMP 
DO 
INSERT INTO user_archieve(id,email,name,emptype,salary,time) 
SELECT * FROM user; 

Is there any way so that I can write some code in changelog.xml and create above event on db?


Solution

  • I suppose <sql> tag should do the trick.

        <changeSet id="foo" author="bar">
            <preConditions  onFail="MARK_RAN">
                <sqlCheck>
                    <!-- if you need some checks to perform before execution -->
                </sqlCheck>
            </preConditions>
            <sql>
                CREATE EVENT IF NOT EXISTS event12 
                ON SCHEDULE EVERY 10 SECOND 
                STARTS CURRENT_TIMESTAMP 
                DO 
                INSERT INTO user_archieve(id,email,name,emptype,salary,time) 
                SELECT * FROM user;
            </sql>
        </changeSet>