diff --git a/persistence-modules/liquibase/pom.xml b/persistence-modules/liquibase/pom.xml
index a6e0ed85e9..5caf7047ac 100644
--- a/persistence-modules/liquibase/pom.xml
+++ b/persistence-modules/liquibase/pom.xml
@@ -4,13 +4,9 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
liquibase
+ com.baeldung
liquibase
-
-
- com.baeldung
- persistence-modules
- 1.0.0-SNAPSHOT
-
+ 0.0.1-SNAPSHOT
@@ -18,6 +14,38 @@
mysql-connector-j
${mysql-connector-java.version}
+
+ org.springframework.boot
+ spring-boot-starter-web
+ ${spring-boot.version}
+
+
+ org.slf4j
+ slf4j-log4j12
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-data-jpa
+ ${spring-boot.version}
+
+
+ org.liquibase
+ liquibase-core
+ ${liquibase.version}
+
+
+ org.postgresql
+ postgresql
+ ${postgresql.version}
+ runtime
+
+
+ net.lbruun.springboot
+ preliquibase-spring-boot-starter
+ ${preliquibase.version}
+
@@ -32,12 +60,30 @@
liquibase/db-changelog.xml
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ ${maven.compiler.release}
+ --enable-preview
+ ${maven.compiler.source.version}
+ ${maven.compiler.target.version}
+
+
8.2.0
4.25.0
+ 17
+ 17
+ 17
+ 17
+ 3.2.3
+ 4.26.0
+ 42.7.2
+ 1.5.0
\ No newline at end of file
diff --git a/persistence-modules/liquibase/src/main/java/com/baeldung/liquibase/LiquibaseCreateSchemaApplication.java b/persistence-modules/liquibase/src/main/java/com/baeldung/liquibase/LiquibaseCreateSchemaApplication.java
new file mode 100644
index 0000000000..f501cbf82a
--- /dev/null
+++ b/persistence-modules/liquibase/src/main/java/com/baeldung/liquibase/LiquibaseCreateSchemaApplication.java
@@ -0,0 +1,12 @@
+package com.baeldung.liquibase;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class LiquibaseCreateSchemaApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(LiquibaseCreateSchemaApplication.class, args);
+ }
+}
diff --git a/persistence-modules/liquibase/src/main/java/com/baeldung/liquibase/configuration/SchemaInitializer.java b/persistence-modules/liquibase/src/main/java/com/baeldung/liquibase/configuration/SchemaInitializer.java
new file mode 100644
index 0000000000..cf122070c2
--- /dev/null
+++ b/persistence-modules/liquibase/src/main/java/com/baeldung/liquibase/configuration/SchemaInitializer.java
@@ -0,0 +1,31 @@
+package com.baeldung.liquibase.configuration;
+
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.beans.factory.config.BeanPostProcessor;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public class SchemaInitializer implements BeanPostProcessor {
+
+ @Value("${spring.liquibase.default-schema}")
+ private String schemaName;
+
+ @Override
+ public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
+ if (bean instanceof DataSource) {
+ DataSource dataSource = (DataSource) bean;
+ try {
+ Connection conn = dataSource.getConnection();
+ Statement statement = conn.createStatement();
+ statement.execute(String.format("CREATE SCHEMA IF NOT EXISTS %s", schemaName));
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return bean;
+ }
+}
\ No newline at end of file
diff --git a/persistence-modules/liquibase/src/main/java/com/baeldung/liquibase/entity/User.java b/persistence-modules/liquibase/src/main/java/com/baeldung/liquibase/entity/User.java
new file mode 100644
index 0000000000..9beedfb55f
--- /dev/null
+++ b/persistence-modules/liquibase/src/main/java/com/baeldung/liquibase/entity/User.java
@@ -0,0 +1,30 @@
+package com.baeldung.liquibase.entity;
+
+import jakarta.persistence.Entity;
+import jakarta.persistence.Id;
+import jakarta.persistence.Table;
+
+@Entity
+@Table(name = "users")
+public class User {
+
+ @Id
+ private Long id;
+ private String name;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git a/persistence-modules/liquibase/src/main/resources/application.properties b/persistence-modules/liquibase/src/main/resources/application.properties
new file mode 100644
index 0000000000..77740c8e2b
--- /dev/null
+++ b/persistence-modules/liquibase/src/main/resources/application.properties
@@ -0,0 +1,5 @@
+#spring.datasource.url=jdbc:postgresql://some-postgresql-host/some-postgresql-database
+#spring.datasource.username=your-postgresql-username
+#spring.datasource.password=your-postgresql-password
+#spring.liquibase.change-log=classpath:liquibase/changelog.xml
+#spring.liquibase.default-schema=user_management
\ No newline at end of file
diff --git a/persistence-modules/liquibase/src/main/resources/liquibase/changelog-customChangeset.xml b/persistence-modules/liquibase/src/main/resources/liquibase/changelog-customChangeset.xml
new file mode 100644
index 0000000000..e33bc1610a
--- /dev/null
+++ b/persistence-modules/liquibase/src/main/resources/liquibase/changelog-customChangeset.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+ CREATE SCHEMA IF NOT EXISTS user_management;
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/persistence-modules/liquibase/src/main/resources/liquibase/changelog.xml b/persistence-modules/liquibase/src/main/resources/liquibase/changelog.xml
new file mode 100644
index 0000000000..6ae5187a92
--- /dev/null
+++ b/persistence-modules/liquibase/src/main/resources/liquibase/changelog.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/persistence-modules/liquibase/src/main/resources/preliquibase/postgresql.sql b/persistence-modules/liquibase/src/main/resources/preliquibase/postgresql.sql
new file mode 100644
index 0000000000..03aad1cbd4
--- /dev/null
+++ b/persistence-modules/liquibase/src/main/resources/preliquibase/postgresql.sql
@@ -0,0 +1 @@
+CREATE SCHEMA IF NOT EXISTS user_management;
\ No newline at end of file