Liquibase - how to generate a changelog for existing database
Asked Answered
P

5

20

I'm trying to use liquibase for generating the changeLog, starting by snapshoting the current state of my database.

Environment details:

  • OS: Windows 7 32 x86,
  • Java JDK 1.7,
  • mysql jdbc driver from MySQL
  • liquibase 2.0.5.

I run the following from command line:

liquibase --driver=com.mysql.jdbc.Driver --changeLogFile=./structure.xml --url="jdbc:mysql://mysql.mysite.com" --username=<myuser> --password=<mypass> generateChangeLog

It runs fine, and generated the output file. But the output file just contains:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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-2.0.xsd"/>

And no tables are created on my database (I was expecting the two tables used for tracking).

What am I missing?


EDITS

Yes, I'm referring to liquibasechanlog and liquibasechangelock tables. I know they should automatically appears on database. My question is why they aren't there. And yes, the provided user have the rights granted for doing such task.

And it is not an empty database. It has near 20 tables, 10 views, data...

Purine answered 16/9, 2012 at 19:7 Comment(4)
By the two tables used for tracking you mean the liquibasechangelog and liquibasechangeloglock? Those aren't actually managed with liquibase.xml but are created automatically for you.Chessy
To expand on what Christoph has asked. Your database contains no application tables and you are asking why the changelog is empty? :-)Eupepsia
I have the same behaviour you described if I don't specify the database in the connection url --url="jdbc:mysql://mysql.mysite.com" but if I add the database name it works fine: --url="jdbc:mysql://mysql.mysite.com/dummy".Eolithic
liquibasechangelog and liquibasechangelock tables are generated if you would apply the generated changelog.xml e.g with liquibase init project --changelog-file=mychangelog.sql --username=myusername - I just hope you have figured that out by now ;)Condorcet
D
16

Just specify the database name with the --url flag like ZNK said:

  --url="jdbc:mysql://mysql.mysite.com/database_name_here"
Darmit answered 20/12, 2013 at 14:50 Comment(0)
M
13

I had faced similar issue when generating changelog xml for postgresql database. I'm posting here if it can help someone. I had to specify --defaultSchemaName in addition to the above params. So in mysql you will have similar option:

The final command will look like :

liquibase --driver=org.postgresql.Driver --changeLogFile=db.changelog.xml  --classpath=postgresql-9.4-1201-jdbc41.jar --url="jdbc:postgresql://localhost:5432/wms"  --username=<USER_NAME> --password=<PASSWD> --defaultSchemaName=<SCHEMA_NAME> generateChangeLog   
Monegasque answered 23/11, 2016 at 16:37 Comment(0)
R
0

This project provides an easy way to generate Liquibase ChangeLogs from Databases https://github.com/HeliasEurodyn/liquibase-maven-plugin

All you do is just defining the databases' connection info and run one command. Just have a look on the README.md file.

The chapter Generate Changelog File from Database explains how to generate a Changelog from a database. While there is also the useful chapter Generate Diff Changelog File from 2 Database differences that explains how to generate a Changelog from the differences 2 databases.

Ronen answered 3/2, 2023 at 14:56 Comment(0)
L
0

With a specified table you can use this liquibase command line as below:

liquibase --changeLogFile=example-changelog.xml --url=jdbc:oracle:thin:@123.45.56.81:1523/trisdevdb --username=maeip --password=maeip --includeSchema=true --schemas=MAEIP --includeObjects=table:table_1 generateChangeLog

Hope to help you!

Lilllie answered 31/10, 2023 at 7:28 Comment(0)
P
0

yes Postgres command is working but objects are only schema specific i can not import things like users, roles, and many more

how to do that

Psilomelane answered 8/7, 2024 at 12:15 Comment(1)
This sounds like a separate question about PostGres, or maybe two.Volatilize

© 2022 - 2025 — McMap. All rights reserved.