Hi I am facing one issue with diffChangelog.I have performed diffchangelog between two MSSQL databases I got list of change sets.I got following
changeSet author="deekshith (generated)" id="1415884590690-1734">
modifyDataType columnName="lingo_id" newDataType="char(36)" tableName="lingo"/>
addNotNullConstraint columnDataType="char(36)" columnName="lingo_id" tableName="lingo"/>
/changeSet
I have update the change sets to respective database and again performed diffChangelog I got same as above again
changeSet author="deekshith (generated)" id="1415884590690-1736">
modifyDataType columnName="lingo_id" newDataType="char(36)" tableName="lingo"/>
addNotNullConstraint columnDataType="char(36)" columnName="lingo_id" tableName="lingo"/>
/changeSet
Please let me know what I am doing wrong
I think you are mis-understanding what the Liquibase diffChangeLog command does. If you are running it between 2 databases, changing the changelog won't alter the output - what the command does is generate a changelog that you could then use with the Liquibase update command to bring the second database in sync with the first. Any changelog you already have isn't used when running the diffChangeLog command.
Related
using liquibase inside a spring boot project in combination with the liquibase maven plugin.
I'v added the following changeset:
<changeSet author="mrx" id="1642181924202-55">
<addColumn tableName="users" >
<column name="email"
type="varchar(255)">
</column>
</addColumn>
</changeSet>
The liquibase properties:
url=jdbc:mysql://db:3306/mydb
username=root
classpath=mysql-connector-java-8.0.12.jar
password=test
ChangeLogFile=liquibaseChangeLog.xml
driver=com.mysql.cj.jdbc.Driver
outputChangeLogFile=src/main/resources/liquibaseChangeLog.xml
diffExcludeObjects=table:ACT_.*
logLevel=finest
diffTypes=data,tables,views,columns,indexes,foreignkeys,primarykeys,uniqueconstraints
in application.yaml of spring boot:
liquibase:
change-log: classpath:liquibaseChangeLog.xml
And then I'm running from intellij the maven liquibase plugin action "update" but the table is not altered and the changelog does not contain the -55 id so it is not used.
The changelog was generated before from an existing DB, this worked and when I delete the whole DB liquibase recreates it. Only cannt add one simple column here by hand.
How can I get this to work? Is my changeset missing some info? (I deleted parameters schema and catalog, seemed like I did not need them and I wouldnt know what to fill in, the id is just the same as the last generated one +1) That the changeset adds actually a simple column like this.
ok, I ran all the time liquibase update and it did not work but after I simply build the project and started the spring boot app, the changelog was applied correctly. :/
I want Liquibase, to generate a changelog, from this DB 'testing'. Is it possible?
I have an existing database already, with its tables and data inside.
jdbc:mysql://localhost:3306/testing
Now, I want Liquibase, to generate a changelog, from this DB 'testing'. Is it possible?
This is my command, but it doesn't work.
liquibase --driver=com.mysql.jdbc.Driver --classpath=C:\mysql-connector-java-5.1.47.jar
--changeLogFile=C:\db.changelog.xml --url="jdbc:mysql://localhost:3306/testing"
--username=root generateChangeLog
I don't use any password.
The error is related to --changeLogFile=C:\db.changelog.xml
I thought, Liquibase will refer to my DB 'testing', and generate changelog, with name 'db.changelog.xml' in folder C.
Which part I'm wrong? Do I miss something?
Or maybe, Liquibase is not intended, to generate changelog, from existing DB?
Or maybe, Liquibase is intended, to generate DB, from changelog only? And not vice versa?
This is possible. You might be having trouble since you are writing to a file in the root of your c: drive. Try c:\temp\changelog instead.
My experience is that liquibase works in increments. So if you run that command on your database, it will produce a file as if everything in the database has to be created in the changelog file (as if starting with a completely empty database).
If you read the text on Liquibase's site regarding this command, it says:
When starting to use Liquibase on an existing database, it is often useful, particularly for testing, to have a way to generate the change log to create the current database schema.
This means that if you:
Execute this command once against your dev database
Run the result against a new database (let's say test)
Run it again on your dev database
Run that file against your test database
You will get a load of errors stating that functions already exist.
I gather that the idea behind this is that you create new entries in the changelog files and executing them against ALL your databases, instead of using other tools and using liquibase for the delta.
Sample entry
<changeSet author="liquibase-docs" id="addColumn-example">
<addColumn catalogName="cat" schemaName="public" tableName="YY">
<column name="xx" type="varchar(255)"/>
</addColumn>
</changeSet>
SQL equivalent
ALTER TABLE yy ADD COLUMN xx INT
I've seen how to rename the DATABASECHANGELOG tables but what I'm looking to do is to have them created in one database for each server and then deploy to the other databases on that server. We are using Liquibase on MSSQL and Sybase databases and executing via command line.
Thoughts?
I've had the same thought before as well. That's just not how it's done at my current shop :)
You're looking for these options:
--liquibaseCatalogName=<name> The name of the catalog with the
liquibase tables
--liquibaseSchemaName=<name> The name of the schema with the
liquibase tables
Doc here: http://www.liquibase.org/documentation/command_line.html.
However, --liquibaseCatalogName is not documented, but it does appear as an option when checking the command line options via liquibase --help. In your case, I believe "Catalog" equates to a Database in MSSQL and Sybase.
I have a situation to handle, i have my liquibase structured as per the best practices recommended. I have the change log xml structured as given below
Master XML
-->Release XML
-->Feature XML
-->changelog XML
In our application group, we run updateSQL to generate the consolidated sql file and get the changes executed through our DBA group.
However, the real problem I have is to execute a common set of sql statements during every iteration. Like
ALTER SESSION SET CURRENT_SCHEMA=APPLNSCHEMA
as the DBA executes the changes as SYSTEM but the target schema is APPLNSCHEMA.
How to include such common repeating statements in Liquibase changelog.
You would be able to write an extension (http://liquibase.org/extensions) that injects it in. If you need to do it per changeLog, it may work best to extend XMLChangeLogParser to automatically create and add a new changeSet that runs the needed SQL.
You could make a changeSet with the attribute 'runAlways' set to true and include the SQL.
As far as I know, there isn't a way to have Liquibase itself do this. I suggest that you wrap Liquibase with your favorite scripting language such that you run a command "generateSQLforThoseCrazyDBAs" that runs Liquibase and then prepends the SQL you need to the output created by Liquibase.
We are using liquibase 1.9.5, but I haven't seen this as a known bug for that version. The short story is we successfully ran liquibase for our 1.0 release, but it errors out complaining about the md5sums of the 1.0 changeSets when trying to run our 1.1 release that has additional changeSets.
We've worked around it in the short term by just nulling out the md5sum column in DATABASECHANGELOG, but I'm wondering if I'm just doing something wrong.
We organize our liquibase as follows:
One master .xml file that we run on every deployment, which just has commands for a separate file for each version of our software (in the correct order)
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9 http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd">
<include file="v1_0.xml" />
<include file="v1_1.xml" />
</databaseChangeLog>
So the first release only included v1_0.xml, and the release we just pushed out included what we have above.
The v1_0.xml file was unchanged between releases, but we got the following error when trying to invoke liquibase for the new release:
SEVERE: Validation Failed:
1 change sets check sum
v1_0.xml::foo_schema::bdeacon::(MD5Sum: ff63b8d1739e6cf1dcaed6a0ef585257)
The changeSet in question:
<changeSet author="bdeacon" id="foo_schema">
<preConditions onFail="MARK_RAN">
<not><tableExists tableName="some_table"/></not>
</preConditions>
<sqlFile path="database/initial/foo-schema.sql" />
</changeSet>
The foo-schema.sql file referred to was also unchanged between releases. (It does the initial creation of our entire database schema for us, which then includes the "some_table" mentioned in the precondition.)
I would hope liquibase isn't expecting us to manually add a validCheckSum element to every changeSet between releases...
You should not need to add a validCheckSum unless the contents of the changeSet or the sql file changes.
Is there anything such as a SVN version number or whitespace/line endings that may be changing in the foo-schema.sql?
You can set “runOnChange” changeSet attribute to true. In that case, whenever any sql file that is referenced by changeset is changed that changeset will be run again and its checksum will be updated. See ChangeSet Check Sums section in liquibase doc. It is especially useful when package/procedure/trigger code is using a statement like "CREATE OR REPLACE" in which case you would not need to precede the calls to sql files with drop statements to avoid "..already exists" errors.