# Convert DB to Liquibase xml

**URL:** <https://forum.liquibase.org/t/convert-db-to-liquibase-xml/5295>\
**Category:** General Discussion\
**Created:** [April 6, 2021, 10:51am UTC](https://forum.liquibase.org/t/convert-db-to-liquibase-xml/5295 "2021-04-06T10:51:03Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ashad](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@Ashad](https://forum.liquibase.org/u/Ashad)\
**Post date:** [April 6, 2021, 10:51am UTC](https://forum.liquibase.org/t/convert-db-to-liquibase-xml/5295/1 "2021-04-06T10:51:03Z")

</div>

Hi,

I’m testing out liquibase for our dbs. we already have an existing dbs. I want to add our entire db into liquibase xml change log. I understand Liquibase would just work in existing db but I will only have change sets from that point. if I want to create a new db using changelog, I wont be able to without entire db schema and table create change sets in xml.  
is there any way to do it ? like converting sql script to xml ?

Thanks.

---

<div class="post-metadata">

**Author:** ![daryldoak](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.liquibase.org/daryldoak/32/764_2.png) [@daryldoak](https://forum.liquibase.org/u/daryldoak)\
**Post date:** [April 6, 2021, 2:55pm UTC](https://forum.liquibase.org/t/convert-db-to-liquibase-xml/5295/2 "2021-04-06T14:55:29Z")

</div>

You can use the generateChangeLog command to capture the current state of the database into changelog format. Be aware that not all objects types are extracted.

[https://docs.liquibase.com/commands/community/generatechangelog.html](https://docs.liquibase.com/commands/community/generatechangelog.html)

---

<div class="post-metadata">

**Author:** ![Ashad](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@Ashad](https://forum.liquibase.org/u/Ashad)\
**Post date:** [April 7, 2021, 6:43am UTC](https://forum.liquibase.org/t/convert-db-to-liquibase-xml/5295/3 "2021-04-07T06:43:33Z")

</div>

Thanks Dary. I’m testing liquibase with Postgresql database. May i know what are the objects that might not get extracted in postgresql.

---

<div class="post-metadata">

**Author:** ![rakhi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.liquibase.org/rakhi/32/288_2.png) [@rakhi](https://forum.liquibase.org/u/rakhi)\
**Post date:** [April 7, 2021, 9:51am UTC](https://forum.liquibase.org/t/convert-db-to-liquibase-xml/5295/4 "2021-04-07T09:51:10Z")

</div>

Hi @Ashad

I’m not 100% sure but what I know is if you are using Liquibase Pro, most of the objects (almost all) would get covered with generateChangelog. However, if you using Liquibase Open Source then generateChangelog will not extract :

- function
- stored procedure
- trigger

for your PostgreSQL database. There could be more addition of objects to this list.

Hope this helps!

Cheers!

Rakhi Agrawal

---

<div class="post-metadata">

**Author:** ![Ashad](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@Ashad](https://forum.liquibase.org/u/Ashad)\
**Post date:** [April 7, 2021, 10:37am UTC](https://forum.liquibase.org/t/convert-db-to-liquibase-xml/5295/5 "2021-04-07T10:37:32Z")

</div>

Thanks, Rakhi,  
I’m currently using Liquibase Open Source for testing purposes.

---

<div class="post-metadata">

**Author:** ![Ashad](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@Ashad](https://forum.liquibase.org/u/Ashad)\
**Post date:** [April 8, 2021, 6:53am UTC](https://forum.liquibase.org/t/convert-db-to-liquibase-xml/5295/6 "2021-04-08T06:53:27Z")

</div>

Hi @rakhi,

Thanks for your input. Could you please give me some advice what is the right way to use liquibase in my environment. I have a db in postgres and ms sql and there are couple of schemas in db. now when there is a change db, i write sql statement for both db and run them manually in each db. since i believe liquibase can update any db with xml changeset. I’m planning on using xml. Is this a good idea ?  
Is there a way to keep changelog for each sql statement types of create, insert, alter, functions or changelogs for each schemas. what is the right way to do ?

---

<div class="post-metadata">

**Author:** ![rakhi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.liquibase.org/rakhi/32/288_2.png) [@rakhi](https://forum.liquibase.org/u/rakhi)\
**Post date:** [April 8, 2021, 9:57am UTC](https://forum.liquibase.org/t/convert-db-to-liquibase-xml/5295/7 "2021-04-08T09:57:12Z")

</div>

Hi @Ashad

Happy to know you are planning to use Liquibase in your project.

> [@Ashad](#):
>
> Is this a good idea ?

Using XML changelogs and changesets is a good idea. It has a lot of features which allows us to use different functions for DBs. Please follow this link for [Liquibase best practices](https://www.liquibase.org/get-started/best-practices).

> [@Ashad](#):
>
> Is there a way to keep changelog for each sql statement types of create, insert, alter, functions or changelogs for each schemas. what is the right way to do ?

By “a way to keep changelog” if you mean to store them or keep them segregated, then you can have it in different folders.  
For eg: You can create directory structure as follows -

```
- Project
    - masterChangelog.xml
    - changesets
        - create
            - all your create changesets goes here
        - insert
            - all your insert changesets goes here
        - update
            - all your update changesets goes here
        - delete 
            - all your delete changesets goes here

```

To segregate your changesets for each schema you can similarly keep a directory structure of your own type. The way I have used in one of my projects is, I follow a format for naming a changeset file :  
`<operation>_<schema>_<table_name>.xml`  
eg: `insert_mySchema_myTable.xml`

To execute it for different schemas please refer to my answer on this post. Link here : [StackOverFlow Post](https://stackoverflow.com/questions/66982395/apply-migration-in-all-schema-that-i-have-using-liquibase/66985298#66985298)

I hope I got your question right and could answer it.

Please let us know if you have any other queries or if you face any issues at the time of implementation.

Cheers!

Rakhi Agrawal

---

<div class="post-metadata">

**Author:** ![Ashad](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@Ashad](https://forum.liquibase.org/u/Ashad)\
**Post date:** [April 19, 2021, 12:39pm UTC](https://forum.liquibase.org/t/convert-db-to-liquibase-xml/5295/8 "2021-04-19T12:39:17Z")

</div>

Thanks again @rakhi.  
Your answer is really useful.

I have another issue in using liquibase xml format. There is no proper documentation on how Liquibase handle datatypes for different database types. I use mssql and postgres. I looked up to a table in a third party site on liquibase equivalent datatypes in other database. There are certain datatypes do not go accordingly to our need. Is there any way to manipulate this ? for eg:- like clob in Liquibase means varcahr in postgres and nvarchar in mssql.

Thank You.

---

<div class="post-metadata">

**Author:** ![daryldoak](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.liquibase.org/daryldoak/32/764_2.png) [@daryldoak](https://forum.liquibase.org/u/daryldoak)\
**Post date:** [April 19, 2021, 6:12pm UTC](https://forum.liquibase.org/t/convert-db-to-liquibase-xml/5295/9 "2021-04-19T18:12:39Z")

</div>

You can use changelog parameters to control the datatypes used by a dbms. Here is a snippet from [changelog parameters](https://docs.liquibase.com/concepts/changelog-parameters.html).

```
<property name="clob.type" value="clob" dbms="oracle,postgresql"/>  
<property name="clob.type" value="longtext" dbms="mysql"/>  
<property name="table.name" value="tableA"/>  

<changeSet id="1" author="joe">  
     <createTable tableName="${table.name}">  
         <column name="id" type="int"/>  
         <column name="${column1.name}" type="${clob.type}"/>  
         <column name="${column2.name}" type="int"/>  
     </createTable>  
</changeSet>
```
