Hi there!
This would be probably my last stop before abandoning LB and doing changesets manually.
The goal I have is quite through: I need to evolve the postgresql database with two schemas (public/audit).
Here I'm going to outline my configuration and steps.
The only way I was able to figure out how to separate operations per schema was using the maven profiles.
pom.xml:
The goal I have is quite through: I need to evolve the postgresql database with two schemas (public/audit).
Here I'm going to outline my configuration and steps.
The only way I was able to figure out how to separate operations per schema was using the maven profiles.
pom.xml:
- ...
- <profiles>
- <profile>
- <id>audit</id>
- <properties>
- <ctlg>audit</ctlg>
- </properties>
- </profile>
- <profile>
- <id>public</id>
- <properties>
- <ctlg>public</ctlg>
- </properties>
- </profile>
- <profiles>
- ...
- <plugin>
- <groupId>org.liquibase</groupId>
- <artifactId>liquibase-maven-plugin</artifactId>
- <version>${liquibase.version}</version>
- <configuration>
- <propertyFileWillOverride>false</propertyFileWillOverride>
- <propertyFile>src/main/resources/liquibase/${ctlg}/liquibase.${ctlg}.properties</propertyFile>
- <driver>org.postgresql.Driver</driver>
- <url>jdbc:postgresql://<ip>:5432/vedica_dev</url>
- <username>qwerty</username>
- <password>qwerty</password>
- <diffChangeLogFile>
- src/main/resources/liquibase/${ctlg}/changelog/${maven.build.timestamp}_changelog.xml
- </diffChangeLogFile>
- <defaultSchemaName>
- ${ctlg}
- </defaultSchemaName>
- <changeLogFile>
- src/main/resources/liquibase/${ctlg}/main.xml</changeLogFile>
- <outputChangeLogFile>
- src/main/resources/liquibase/${ctlg}/${ctlg}_init.xml
- </outputChangeLogFile>
- <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
- <referenceUrl>
- hibernate:spring:com.nws.vedica.model?dialect=org.hibernate.dialect.PostgreSQL92Dialect
- </referenceUrl>
- </configuration>
- <dependencies>
- <dependency>
- <groupId>org.liquibase.ext</groupId>
- <artifactId>liquibase-hibernate5</artifactId>
- <version>3.6</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-beans</artifactId>
- <version>${spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework.data</groupId>
- <artifactId>spring-data-jpa</artifactId>
- <version>1.11.1.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>javax.validation</groupId>
- <artifactId>validation-api</artifactId>
- <version>2.0.0.Final</version>
- </dependency>
- </dependencies>
- <executions>
- <execution>
- <id>liquibaseAudit</id>
- <phase>process-resources</phase>
- <configuration>
- <propertyFileWillOverride>true</propertyFileWillOverride>
- <propertyFile>target/classes/liquibase/audit/liquibase.audit.properties</propertyFile>
- </configuration>
- <goals>
- <goal>
- update
- </goal>
- </goals>
- </execution>
- <execution>
- <id>liquibasePublic</id>
- <phase>process-resources</phase>
- <configuration>
- <propertyFileWillOverride>true</propertyFileWillOverride>
- <propertyFile>target/classes/liquibase/public/liquibase.public.properties</propertyFile>
- </configuration>
- <goals>
- <goal>update</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- ...
- driver=org.postgresql.Driver
- defaultSchemaName=audit
- outputChangeLogFile=target/classes/liquibase/audit/audit_init.xml
- url=jdbc:postgresql://212.89.239.181:5432/vedica_dev
- changeLogFile=target/classes/liquibase/audit/main.xml
liquibase.public.properties:
- driver=org.postgresql.Driver
- defaultSchemaName=public
- outputChangeLogFile=target/classes/liquibase/audit/audit_init.xml
- url=jdbc:postgresql://212.89.239.181:5432/vedica_dev
- changeLogFile=target/classes/liquibase/audit/main.xml
First I have generated changeLog to describe current state of the database/schema with:
- mvn liquibase:generateChangeLog -P audit
That has generated 'audit_init.xml' which looks fine. It contains table definitions, constraints about the audit schema. I have included this one in
main.xml:
- <databaseChangeLog
- xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
- http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
- <include file="target/classes/liquibase/audit/audit_init.xml" />
- </databaseChangeLog>
The path is of the 'target' dir because I want maven to execute update upon the build (process-resources phase).
So with this setup, when I run LB with 'mvn liquibase:<goal>' it should use the configuration from the pom.xml file and maven's build phases should use configurations defined in .properties files. That's because I set 'propertyFileWillOverride' (for maven to be able to find files while performing process-resources).
Now, when I run 'mvn liquibase:diff -P audit' it generates changelog of the public schema anyway. So when I run update I end up with two schemas mixed together.
I think I should have all set for distinguishing those two schemas in place.
Even the command outputs this:
So with this setup, when I run LB with 'mvn liquibase:<goal>' it should use the configuration from the pom.xml file and maven's build phases should use configurations defined in .properties files. That's because I set 'propertyFileWillOverride' (for maven to be able to find files while performing process-resources).
Now, when I run 'mvn liquibase:diff -P audit' it generates changelog of the public schema anyway. So when I run update I end up with two schemas mixed together.
I think I should have all set for distinguishing those two schemas in place.
Even the command outputs this:
- [INFO] Performing Diff on database vedic @ jdbc:postgresql://212.89.239.181:5432/vedica_dev (Default Schema: audit)
Please point out what am I doing wrong or whether my expectations are over the top or if this possibly can be a bug.
I believe there is a way of achieving this cause Liquibase is pretty widely adopted.
Thanks for your responses!
I believe there is a way of achieving this cause Liquibase is pretty widely adopted.
Thanks for your responses!