How using folder repository to migration flyway - spring-boot

I'm using java 11 and flyway.
I have a doubt, I'm trying to access a repository folder to apply the scripts in the database.
Example: When my application is started, it will check if there are .SQL files inside a specific folder, if there is, it will apply the script in the informed bank and then it will delete this file. I need to do this because I'm going to fetch the script files from an external repository. In the test I'm doing I'm getting the files from the repository and putting them in a folder at temp.
Flyway flyway = Flyway
.configure()
.locations("filesystem:" + "C:\Users\user_name\AppData\Local\Temp\versionamento_flyway\2\19")
.dataSource(databaseUrl, databaseUser, databasePassword)
.baselineOnMigrate(true)
.connectRetries(2)
.load();
MigrateResult result = flyway.migrate();

Related

Jenkins Job - Creating a zip file with war file, appspec.yml and scripts folder

I have created a build with Jenkins for a spring boot application and it is creating a war file.
Now I want to create a second job which should create a zip file with the war file created and appsepc.yml file and a folder "scripts" folder which contains some shell script that the appspec.yml file uses. Can anyone let me know how to do this?
The job name is "Package" so the following is the structure where the different files are.
.jenkins\workspace\Package\target\cpproject.war
.jenkins\workspace\Package\appspec.yml
.jenkins\workspace\Package\scripts\after_install.sh
.jenkins\workspace\Package\scripts\before_install.sh
.jenkins\workspace\Package\scripts\start_server.sh
.jenkins\workspace\Package\scripts\stop_server.sh
Thank you.
See the Maven Assembly Plugin:
The Assembly Plugin for Maven enables developers to combine project output into a single distributable archive that also contains dependencies, modules, site documentation, and other files.
Currently it can create distributions in the following formats:
zip
...

Liquibase databasechangelog table stores relative path if run spring boot and let liquibase do the migration automatically

I know that liquibase will create a databasechangelog to check if one change set has been applied. But if i let the app to run it automatically, the FILENAME column will store the relative path of the changelog file. But if I run mvn liquibase:status, it said my change set had not been applied, the cause is that in liquibase.properties file I defined the path of the changelog as absolute path (i.e changeLogFile=src/main/resources/db/changelog/db-changeLog-master.xml) while for spring boot app automatic migration the path was defined as relative path (spring.liquibase.change-log=classpath:db/changelog/db-changeLog-master.xml) in application.properties file and "db/changelog/db-changeLog-master.xml" was stored in the database. If you do it manually (by running mvn liquibase:update), "src/main/resources/db/changelog/db-changeLog-master.xml" would be stored instead.
How could I solve this problem? Since I wanna have control over the migration (i.e. do the migration manually) or check the status of migration in development environment.
after I changed the property: changeLogFile=/db/changelog/db-changeLog-master.xml, in liquibase.properties, mvn command works as expected: now liquibase consider the path of my changelog to be "db/changelog/db-changeLog-master.xml"

Maven dependency generation

Is there a plugin available for maven which i can use to generate all the dependencies of a project ? For example I have a server folder which contains folders like below
-server
--test1
--test2
--test3
when i run a particular comand from server folder it should generate all the dependency info in the target folder of server. I know if I use dependency:analyze-report it will generate in all the folders target, but I want then all together in the top folder. Please let me know if there is any way.

Spring DAO test (how to specify location of sqlite db file)

I'm using Spring 4 and I've a JUnit test which uses jdbc template to persist data to an sqlite 3 database (which is essentially a file in my case called test.db on the file system). My test works fine and does persist to the database file successfully.
I'm using Maven to build and when I run my Junit test it creates the test.db file in the root folder of the project (i.e. in the same directory where the pom.xml file is). I would like to ensure this file gets created in the target/ directory instead and referenced in there.
Is there a way in a spring test that i can tell spring where to "create" this test.db file?
Any help would be great -
Thanks Ro
Somewhere in one of your files you should have a path variable to the database. This is probably in our JDBC template file. It should look something like this:
DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver");
dataSource.setUrl("jdbc:derby:c:\temp\database\test01;create=true");
http://www.vogella.com/tutorials/SpringJDBC/article.html

How to configure Typesafe Activator *a priori* to use an existing local Maven repository?

(Not found in the Activator documentation)
It seems that it is possible to have Activator also use an existing local Maven repository by adding the following entry (in bold) in file build.sbt:
resolvers += Seq(
"Local Maven Repository" at "file://q:/repositories/maven",
"Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
)
I am not sure it works but anyway, the problem with this approach is that the project structure must already have been created (and therefore a local repository created and automatically populated by downloads), hence my question : is it possible to tell Activator before it creates the project structure that it should use some local Maven repository ?
Thanks in advance for any hint.
Activator makes use of the sbt-launcher. You can use the sbt-launcher to control which repositories sbt makes use of by default for each project and for the launcher itself.
If you'd like to modify the activator launcher itself, unzip the jar file and take a look at the sbt/boot.properties file included. You can use the format outlined at sbt's launcher docs to add your local maven repository to the list.
A simpler option in the future (but not enabled in our current properties file) is the launcher's ability to have an override repository configuration file. See: Sbt's proxy configuration docs. This file would allow you to specify the repositories you wish activator to use by default. We disabled this to ensure the offline repository which activator uses is added by default. However, I'll open a ticket to re-enable this feature. That way, you should be able to just create a ~/.sbt/repositories file with the following contents:
[repositories]
activator-local: file://${activator.local.repository-${activator.home-${user.home}/.activator}/repository}, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
local
maven-local
maven-central
typesafe-releases: http://typesafe.artifactoryonline.com/typesafe/releases
typesafe-ivy-releases: http://typesafe.artifactoryonline.com/typesafe/ivy-releases, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
Note: the ~/.sbt/boot directory will always exist. This is created to ensure that no other process deletes jar files we use while running, so we copy these out of the local cache. If we didn't, you'd see some really fun error messages.

Resources