# Copy database schema created by liquibase into another database by java code

**URL:** <https://forum.liquibase.org/t/copy-database-schema-created-by-liquibase-into-another-database-by-java-code/4065>\
**Category:** General Discussion\
**Created:** [December 20, 2019, 7:10pm UTC](https://forum.liquibase.org/t/copy-database-schema-created-by-liquibase-into-another-database-by-java-code/4065 "2019-12-20T19:10:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![czetsuya](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@czetsuya](https://forum.liquibase.org/u/czetsuya)\
**Post date:** [December 20, 2019, 7:10pm UTC](https://forum.liquibase.org/t/copy-database-schema-created-by-liquibase-into-another-database-by-java-code/4065/1 "2019-12-20T19:10:00Z")

</div>

Hi,

I have a database A created using liquibase changeset. Now, it’s possible to create another database B and to initialize that database similar to database A schema.

How can that be achieve using liquibase? Basically I want to clone database A into database B, with the same databasechangelogs entries because the database can be updated in real time.

Thanks,

czetsuya

---

<div class="post-metadata">

**Author:** ![un1382561729492r88id](https://avatars.discourse-cdn.com/v4/letter/u/c4cdca/32.png) [@un1382561729492r88id](https://forum.liquibase.org/u/un1382561729492r88id)\
**Post date:** [December 20, 2019, 7:10pm UTC](https://forum.liquibase.org/t/copy-database-schema-created-by-liquibase-into-another-database-by-java-code/4065/2 "2019-12-20T19:10:00Z")

</div>

I saw your question on StackOverflow as well. As the commenters said, it isn’t clear exactly what you are trying to do here. If you have database A and database B, it seems to me you would just run liquibase update command pointing to A, and then run it again pointing to B.&nbsp;

I guess the biggest misunderstanding I have is that 'm not sure what you mean by “the database can be updated in real time” - do you mean that there is some other process that is affecting database A that is not Liquibase?&nbsp;

Steve Donie  
Principal Software Engineer  
Liquibase Community Engagement  
Datical, Inc. [http://www.datical.com/](http://www.datical.com/)

---

<div class="post-metadata">

**Author:** ![czetsuya](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@czetsuya](https://forum.liquibase.org/u/czetsuya)\
**Post date:** [December 20, 2019, 7:10pm UTC](https://forum.liquibase.org/t/copy-database-schema-created-by-liquibase-into-another-database-by-java-code/4065/3 "2019-12-20T19:10:00Z")

</div>

Hi Steve,

Sorry for the confusion I may have cause.

Let me try to explain the workflow:

1. We initialize a new database a schema using liquibase changeset.
2. We can add a new table and field to database a at run-time. Or during the time when the application is running. For example, we add a new table people to the schema of database a, which is not originally in the changeset.
3. Now, we create a new database b.
4. We want to import the schema of database a to b, with people table.

I hope that is clear.

Thanks and Regards,

czetsuya

---

<div class="post-metadata">

**Author:** ![un1382561729492r88id](https://avatars.discourse-cdn.com/v4/letter/u/c4cdca/32.png) [@un1382561729492r88id](https://forum.liquibase.org/u/un1382561729492r88id)\
**Post date:** [December 20, 2019, 7:10pm UTC](https://forum.liquibase.org/t/copy-database-schema-created-by-liquibase-into-another-database-by-java-code/4065/4 "2019-12-20T19:10:00Z")

</div>

OK, I understand. If I was an architect on your project I would suggest that could be a bad design decision, but there is obviously I don’t know about your application and why you are doing that.&nbsp;

Assuming you are committed to that, then here are a couple of ways you might solve it.&nbsp;

1. Use the same ‘real time schema modification’ step you use on A to also modify B.&nbsp;

2. Use the Liquibase diffChangeLog functionality to compare database A to database B and create a changelog that only has the changes between A and B, then use Liquibase update to apply the changes to B. With this technique you would need to embed Liquibase in your application (if you haven’t already done that) and then add some methods to your code to call Liquibase.&nbsp;

Steve Donie  
Principal Software Engineer  
Liquibase Community Engagement  
Datical, Inc. [http://www.datical.com/](http://www.datical.com/)

---

<div class="post-metadata">

**Author:** ![czetsuya](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@czetsuya](https://forum.liquibase.org/u/czetsuya)\
**Post date:** [December 20, 2019, 7:10pm UTC](https://forum.liquibase.org/t/copy-database-schema-created-by-liquibase-into-another-database-by-java-code/4065/5 "2019-12-20T19:10:00Z")

</div>

Hi Steve,

Indeed, I don’t really agree with the design myself but there is a logic for doing so and this is one way of achieving the requirement given the technology and framework we have.

Thanks for the suggestions. I was actually able to solve the issue by exporting a liquibase changelog and executing it to the new data source.

Best Regards,

czetsuya

---

<div class="post-metadata">

**Author:** ![un1382561729492r88id](https://avatars.discourse-cdn.com/v4/letter/u/c4cdca/32.png) [@un1382561729492r88id](https://forum.liquibase.org/u/un1382561729492r88id)\
**Post date:** [December 20, 2019, 7:10pm UTC](https://forum.liquibase.org/t/copy-database-schema-created-by-liquibase-into-another-database-by-java-code/4065/6 "2019-12-20T19:10:00Z")

</div>

Excellent. Glad to hear you got this working.

Steve Donie  
Principal Software Engineer  
Liquibase Community Engagement  
Datical, Inc. [http://www.datical.com/](http://www.datical.com/)
