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

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

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. 

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? 

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

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

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. 

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

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

  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. 

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

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

Excellent. Glad to hear you got this working.

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