Raghav Vaidhyanathan
Raghav Vaidhyanathan

Reputation: 905

SQL enddelimiter in Liquibase 3.1 does not seem to work

I have a trigger written like below

create or replace trigger departments_bi before insert on departments_test
for each row
when (new.id is null)
begin
 select departments_seq.nextval into :new.id from dual;
end;
/

I am referring to this trigger inside a changeset xml using sqlfile

<?xml version="1.0" encoding="UTF-8" ?>
<databaseChangeLog
  xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
         http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
    <changeSet author="raghav" id="004" runOnChange="true">
     <sqlFile dbms="oracle"
            encoding="ASCII"
            endDelimiter="\n"
            path="Triggers.sql"
            relativeToChangelogFile="true"
            splitStatements="false"
            stripComments="false"/>         
        <rollback>
            drop trigger departments_bi
        </rollback>
    </changeSet>
</databaseChangeLog>

Using Ant UpdateDatabase command am generating a SQL File with all the changes. Am also using exec task to execute the generated SQL with all changes against a target DB.

<updateDatabase
            changeLogFile="${checkout}/Trigger.xml"
            driver="oracle.jdbc.OracleDriver"
            url="jdbc:oracle:thin:@${machineId}:${targetDB_Port}:${targetDB}"
            username="${targetDB_User}"
            password="${targetDB_Password}"
            classpathref="classpath"
            outputFile="${env1.WORKSPACE}/Update_MNT.sql"
    />

    <echo message="Beginning to execute Update_MNT.sql to target DB ${targetDB} using username ${targetDB_user}"/>


    <exec dir="${env1.WORKSPACE}" executable="sqlplus" failonerror="true">
        <arg value="${targetDB_User}/${targetDB_Password}@${tnstargetDB}"/>
        <arg value="@Update_MNT.sql"/>
    </exec> 

The problem am having is with the generated SQL file. Its including the contents of the Trigger.sql file with an extra ; at the end .. So while executing the Update_MNT.sql using exec command. The sqlplus fails because of the additional ; after / in the generated SQL file. How to resolve this issue?

-- Changeset E:/Jenkins_Liquibase_Test/Triggers.xml::004::raghav
create or replace trigger departments_bi before insert on departments_test
for each row
when (new.id is null)
begin
 select departments_seq.nextval into :new.id from dual;
end;
/;

Upvotes: 0

Views: 3277

Answers (1)

bgillis
bgillis

Reputation: 261

There are currently some issues with endDelimiter, formatted SQL changeset and updateSQL command:

Upvotes: 2

Related Questions