Liquibase doesn't create or replace view using sqlFile - sql

I have many sql files for creating or replacing views and I want to reuse them through sqlFile in liquibase changelog instead of using createView xml tag.
I use:
<sqlFile path="VI_NAME.sql" relativeToChangelogFile="true"/>
Instead:
<createView viewName="VI_NAME" replaceIfExists="true">
SELECT
...
</createView>
But views not created with this approach!
I debug the way using createView and sql generated by liquibae is the same as in sql file (only schema is added to view name - but this doesn't solve my problem)
PS:
Logging for sqlFile:
SQL in file VI_NAME.sql executed
Liquibase Version: 3.1.1

Use runOnChange attribute.
<changeSet author="liquibase" id="my_view" runOnChange="true"><sqlFile path="VI_NAME.sql"/>
</changeSet>

Related

Why is liquibase changeset not used with liquibase maven plugin update

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. :/

Liquibase - Generating Change Logs

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

Avoiding create databasechangelog table in Liquibase

I want to generate a SQL file to update my database's databasechangelog table with changeLogSyncSQL via command-line. When I generate the SQL file there is a CREATE TABLE [DATABASECHANGELOG] in it, which is alright when I use the SQL file for the first time on a database but what can I do to generate a SQL file without this CREATE TABLE [DATABASECHANGELOG] statement since then there will already be a databasechangelog table in the database. It is no option to run it directly against a database.
My properties file:
driver: com.microsoft.sqlserver.jdbc.SQLServerDriver
classpath: sqljdbc42.jar
url: offline:mssql?outputLiquibaseSql=true
changeLogFile: cl.xml
outputFile: output.sql
I am using liquibase 3.5.5.

liquibase diffchange log issue repeats the change set

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.

Erroneous md5sum failure for liquibase changeSets

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.