Quantcast
Channel: Liquibase Forums
Viewing all 2993 articles
Browse latest View live

Formatted SQL, endDelimiter issue

$
0
0
Hi,

I am very new to the world of SQL and Databases in general so this issue may be me overlooking something very simple,but it has me abit confused all the same!

The issue I am running into is, whenever a SQL script contains multiple semi-colons Liquibase will return "ORA-00900: invalid SQL statement."

Here is a simple example that will return this error.

--liquibase formatted sql

--changeset conor:1.3.0_createproc2
CREATE OR REPLACE PROCEDURE conor_proc2
    IS
    BEGIN
      DBMS_OUTPUT.PUT_LINE('Hello From The Database!');
    END conor_proc2;

--rollback drop procedure conor_proc2;


After abit of playing around and research I found that the endDelimiter was most likely the problem. So when I made this change

--changeset conor:1.3.0_createproc2 endDelimiter:/
CREATE OR REPLACE PROCEDURE conor_proc2
    IS
    BEGIN
      DBMS_OUTPUT.PUT_LINE('Hello From The Database!');
    END conor_proc2;
/
--rollback drop procedure conor_proc2;

It works fine. My understanding it has something to do with the fact that the default of endDelimiter is ';'.

I have no problem with adding an endDelimiter statement to the changeset as long as it is consistent with every changeset. However what I find if I add a endDelimiter parameter to a changeset that has only 1 semi-colon it runs into problems. For example

--changeset conor:1.2.0_createview endDelimiter:/
CREATE OR REPLACE VIEW CONOR_VIEW1 AS SELECT id
FROM conor_table1;
/
--rollback drop view conor_view1;

Will return "ORA-00933: SQL command not properly ended".

However if I remove the semi-colon the statement will executed successfully. Similarly if I don't add the endDelimiter parameter the statement will execute successfully.

--liquibase formatted sql

--changeset conor:1.2.0_createview endDelimiter:/
CREATE OR REPLACE VIEW CONOR_VIEW1 AS SELECT id
FROM conor_table1
/
--rollback drop view conor_view1;

Successfull update.


--changeset conor:1.2.0_createview
CREATE OR REPLACE VIEW CONOR_VIEW1 AS SELECT id
FROM conor_table1;
--rollback drop view conor_view1;

This also works.

I know most likely the issue is to do with my SQL syntax but I am still a bit stumped.

I was hoping someone could shed some light on how exactly does the endDelimiter parameter work. And how I could make using the endDelimiter parameter consistent with simple SQL statements and longer SQL scripts.

Thanks for any help!

Conor.

TL:DR. endDelimiter parameter not needed with SQL statements containing 1 semi-colon. endDelimiter parameter is needed with SQL statements that include multiple semi-colons in formatted SQL.




Re : Extension migration validation issue 3.1.1 -> 3.2.2

$
0
0
Usually we try to keep the checksums consistent from release to release, but there were some large changes in how the parser works in 3.2 that caused some to change due to bugs. 

Do you have an example of the the problem changeSets? Are they ones with your extension, or other ones?

You can tell how the checksums are computed with logLevel=DEBUG. If you run it in 3.1.1 and 3.2.2 you should be able to see what changed in the logic.

Nathan

Re : Liquibase upgradation from 2.1 to 3.1

$
0
0
Yes, there were some changes with the ResourceAccessor API in 3.2. There was logic in XMLChangeLogParser and other locations that really belonged in the ResouceAccessor and there wasn't a good way to change it while preserving compatibility, unfortunately.


What getSourcesAsStream should do is return a set of opened InputStreams for the given path. If just one file corresponds to the path, just return a single-item set. If none match, return null.

Nathan

