Liquibase not logging change sets in Postgresql Database - liquibase

I am trying to use liquibase for postgresql database versioning and followed the given in official link.
Created a test database and added a tag="baseline" using commandline . This was recorded in the Changelog table.
liquibase --driver= org.postgresql.Driver --classpath=./lib/postgresql-42.2.5.jar --url=jdbc:postgresql://localhost:5432/lpoc --username=postgres --password=emr123 tag=baseline
Successfully tagged postgres#jdbc:postgresql://localhost:5432/lpoc
Liquibase 'tag' Successful
Created a table and added columns into it. This was not recorded as a change set in the Changelog table .
When added a new column to the newly created table, it is not showing as a changeset tag when checked in changelog.xml file and also in changelog table .

Related

Databasechangelog file already exists error in postgres

I tried to setup default schema, it didn't work. I am using postgres db and trying to test it on my local system.
I am not using any application. I am just trying to update db directly using changelog

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.

Trying to add a column (alter a table) through postdeployment scripts and trying to add data into the newly created column throwing error

We use post-deployment scripts to maintain history of the data in the tables. I am trying to add a new column to the existing table through post deployment script. I have written a post-deployment script to add the new column and one more post deployment script to add data into the newly inserted column.I am trying to publish my database then I can see my alter table script before adding data but it throws an error 'Invalid column name 'NewlyAddedColumn'' My question can we alter the schema using post deployment scripts? I tried using Commit command after altering the table in the post deployment but still encountered the same error message. I am running the post-deployment script to add new column before accessing it to insert data.Could some one help me with this issue.
Yes you can. Right-click on the post deployment script, go to the properties and set Build = none. But why do you want to add column in the post script? Why don't you want to add it to the project?

Run a initial Liquibase script

This is my 2nd day using Liquibase.
I have a 'backup' or 'Repositry' with the database that I need to create locally on my PC.
I have looked at the documentation, but Im realy not 100% clear on how to run it.
Ive updated the Liquibase.properties file to reflect the correct paths and username and passwords.
How do you run the update command to generate the tables and test data.
Windows 7
The Liquibase documentation on 'Adding Liquibase to an existing project' is probably the best place to start. Basically, you want to set the properties file so that it refers to the existing 'backup' database, and then run liquibase generateChangeLog
This will connect to the existing database and generate a file that contains the structure of the existing database expressed (typically) in an XML file called a changelog. You then create a new properies file that will connect to your local database and use liquibase update to apply the changelog to the local database and populate the structure. Note that this does not typically transfer the data from the existing database to the new database, just the structure - the tables, keys, indexes, etc. If you want to have test data as well, you can either export that data from the existing database, or you might look into crafting the changesets manually. To export the data, a command like this would be used:
java -jar liquibase.jar --changeLogFile="./data/<insert file name> " --diffTypes="data" generateChangeLog