Is it possible to use some kind of variable or property to set the changeset author in a liquibase formatted sql file.
I have tried to set a property in a chnagelog.xml and using the property for the author as show below.
changelog.xml
<?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.8.xsd">
<property name="author" value="my-author"/>
<include file="sql/test_schema.sql"/>
</databaseChangeLog>
And test_schemal.sql
--liquibase formatted sql
--changeset ${author}:1
CREATE SCHEMA IF NOT EXISTS test_schema;
--rollback DROP SCHEMA IF EXISTS test_schema;
However, the author is not set to the author property, "my-author".
I think this could also be done with terraform templating, but is there a way to do this using only liquibase functionality?
Liquibase allows dynamic substitution of properties in changelog files. We can configure multiple properties inside a file and then use them wherever required. In your case, we can just configure property "authorName" with some value and then use it in changelog file using ${authorName} syntax.
Whatever Jorge has mentioned in his answer is correct. Liquibase assigns or prioritizes value for configured property in below order:
As an attribute passed to your liquibase runner.
As a JVM sytem property
As an environment variable
As a CLI attribute if you are running liquibase through command line
In liquibase.properties file
In the parameters block (property element of the DATABASECHANGELOG table)
You can do it as below example code snippet:
<?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.8.xsd">
<changeSet author="${authorName}" id="some-unique-id" dbms="${dbType}" context="some-context">
**My SQL query/ transactional logic goes here**
</changeSet>
</databaseChangeLog>
In liquibase.properties file, I will configure these properties as follows:
authorName=Rakhi
dbType=PostgreSQL
Note: above example is using 2 properties (authorName and dbType). You can use only authorName or even more than that.
If you need help with creating "liquibase.properties" file, visit this link
Cheers!
Using property substitution in your changelog
Liquibase allows you to use different ways to can set property values. Liquibase assigns these values in the order specified below:
As an attribute passed to your Liquibase runner.
As a JVM system property.
As an environment variable.
As a CLI attributes if executed from the command line
As a CLI attributes if executed from the command line
command_line parameter if executed from the command line
In the parameters block (property element) of the DATABASECHANGELOG file itself
Check this liquibase doc
Related
I am using a Gradle Spring project with liquibase. To run liquibase I am running the jar created by compiling the project. I am trying to use the liquibase "includeAll" tag in an xml changelog to run all formatted sql changelog scripts inside a directory I've called includeAllScriptsTest (currently contains only one .sql file named test.sql with one changeset).
If I try to use includeAll in my master db-changelog file, at run time liquibase returns the error: file:///.../conf/db/db.changelog-master.xml/ is not a recognized file type.
In an attempt to get around this, I reference from my db-changelog-master.xml another xml called includeAll-changelog.xml. In this file I have the includeAll tag, below are the contents of this file.
<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="https://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog conf/xsd/dbchangelog-3.8.xsd">
<includeAll path="***/includeAllScriptsTest/" relativeToChangelogFile="true"/>
</databaseChangeLog>
Inside the folder includeAllScriptsTest is a single file called test.sql, with the contents as below:
--liquibase formatted sql
--changeset author:1 dbms:MySQL splitStatements:true endDelimiter://
DROP PROCEDURE IF EXISTS `TESTINCLUDEALL`;//
CREATE PROCEDURE `TESTINCLUDEALL`()
BEGIN
SELECT * FROM TABLE;
END;//
However, this gives me a different error at run time: cvc-elt.1.a: Cannot find the declaration of element 'databaseChangeLog'. I've found online conflicting information regarding whether it is possible to use includeAll with the version of liquibase used by my project. I'm currently using 3.4.1.
cvc-elt.1.a: Cannot find the declaration of element
'databaseChangeLog'
This error is an XML Parsing error, pointing databaseChangeLog is not declared in the xml schema.
May be you can try using following XSD in your changelog:
<?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.8.xsd">
<includeAll path="***/includeAllScriptsTest/" relativeToChangelogFile="true"/>
</databaseChangeLog>
If this still doesn't help, please have a look at few points in answer on this post.
I have some xml data on a MariaDB database and need to do some parsing.
I ve tried using the following code to extraxt some values but no matter what i may try i keep getting null as output
SELECT xmlResponse FROM myDataBase.xmlLogging where id = '1' INTO #xml;
SELECT ExtractValue(#xml, 'node2');
tried also count(node2) to try identify if there is somtheting wrong in my syntaxaccording to this
https://mariadb.com/kb/en/mariadb/documentation/sql-structure-and-commands/functions-and-operators/string-functions/extractvalue/
my xml structure looks like this, with namespacess
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns:SMnamespace xmlns:ns="http://somenamespace.com/WS/">
<ns:Error_spcCode>0</ns:Error_spcCode><ns:Error_spcMessage/>
<ListofData xmlns="http://www.vendor.com/namespeceIO">
<node1>
<node2>text</node2>
<node3>text</node3>
<node4/>
</node1>
</ListofData>
</ns:SMnamespace>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>'
MySQL/MariaDB do not support xml namespaces. They support colons in element names however.
The reason that you do not get the node should be an invalid context in you location path try:
SELECT ExtractValue(#xml, '//node2');
Starting an Xpath expression with // means any node in the document.
I found this reference
http://bugs.mysql.com/bug.php?id=51425
and it seems that this is the case for me as well. The xml that i demonstrated was a simplier version of my actual one that contains quite big strings. So it seems as soon as i reduced the string size, i could get a result.
I am trying to create an event formatter for MySql in WSO2 but am hitting a problem. It appears to be linked to the use of "Composite Key Columns". The error I am getting is:
ERROR - {MysqlEventAdaptorType}
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Window = '15'' at line 1
This only happens if I use a two or more keys in the formatter:
<eventFormatter name="GenericAccountSQLFormatter" statistics="enable"
trace="enable" xmlns="http://wso2.org/carbon/eventformatter">
<from streamName="GenericAccountMeasureStream" version="1.0.0"/>
<mapping customMapping="disable" type="map"/>
<to eventAdaptorName="APCSQLOut" eventAdaptorType="mysql">
<property name="table.name">AccountStats</property>
<property name="update.keys">AccountId,Window</property>
<property name="execution.mode">insert-or-update</property>
</to>
</eventFormatter>
Removing either of the keys (AccountId, Window) then the formatter will send data to MySQL.
Can anyone help?
This is a bug and happens when existing events are sent to a MySQL adaptor with composite keys. Created a jira to track this and the source patch is also available there.
If you don't want to create/apply a patch, then as a quick workaround for now - you can output a composite key from CEP query by concatenating the two attributes and use that as the key in formatter.
UPDATE
The source patch with the fix and build instructions are now available in the jira here. Once built, you need to apply it as a patch to CEP. To apply it as a patch, create a directory named patch0xyz ( xyz are digits as in patch0135, also make xyz > 100) in <CEP>/repository/components/patches and then place the jar inside it. Then you need to rename the jar as org.wso2.carbon.event.output.adaptor.mysql_1.0.1.jar. Then restart the server.
I have a chunk of XML stored as a string in a MySQL database, and need to update one of the attributes using a query.
Given the following string:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<town>
<road name="Main" direction="north"/>
</town>
I would need to change it to update the attribute direction to a different value:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<town>
<road name="Main" direction="east"/>
</town>
Is there an easy way to accomplish this? Thanks in advance!
EDIT: The query would be ran in a SQL script file containing various other upgrade queries, which is called by a piece of code in Java.
Checkout PHP's simple XML
http://www.php.net/manual/en/class.simplexmlelement.php
$xml=new SimpleXMLElement($xml);
print $xml->road->attributes('direction') = 'east';
I ended up overriding the upgrade process for that version. Through Java and JDBC I looped through every row and used JAXB to gain access to the attribute that needed to be changed. I would have preferred to do it with full SQL queries. :(
I am using LINQ to SQL to connect to database from my application. When I am changing environment from production to staging, I can update my connection string in web.config.
But there is one more value I need to update when environment changes. That is database name. In LINQ to SQL designer file, database name is mentioned as attribute like-
[System.Data.Linq.Mapping.DatabaseAttribute(Name="somedbname")]
How can I pick up value of Name dynamically from some config file?
Any help is really appreciated.
as mentioned on the
http://msdn.microsoft.com/en-us/library/system.data.linq.mapping.databaseattribute.name.aspx
"The DatabaseName is used only if the connection itself does not specify the database name."
so you can delete this attribute and all is gonna work fine!
I've used a wrapper class to provide a context along the lines of
public DataContext Context = new DataContext(SqlConnectionString); //much simplified
I fixed this problem by editing the .dbml file outside of Visual Studio (the designer doesn't seem to allow access to the DatabaseAttribute) and getting rid of the name property here:
<Database Name="BadName" Class="OutputDataContext" xmlns="http://schemas.microsoft.com/linqtosql/dbml/2007">
(note that the accepted answer is no longer correct: this attribute was overriding my connection string)