Flyway only migrates one of my two configured schemas - java

I have a MySQL 5.7 instance that needs to have two DBs with identical schemas. I'm trying to use flyway with multiple schemas to accomplish this. I'm using the Maven plugin and v5.1.38 of the MySQL connector. Here is my POM config:
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>4.0</version>
<configuration>
<url>jdbc:mysql://192.168.99.100:3306</url>
<user>root</user>
<password>mypassword</password>
<schemas>
<schema>stage</schema>
<schema>public</schema>
</schemas>
</configuration>
</plugin>
Running from an empty DB, this is the output:
[INFO] Database: jdbc:mysql://192.168.99.100:3306 (MySQL 5.7)
[INFO] Successfully validated 3 migrations (execution time 00:00.013s)
[INFO] Creating schema `stage` ...
[INFO] Creating schema `public` ...
[INFO] Creating Metadata table: `stage`.`schema_version`
[INFO] Current version of schema `stage`: 0
[INFO] Migrating schema `stage` to version 1 - initialize schema
[INFO] Migrating schema `stage` to version 2 - seed users
[INFO] Migrating schema `stage` to version 3 - create read items proc
[WARNING] DB: PROCEDURE stage.read_items does not exist (SQL State: 42000 - Error Code: 1305)
[INFO] Successfully applied 3 migrations to schema `stage` (execution time 00:01.824s).
It creates both schemas, but then only runs the migrations for the first one. Am I doing something wrong, or is this a bug in Flyway?
Update:
I've tried to create two executions for the Maven plugin using this config:
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>4.0.1</version>
<executions>
<execution>
<id>migrate-stage</id>
<goals>
<goal>migrate</goal>
</goals>
<configuration>
<url>jdbc:mysql://192.168.99.100:3306/stage</url>
<user>root</user>
<password>password</password>
<schemas>
<schema>stage</schema>
</schemas>
</configuration>
</execution>
<execution>
<id>migrate-pub</id>
<goals>
<goal>migrate</goal>
</goals>
<configuration>
<url>jdbc:mysql://192.168.99.100:3306/public</url>
<user>root</user>
<password>password</password>
<schemas>
<schema>public</schema>
</schemas>
</configuration>
</execution>
</executions>
</plugin>
That gives me the following error:
Unable to connect to the database. Configure the url, user and password!

This seems to be similar to the following : Flyway database migration to multiple schemas
As Mr. Fontaine suggest you should split your schema's for this scenario.
I'm not certain about the correct usage of the schema-tag as I'm new to Flyway myself.
Hope this helps!

It's not the answer I was hoping for, but having tried everything else, I wound up just duplicating the SQL for the 2nd schema, adding a use public; or use stage; before the respective part.

Related

properties-maven-plugin does not set System propertey correctly

I am trying to set a system property in my java project with the maven plugin properties-maven-plugin. Here is my maven code:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<goals>
<goal>set-system-properties</goal>
</goals>
</execution>
<configuration>
<properties>
<property>
<name>system.property.name</name>
<value>${myvalue}</value>
</property>
</properties>
</configuration>
</executions>
</plugin>
...
I can see that is executed in the maven run:
[INFO] --- properties-maven-plugin:1.0.0:set-system-properties (default) # myproject ---
[INFO] Set 1 system property
[INFO]
But in then it is not present at runtime. For example I can not get it with System.getProperty("system.property.name")
I do not understand why. Funny thing is: It worked at one time and then it didn't, without me changing anything.
I also get this strange Eclipse error at the execution-tag: "Plugin execution not covered by lifecycle configuration: ..." but I think this is an Eclipse problem?
The system property is set for the build. After the build is over, it is gone. If you start the built program later, it does not have that system property.

Information_schema not getting generated from jooq for SQL Server