Re : Braces { in "sql" source not working

$
0
0
It seems to be from Liquibase calling the Oracle driver's connection.nativeSQL(sql) method. The braces get lost from that.

Do you know if there are any issues or work-arounds at the driver level with SQL with braces?

Nathan

Re : What does liquibase validate really do, and when should I use it?

$
0
0
It looks like changeLogSync should run the validate method as part of that processing. 

The error looks like a problem with the checksum changing between when you ran "update" and when you run validate. It's strange that would happen if there were no steps between them. Can you post an example of the problem changeSets? Are they using changelog parameters or anything that could vary?

Nathan

Re : Formatted SQL, endDelimiter issue

$
0
0
The trouble is that the statements coming to the database through the JDBC driver generally need to be sent one at a time, it doesn't do any splitting of statements like the SQL client applications do. Therefore, Liquibase needs to know how to split them and assumes ";" as where to split because that is standard.

However, that doesn't work with procedures and other times you really do need a ";". That is generally a rare case, so I'd suggest only dealing with endDelimiters etc. when you need to.

Even easier than endDelimiter:/ is probabably using splitStatement:false. That will cause liquibase to not do any processing of the SQL in the changeSet and just send it as it is. For most statements, don't bother with splitStatements tag, but if you have a procedure or something that is causing problems, just add splitStatements:false at that point.

Nathan

Re : Braces { in "sql" source not working

$
0
0
Hmmm ... it seemed to me that the {'s are being stripped before the SQL is executed but I could have that wrong as I've only just had a quick glnce at the Liquibase code.

I can't find anything re the drivers and braces other than the standard JDBC escape processing.

Andrew

Re : Extension migration validation issue 3.1.1 -> 3.2.2

$
0
0
Thank you for your hint.
I've done the logging test you suggested.

3.1.1:
[30 Jul 2014 07:14:57,247] main   DEBUG de.medav.dmf.server.base.MARServer.Container.LiquibaseService.liquibase  - liquibase/db-changes.xml: liquibase/db-changes-4.4.xml::4.4.0-4c::tins: Computed checksum for changeAutoincrementValue:[] as 78fb688dce3de0e48421a8933c935ab3

3.2.2:
[30 Jul 2014 07:18:11,518] main   DEBUG de.medav.dmf.server.base.MARServer.Container.LiquibaseService.liquibase  - liquibase/db-changes.xml: liquibase/db-changes-4.4.xml::4.4.0-4c::tins: Computed checksum for changeAutoincrementValue:[
    columnName="Id_Language"
    tableName="mar_language"
] as b28775d91b0587713c6dbfd7b6a1ac9b

the correlating changeset:
<changeSet id="4.4.0-4c" author="tins" dbms="${autoIncrementDBMS}">
    <comment>set autoincrement value to the maximum of column + 1 or the passed minValue</comment>
    <ext:changeAutoincrementValue tableName="mar_language" columnName="Id_Language" minValue="1000000" />
</changeSet>

Seeing the debug log, none XML-attributes of the changeset have been considered for the checksum with the 3.1.1 version of the extension, whereas the string attributes/values are included in the 3.2.2 versions (why are the BigInteger-defined "minValue" attribute and value not included in the checksum of 3.2.2?).

What are the options to fix this now? I won't be able to get direct access to all the databases the changes have been run onto. I'm not sure if the "runOnChange" (or whatever the changeset-option is called) is a good idea either.

As stated in the original post, die extension used has been changed, I attach the 2 change-class versions (as a zip, as only one attachment is allowed).



Re : Configurable DATABASECHANGELOG table name ?

$
0
0
It was not easy to find out the only way I could make it work, so maybe it'll be useful for someone else:

JAVA_OPTS=-Dliquibase.databaseChangeLogTableName=MYTABLE ./liquibase --url=jdbc... --username=u --password=p --changeLogFile=c.xml updateSQL

INSERT INTO test.MYTABLE (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, LIQUIBASE) VALUES ('2', 'user', 'c.xml', NOW(), 5, '7:1d127652402f4036e82f57e2a37cb40c', 'createTable', '', 'EXECUTED', '3.2.2');

diff between current changelog and hibernate entities

$
0
0
Hi,

is it possible to generate a diff changelog between the current changelog xml file and my hibernate/jpa entities without first applying the current changelog to a db and diffing that db with liquibase-hibernate?

as liquibase supports URLs of the type hibernate:spring:com.mycompany.model, could it support something like changelog:classpath:com/mycompany/model/changelog.xml.

I don't know how liquibase works but I suppose it constructs a relational model of its own either based on jdbc metadata or hibernate mappings... so I guess, it could do the same based on changelog files.

Thanks,

Xavier

How can I set the liquibase.properties path ignore the OS?

$
0
0

I want to put my liquibase.properties to another local folder. such as: c:\opt\liquibase\config

And I hope the path can ignore the OS.

So in my pom.xml,

<plugin> <groupId>org.liquibase</groupId> <artifactId>liquibase-maven-plugin</artifactId> <version>3.1.1</version> <configuration> <propertyFile>\opt\liquibase\config</propertyFile> </configuration> </plugin> 

But it doesn't work, I must add the prefix "C:" to path.

Is there any way to set the path but ignore the OS?

Re : How can I set the liquibase.properties path ignore the OS?

Re : Braces { in "sql" source not working

$
0
0
Stepping through, the braces seem to be lost in JdbcConnection with a call to connection.nativeSQL(sql).  Perhaps it is confused with your brace and "\\ ?"  ? If you add some newlines in there, perhaps it may help?

Nathan

Re : diff between current changelog and hibernate entities

$
0
0
In theory it could be done, but it isn't supported yet. The main problem with supporting a changelog "database" is that Liquibase has not SQL parser so if there are any <sql> block we aren't able to track what is happening. Similarly, <modifySql> can keep Liquibase from knowing what is really going on.

It should be able to make it work for a subset of tags, especially. It's a commonly requested feature, but it hasn't been implemented yet. 

Nathan

Re : Extension migration validation issue 3.1.1 -> 3.2.2

$
0
0
So it does look like the 3.2.2 version actually a bugfix that affects the calculation and probably not something we want to revert back to. 

You have a couple options, you can override the generateCheckSum() method to not take the attributes into account anymore, but the better option is probably to use the <validCheckSum> tag in the problem changeSets. You can use <validCheckSum>any</validCheckSum> or use the new checksum you see in the validation error message.

Nathan

Multi-statement rollback: supported?

$
0
0
Is there any support for multi-statement rollback? If so, how is invoked?

In other words, if I have a changeset sql subsection with several statements
  1. <sql splitStatements="true" endDelimiter="~~"> 
  2.   foo ~~ 
  3.   bar ~~ 
  4. </sql>
is there a way I can specify a corresponding
  1. <rollback> 
  2.     undo foo ~~ 
  3.     undo bar ~~ 
  4. </rollback> 
subsection that also contains several statements?

(I recognize I could create separate change sets for each statement but that is awkward in those rare use cases where I want to do a large bulk set of DDL operations at once, in my case as part of the initial build of the application where the initial schema and objects are created from code generated by an ERD diagramming tool which I am pasting into my liquibase script.)

Thanks!
   GregW

Re : Extension migration validation issue 3.1.1 -> 3.2.2

$
0
0
Thank you for your response, the validChecksum tag seems to be a good alternative.

I'd like to discuss an issue that was mentioned in my last post here:

xxx: Computed checksum for changeAutoincrementValue:[
    columnName="xxx"
    tableName="xxx"
] as xxx

was the log entry for one examplary changeSet, the changeSet however requires *3* attributes, the "minValue" field was not considered in the checksum calculation (it is a BigInteger member in constrast to the "columnName" and "tableName" fields, which are strings). Why is this field not considered in the calculation?

Re : diff between current changelog and hibernate entities

$
0
0
Ok, thanks for the information.

As I am not using any sql in my changelog (I'm only using basic refactoring tags), I suppose a small subset of the supported tags would be enough in my case.

This feature would indeed be a great addition to liquibase. Any idea if and when this could be implemented in the future?

Thanks,

Xavier

Re : What does liquibase validate really do, and when should I use it?

$
0
0
Nothing changed in the xml files between step 3 and 4. There were changes before step 1, but I assumed that if both changelogSync and update passed without any warnings, then it means everything is OK. 

To me it looks like validate validates things that update doesn't check. Is it possible? In other words I have some old changesets that have their hash changed, but when I run update it doesn't care, doesn't warn. Only when I run validate it shouts. If this is the case then I wonder what is validate aimed for? Would updateSQL shout when there are hashes changed that would cause update to fail? If yes, then I won't add validate to the pre-test, only updateSQL.

Re : Multi-statement rollback: supported?

$
0
0
Yes, you can have any number of tags inside your rollback block, such as

  1. <rollback>
  2.    <dropColumn...>
  3.    <dropTable..>
  4. </rollback>

or

  1. <rollback>
  2.    <sql>....</sql>
  3.    <sql>....</sql>
  4.    <sql>....</sql>
  5. </rollback>

Nathan
Viewing all 2993 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>