0

I am trying to perform a liquibase rollback command on an application

I have my changeset:

<changeSet id="dmsTestSQL" author="ahmed" 
        dbms="mysql">
        <sqlFile path="db/changelog/sql/add.sql"
             encoding="UTF-8"
             splitStatements="true"
             stripComments="true"/>
        <rollback>
            <sqlFile path="db/changelog/sql/rollback.sql"/>
        </rollback>
    </changeSet>

and I have my configuration class:

@Configuration
public class LiquibaseConfiguration {

    @Value("${com.autogravity.dms.liquibase.changelog}")
    private String changelog;

    @Value("${spring.datasource.url}")
    private String url;

    @Value("${spring.datasource.username}")
    private String username;

    @Value("${spring.datasource.password}")
    private String password;

    /*@Value("${liquibase.rollback-file}")
    private String rollback;*/

    @Bean
    public SpringLiquibase liquibase()  {
        SpringLiquibase liquibase = new SpringLiquibase();
        liquibase.setDataSource(dataSource());
        liquibase.setChangeLog(changelog);
        //liquibase.setRollbackFile(new File(rollback));
        return liquibase;
    }

    public MysqlDataSource dataSource() {
        MysqlDataSource ds=new MysqlDataSource();
        ds.setURL(url);
        ds.setUser(username);
        ds.setPassword(password);
        ds.setAutoReconnect(true);
        ds.setCreateDatabaseIfNotExist(true);
        return ds;
    }

}

I also have created mvn plugin in my pom file:

<plugin>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <version>2.0.2</version>
            <executions>
                <execution>
                    <phase>process-resources</phase>
                    <configuration>
                        <tag>${project.version}</tag>
                        <dropFirst>false</dropFirst>
                        <changeLogFile>classpath:/db/changelog/db.changelog.xml</changeLogFile>
                        <driver>com.mysql.jdbc.Driver</driver>
                        <url>jdbc:mysql://localhost:3306/db</url>
                        <username>root</username>
                        <password>test</password>
                    </configuration>
                    <goals>
                        <goal>rollback</goal>
                        <goal>tag</goal>
                    </goals>
                </execution>
            </executions>
        </plugin> 

I try to run command liquibase:rollback -Dliquibase.rollbackTag=1.0 but then I get the error :

Failed to execute goal org.liquibase:liquibase-maven-plugin:2.0.2:rollback (default-cli) on project dealer-microservice: The driver has not been specified either as a parameter or in a properties file. -> [Help 1]

I don't understand the previous error and I tried to search it but found nothing. can I get help in interpreting this error

Muhammad Bekette
  • 1,396
  • 1
  • 24
  • 60
  • Could be a failure to set the property "liquibase.driver". For an example see: http://stackoverflow.com/questions/11131978/how-to-tag-a-changeset-in-liquibase-to-rollback/11145866#11145866 – Mark O'Connor Jan 06 '17 at 00:32
  • Mark, I used the plugin you provided and added a Driver tag to the configuration, however it is still the same error – Muhammad Bekette Jan 06 '17 at 02:11
  • Also checkout [this answer](http://stackoverflow.com/a/18949719/332248) and the comments. Did you put `liquibase.driver` instead of just `driver`? – Jens Jan 06 '17 at 15:42
  • do you mean replase the `com.mysql.jdbc.Driver` with `${liquibase.driver}` where I set the properties with the rest of the maven properties? – Muhammad Bekette Jan 06 '17 at 16:13
  • @Jens now I get this error PM:liquibase: cvc-elt.1: Cannot find the declaration of element 'databaseChangeLog'. – Muhammad Bekette Jan 06 '17 at 17:00
  • I did not realize you are using spring to configure - my fault. I might still be a problem of the driver config but my I am afraid my original idea does not apply... – Jens Jan 06 '17 at 18:14
  • @Jens ok, another inquiry. should the `liquibase:rollback -Dliquibase.rollbackTag=` is that valid command? I mean the rollbackTag is the changeset I want to roll back? or this is different – Muhammad Bekette Jan 06 '17 at 18:18

0 Answers0