Quantcast
Channel: Liquibase Forums
Viewing all articles
Browse latest Browse all 2993

Liquibase for two pg schemas

$
0
0
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:

  1. ...
  2. <profiles>
  3.         <profile>
  4.             <id>audit</id>
  5.             <properties>
  6.                 <ctlg>audit</ctlg>
  7.             </properties>
  8.         </profile>
  9.         <profile>
  10.             <id>public</id>
  11.             <properties>
  12.                 <ctlg>public</ctlg>
  13.             </properties>
  14.         </profile>
  15. <profiles>
  16. ...
  17.             <plugin>
  18.                 <groupId>org.liquibase</groupId>
  19.                 <artifactId>liquibase-maven-plugin</artifactId>
  20.                 <version>${liquibase.version}</version>
  21.                 <configuration>
  22.                     <propertyFileWillOverride>false</propertyFileWillOverride>
  23.                     <propertyFile>src/main/resources/liquibase/${ctlg}/liquibase.${ctlg}.properties</propertyFile>
  24.                     <driver>org.postgresql.Driver</driver>
  25.                     <url>jdbc:postgresql://<ip>:5432/vedica_dev</url>
  26.                     <username>qwerty</username>
  27.                     <password>qwerty</password>
  28.                     <diffChangeLogFile>
  29.                         src/main/resources/liquibase/${ctlg}/changelog/${maven.build.timestamp}_changelog.xml
  30.                     </diffChangeLogFile>
  31.                     <defaultSchemaName>
  32.                         ${ctlg}
  33.                     </defaultSchemaName>
  34.                     <changeLogFile>
  35.                         src/main/resources/liquibase/${ctlg}/main.xml</changeLogFile>
  36.                     <outputChangeLogFile>
  37.                         src/main/resources/liquibase/${ctlg}/${ctlg}_init.xml
  38.                     </outputChangeLogFile>
  39.                     <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
  40.                     <referenceUrl>
  41.                         hibernate:spring:com.nws.vedica.model?dialect=org.hibernate.dialect.PostgreSQL92Dialect
  42.                     </referenceUrl>
  43.                 </configuration>
  44.                 <dependencies>
  45.                     <dependency>
  46.                         <groupId>org.liquibase.ext</groupId>
  47.                         <artifactId>liquibase-hibernate5</artifactId>
  48.                         <version>3.6</version>
  49.                     </dependency>
  50.                     <dependency>
  51.                         <groupId>org.springframework</groupId>
  52.                         <artifactId>spring-beans</artifactId>
  53.                         <version>${spring.version}</version>
  54.                     </dependency>
  55.                     <dependency>
  56.                         <groupId>org.springframework.data</groupId>
  57.                         <artifactId>spring-data-jpa</artifactId>
  58.                         <version>1.11.1.RELEASE</version>
  59.                     </dependency>
  60.                     <dependency>
  61.                         <groupId>javax.validation</groupId>
  62.                         <artifactId>validation-api</artifactId>
  63.                         <version>2.0.0.Final</version>
  64.                     </dependency>
  65.                 </dependencies>

  66.                 <executions>
  67.                     <execution>
  68.                         <id>liquibaseAudit</id>
  69.                         <phase>process-resources</phase>
  70.                         <configuration>
  71.                             <propertyFileWillOverride>true</propertyFileWillOverride>
  72.                             <propertyFile>target/classes/liquibase/audit/liquibase.audit.properties</propertyFile>
  73.                         </configuration>
  74.                         <goals>
  75.                             <goal>
  76.                                 update
  77.                             </goal>
  78.                         </goals>
  79.                     </execution>
  80.                     
  81.                   <execution>
  82.                         <id>liquibasePublic</id>
  83.                         <phase>process-resources</phase>
  84.                         <configuration>
  85.                             <propertyFileWillOverride>true</propertyFileWillOverride>
  86.                             <propertyFile>target/classes/liquibase/public/liquibase.public.properties</propertyFile>
  87.                         </configuration>
  88.                         <goals>
  89.                             <goal>update</goal>
  90.                         </goals>
  91.                     </execution>
  92.                 </executions>
  93.             </plugin>
  94. ...

   liquibase.audit.properties:
  1. driver=org.postgresql.Driver
  2. defaultSchemaName=audit
  3. outputChangeLogFile=target/classes/liquibase/audit/audit_init.xml
  4. url=jdbc:postgresql://212.89.239.181:5432/vedica_dev
  5. changeLogFile=target/classes/liquibase/audit/main.xml
   liquibase.public.properties:
  1. driver=org.postgresql.Driver
  2. defaultSchemaName=public
  3. outputChangeLogFile=target/classes/liquibase/audit/audit_init.xml
  4. url=jdbc:postgresql://212.89.239.181:5432/vedica_dev
  5. changeLogFile=target/classes/liquibase/audit/main.xml

First I have generated changeLog to describe current state of the database/schema with:
  1. 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:

  1. <databaseChangeLog
  2.         xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
  3.         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.         xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
  5.          http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">

  6.     <include file="target/classes/liquibase/audit/audit_init.xml" />

  7. </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:
  1. [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!

Viewing all articles
Browse latest Browse all 2993

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>