I am using Jooq Trial for generating code from SQL Server database as a poc. I use the below congifuration. However, it is not generating the information schema during compilation.
<plugin>
<groupId>org.jooq.trial</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>${jooq.version}</version>
<executions>
<execution>
<id>jooq-codegen</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<skip>${skip.jooq.generation}</skip>
</configuration>
</execution>
</executions>
<configuration>
<jdbc>
<driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver>
<url>${database.url}</url>
<user></user>
<password></password>
</jdbc>
<generator>
<name>org.jooq.codegen.JavaGenerator</name>
<database>
<name>org.jooq.meta.sqlserver.SQLServerDatabase</name>
<includes>.*</includes>
<excludes></excludes>
<!--<inputSchema></inputSchema> --> <!-- This will generate all schema of db, better to only generate the one
interested in -->
<inputCatalog>scm</inputCatalog>
<schemata>
<schema>
<inputSchema>dbo</inputSchema>
</schema>
<schema>
<inputSchema>INFORMATION_SCHEMA</inputSchema>
</schema>
</schemata>
</database>
<target>
<packageName>org.blackdread.sqltojava.jooq</packageName>
<directory>target/generated-sources/jooq</directory>
</target>
</generator>
</configuration>
<dependencies>
<dependency>
<groupId>org.jooq.trial</groupId>
<artifactId>jooq-meta</artifactId>
<version>${jooq.version}</version>
</dependency>
<dependency>
<groupId>org.jooq.trial</groupId>
<artifactId>jooq-codegen</artifactId>
<version>${jooq.version}</version>
</dependency>
<dependency>
<groupId>org.jooq.trial</groupId>
<artifactId>jooq</artifactId>
<version>${jooq.version}</version>
</dependency>
</dependencies>
</plugin>
Log:
[INFO] Generation finished: scm.dbo: Total: 1.493s, +0.333ms [INFO]
[INFO] Excluding empty schema : scm.INFORMATION_SCHEMA [INFO]
Removing excess files
But information_schema is available as views and it is returning me the necessary information too. I'm using windows authentication and not sa.
For historic reasons, jOOQ-meta's SQLServerDatabase only queries the sys.objects table, not the sys.all_objects table, to reverse engineer your database. This should be changed, of course. I have created a feature request for this:
https://github.com/jOOQ/jOOQ/issues/8827
It has been implemented for jOOQ 3.12
Workaround
In the meantime, you have these options:
Extend the SQLServerDatabase to adapt its queries to fetch rom all_objects, not from objects (this is a lot simpler with the professional edition than with the free trial, as you'll get the sources, and the right to patch the source code)
Use the JDBCDatabase, which queries JDBC's DatabaseMetaData, instead. This should return content from the sys and INFORMATION_SCHEMA schemas as well (but currently doesn't give access to e.g. stored procedures)
Use the generated INFORMATION_SCHEMA tables located in the jOOQ-meta module

Postgres database creation with liquibase

I'm trying to create an empty database using liqubase. I use this approach to do this, but the problem is it doesn't work for me.
I use Postgresql 10 and there are my configurations for maven and liqubase:
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.0.5</version>
<configuration>
<propertyFile>src/main/resources/liquibase/liquibase.properties</propertyFile>
</configuration>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
</plugin>
And my liqubase.properties:
changeLogFile=src/main/resources/liquibase/db.changelog.xml
driver=org.postgresql.Driver
dropFirst=false
url=jdbc:postgresql://localhost:5432/auth?createDatabaseIfNotExist=true
username=postgres
password=root
The error on mvn clean package is:
org.postgresql.util.PSQLException: FATAL: database "auth" does not
exist
Liquibase will not create a database that does not exist at all. I also imagine that the url parameter ?createDatabaseIfNotExist=true that is referenced in the linked question/answer is probably MySql specific.
This is slightly beyond the scope of your question, but you could use liquibase against a Docker postgres instance, and per the docker-library's documentation on ENVIRONMENT VARIABLES, set POSTGRES_DB to "auth" (in your case), and it will create the "auth" db when the docker image launches, with which liquibase can then interact.

Problems building and deploying JAX-RS 2.0 app on WebLogic 12.1.3 with Maven

We have an app running on WebLogic 12.1.3 and we would like to add some JAX-RS 2.0 services to it. We use Maven to build and deploy to the server (with the weblogic-maven-plugin).
To install JAX-RS 2.0 on the server I followed the steps given here:
https://docs.oracle.com/middleware/1213/wls/RESTF/use-jersey20-ri.htm#RESTF297
Everything seems fine. No errors or warnings given during install and the library is visible in the WebLogic Administration Console.
But now when I do "mvn clean install" I'm getting this:
<Nov 23, 2016 2:39:00 PM CET> <Error> <J2EE> <BEA-160187> <weblogic.appc failed to compile the application. Recompile with the -verbose option for more details about the issue.>
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 26.655s
[INFO] Finished at: Wed Nov 23 14:28:21 CET 2016
[INFO] Final Memory: 65M/872M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.oracle.weblogic:weblogic-maven-plugin:12.1.3-0-0:appc (wls-appc) on project our-awesome-app: weblogic.utils.compiler.ToolFailureException: Unresolved WebApp library references defined in weblogic.xml, of module 'our-awesome-app.war' [Extension-Name: jax-rs, Specification-Version: 2, Implementation-Version: 2.5.1, exact-match: false]
[ERROR] at weblogic.servlet.tools.WARModule.initWebAppLibraryManager(WARModule.java:449)
[ERROR] at weblogic.servlet.tools.WARModule.processLibraries(WARModule.java:492)
[ERROR] at weblogic.servlet.tools.WARModule.compile(WARModule.java:274)
[ERROR] at weblogic.application.compiler.ToolsModuleWrapper.compile(ToolsModuleWrapper.java:107)
(goes on and on...)
Compiling with "-verbose" option doesn't render more information btw.
I've googled and searched StackOverflow thoroughly to the best of my ability but I can't seem to find an explanation or a solution to this issue.
Here are (I believe) the relevant parts of our pom.xml:
<plugin>
<!-- This is the configuration for the weblogic-maven-plugin -->
<groupId>com.oracle.weblogic</groupId>
<artifactId>weblogic-maven-plugin</artifactId>
<version>12.1.3-0-0</version>
<configuration>
<middlewareHome>${wls-admin-middleware-home}</middlewareHome>
<adminurl>${wls-admin-url}</adminurl>
<user>${wls-admin-user}</user>
<password>${wls-admin-password}</password>
<source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>
<targets>${wls-admin-targets}</targets>
<name>${project.build.finalName}</name>
<domainHome>${wls-admin-domain-home}</domainHome>
<securityModel>DDOnly</securityModel>
</configuration>
<executions>
<execution>
<id>wls-appc</id>
<phase>package</phase>
<goals>
<goal>appc</goal>
</goals>
<configuration />
</execution>
<execution>
<id>wls-wlst-start-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start-server</goal>
</goals>
<configuration>
</configuration>
</execution>
<execution>
<id>wls-deploy</id>
<phase>pre-integration-test</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<securityModel>DDOnly</securityModel>
</configuration>
</execution>
<execution>
<id>wls-start-app</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start-app</goal>
</goals>
<configuration />
</execution>
</executions>
</plugin>
...
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
and this is in our weblogic.xml:
<wls:library-ref>
<wls:library-name>jax-rs</wls:library-name>
<wls:specification-version>2.0</wls:specification-version>
<wls:implementation-version>2.5.1</wls:implementation-version>
</wls:library-ref>
I'd be very appreciative if anybody with more experience and knowledge of WebLogic could point me towards a solution. I've mainly worked with JBoss and Glassfish previously and this is giving me a huge headache since I've never experienced anything like it with those application servers.
Solved it. The library-ref goes in META-INF/weblogic-application.xml, not in WEB-INF/weblogic.xml.
This happens because those library references are missing when trying to pre-compile the war with wls-appc.
those shared libraries must be in the classpath at compilation time.
You're probably missing the JAX-RS 2.0 library. Follow this to install it : Go into your server , click on install new Application/Library , then select the the path to Oracle-> Middleware-> wlserver-> common-> deployable-libraries and select the JAX-RS 2.0.war library . It worked for me

