0

Is there any way to create schema through liquibase script ?

After some research I've found out that we need to include a create schema in change log file.

I'm thinking on similar terms for question asked previously for postgres

Any pointers or help is welcomed.

2 Answers2

0

Found an answer that was mentioned already on stackoverflow.

We can create a fresh database using this URL.

jdbc:mysql://localhost:3306/database_name?createDatabaseIfNotExist=true

createDatabaseIfNotExist this keyword create a fresh new database in your system. If the database does not exist. if exist, skip executing.

0

Your proposed solution to your own question is to separate stuff by database, while your original question was about how to separate stuff using schema. Those are not the same.

If you are using Liquibase in "embedded mode", meaning it is your application code which controls Liquibase execution, not some Maven cmd or Liquibase CLI, then you can have a look at Pre-Liquibase.

Pre-Liquibase attempts to solve the chicken-and-egg problem inherent to Liquibase: It cannot be used to setup its own "home" (Liquibase needs two tables of its own that has to live somewhere), nor can Liquibase ChangeSets be used to create databases or schemas.

This is the problem which Pre-Liquibase solves. It executes some SQL prior to Liquibase itself. For example, you can use it with MySQL to make sure the database exists without fiddling with URL. In such case your Pre-Liquibase SQL script file would look like this:

CREATE DATABASE IF NOT EXISTS my_database_name

You can use Pre-Liquibase if you are using Spring Boot or just Spring Framework without Spring Boot. However, feel free to steal the ideas if you have another tech stack.

(full disclosure: I'm the author of Pre-Libuibase)

lbruun
  • 241
  • 1
  • 6