Manually set Assembly package name, but Install plugin ignores them

I am having a problem with some functionality I need configured.
Here is a part of my POM, where I configured a project to be assembled into two different files: FirstNameProject-VERSION-bin.zip and SecondNameProject-VERSION-bin.zip.
The idea is that I had to maintain those names set, even if the original artefact is common.
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>com.project.my</groupId>
<artifactId>MyGenericProject</artifactId>
<name>Generic Project</name>
<version>2.0.2-SNAPSHOT</version>
...
<build>
<plugins>
....
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>first</id>
<configuration>
<finalName>FirstNameProject-${project.version}-bin</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/resources_first.xml</descriptor>
</descriptors>
</configuration>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
<execution>
<id>second</id>
<configuration>
<finalName>FirstNameProject-${project.version}-bin</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/resources_second.xml</descriptor>
</descriptors>
</configuration>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
This is working properly and in the mvn package logs I can see:
[INFO] --- maven-assembly-plugin:2.2.1:single (first) # MyGenericProject ---
[INFO] Reading assembly descriptor: src/main/assembly/resources_first.xml
[INFO] Building zip: C:\MyPath\MyProject_trunk\target\FirstNameProject-2 .0.2-bin.zip
[INFO]
[INFO] --- maven-assembly-plugin:2.2.1:single (second) # MyGenericProject ---
[INFO] Reading assembly descriptor: src/main/assembly/resources_second.xml
[INFO] Building zip: C:\MyPath\MyProject_trunk\target\SecondNameProject-2.0 .2-bin.zip
The problem is that, at during install, it just reverts to the generic name and install the the rightly named file as the Generic one!
[INFO] --- maven-install-plugin:2.3.1:install (default-install) # MyGenericProject ---
[INFO] Installing C:\MyPath\MyProject_trunk\target\MyGenericProject-2.0.2-SNAPSHOT.jar to C:.m2\repository\com\project\my\MyGenericProject\2.0.2-SNAPSHOT\MyGenericProject-2.0.2-SNAPSHOT.jar
[INFO] Installing C:\MyPath\MyProject_trunk\pom.xml to C:.m2\repository\com\project\my\MyGenericProject\2.0.2-SNAPSHOT\MyGenericProject-2.0.2-SNAPSHOT.pom
[INFO] Installing C:\MyPath\MyProject_trunk\target\FirstNameProject-2.0.2-SNAPSHOT-bin.zip to C:.m2\repository\com\project\my\MyGenericProject\2.0.2-SNAPSHOT\MyGenericProject-2.0.2-SNAPSHOT.zip
I am imagining that this is because the install plugin has no visibility on exactly how the assembly plugin was configured so I ask you: how can I configure the install plugin so that I will end up with FirstNameProject-VERSION-bin.zip and SecondNameProject-VERSION-bin.zip installed in my repository??
I hope I was clear enough,
Thanks
It sounds like Maven is "attaching" the assembly artifact to the project under the default name. The first option is to scour the assembly plugin configuration to see if there's a way to control this. Looking through it myself, I don't see a way to do this. I would have thought it would have used your final name configuration, but if it doesn't, it doesn't.
The workaround I can offer, and I would hope someone can offer something more standard, is to configure the assembly to NOT attach itself.
Next, take the file it creates, the one with the name you want, and use the build-helper plugin to attach the file under the precise coordinates that you want.

Categories