GithubHelp home page GithubHelp logo

bootique / bootique-liquibase Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 3.0 217 KB

Integration of Liquibase with Bootique

Home Page: http://bootique.io

License: Apache License 2.0

Java 100.00%
bootique liquibase migrate-database migration-tool migrations

bootique-liquibase's Introduction

build test deploy Maven Central

Bootique is a minimally opinionated java launcher and integration technology. It is intended for building container-less runnable Java applications. With Bootique you can create REST services, webapps, jobs, DB migration tasks, etc. and run them as if they were simple commands. No JavaEE container required! Among other things Bootique is an ideal platform for Java microservices, as it allows you to create a fully-functional app with minimal setup.

Each Bootique app is a collection of modules interacting with each other via dependency injection. This GitHub project provides Bootique core. Bootique team also develops a number of important modules. A full list is available here.

Quick Links

Support

You have two options:

  • Open an issue on GitHub with a label of "help wanted" or "question" (or "bug" if you think you found a bug).
  • Post a question on the Bootique forum.

TL;DR

For the impatient, here is how to get started with Bootique:

  • Declare the official module collection:
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>io.bootique.bom</groupId>
            <artifactId>bootique-bom</artifactId>
            <version>3.0-M4</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency> 
    </dependencies>
</dependencyManagement>
  • Include the modules that you need:
<dependencies>
    <dependency>
        <groupId>io.bootique.jersey</groupId>
        <artifactId>bootique-jersey</artifactId>
    </dependency>
    <dependency>
        <groupId>io.bootique.logback</groupId>
        <artifactId>bootique-logback</artifactId>
    </dependency>
</dependencies>
  • Write your app:
package com.foo;

import io.bootique.Bootique;

public class Application {
    public static void main(String[] args) {
        Bootique
            .app(args)
            .autoLoadModules()
            .exec()
            .exit();
    }
}

It has main() method, so you can run it!

For a more detailed tutorial proceed to this link.

Upgrading

See the "maven-central" badge above for the current production version of bootique-bom. When upgrading, don't forget to check upgrade notes specific to your version.

bootique-liquibase's People

Contributors

aarrsseni avatar andrus avatar const1993 avatar dependabot[bot] avatar elena-bondareva avatar irus avatar stariy95 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bootique-liquibase's Issues

Namespace the commands

Liquibase module contributes 5 commands already and will contribute 6th per #15 shortly. This can be confusing in an app that contains Jetty and other commands, as some commands have pretty generic names (like "update" or "validate"). I think we must prefix all of their long names with "lb":

--lb-update
--lb-validate
--lb-changelog-sync
etc...

Short names should be preserved for partial backwards compatibility.

snakeyaml version conflict with Jackson

Liquibase 3.6.3 depends on snakeyaml library version 1.18. Jackson from Bootique core uses snakeyaml 1.24. In certain app dependency combinations this cases MethodNotFound errors, and other unpleasantness. Let's align the versions.

Add config parameter for liquibase.schemaName

Currently it's only possible to specify the defaultSchema (--lb-default-schema command line parameter), which is used for both Liquibase control tables and objects with unqualified names in changelog scripts. But some databases, like SQL Server, don't allow to override current user's default schema. See liquibase.database.core.MSSQLDatabase#setDefaultSchemaName:

@Override
    public void setDefaultSchemaName(String schemaName) {
        if (schemaName != null && !schemaName.equalsIgnoreCase(getConnectionSchemaName())) {
            throw new RuntimeException(String.format(
                "Cannot use default schema name %s on Microsoft SQL Server because the login " +
                    "schema of the current user (%s) is different and MSSQL does not support " +
                    "setting the default schema per session.", schemaName, getConnectionSchemaName()));
        }
        super.setDefaultSchemaName(schemaName);
    }

At the same time, while it is possible to partly work around this issue by using qualified object names in the changelog, the only way to place the control tables (DATABASECHANGELOG*) in a schema other than the user's login chema is to set a system property:

System.setProperty("liquibase.defaultSchema", "myschema");

That's what I'm doing now, but it would be cool to have a dedicated command option just for that. Thanks!

Add "delete-all" command

Often the dev workflow requires wiping out the schema and starting with migrations from scratch. Liquibase standard "delete-all" command should come handy.

Contributing change logs via DI

For database modularity we need migrations to come with modules. So a migration changeset would be built dynamically based on the runtime module collection. We will add a LiquibaseModule.contributeChangeLogs method that will allow to gather a set of module changelogs that will be merged with changelog from YAML and executed by Liquibase.

Changelog Ordering

The ordering of migrations will be non-deterministic and hence by default limited to schemas that don't have relationships between tables belonging to each module. We will add an injectable service that orders available change logs. By overriding this service, you can get access to the full change log collection and can do ordering dynamically. Also using "changeLogs" property in YAML will result in ignoring DI-contributed change logs and will allow for explicit ordering.

In the future we can implement an ordering algorithm based on cross-module dependency analysis.

DI vs YAML

I guess if change logs are set in YAML, we will ignore DI-contributed logs, which is kind of consistent with how Bootique merges collections in other places, by replacing the entire collection.

DropAll does not work in shadowed JAR / upgrade LB to 3.6.3

Here's my gradle.build:

dependencies {
    compile "io.bootique.liquibase:bootique-liquibase:${bootiqueVersion}"
    compile "io.bootique.jdbc:bootique-jdbc-tomcat:${bootiqueVersion}"
    compile "org.postgresql:postgresql:${postgresVersion}"
}

apply plugin: 'com.github.johnrengelman.shadow'

tasks.build.dependsOn tasks.shadowJar

jar {
    manifest {
        attributes 'Main-Class': 'net.manaty.octopusync.db.LiquibaseMain'
    }
}

shadowJar {
    mergeServiceFiles()
}

When running java -jar <path-to-shadowed-jar> --config=db/config/db-dev.yml --lb-drop-all --lb-default-schema=octopus I get the following error:

14:24:08.864 [main] DEBUG liquibase.servicelocator.ServiceLocator - ServiceLocator.findClasses for liquibase.command.LiquibaseCommand
14:24:08.864 [main] DEBUG liquibase.servicelocator.ServiceLocator - ServiceLocator finding classes matching interface liquibase.command.LiquibaseCommand
14:24:08.864 [main] DEBUG liquibase.servicelocator.DefaultPackageScanClassResolver - Searching for implementations of liquibase.command.LiquibaseCommand in packages: [liquibase.change, liquibase.changelog, liquibase.database, liquibase.parser, liquibase.precondition, liquibase.datatype, liquibase.serializer, liquibase.sqlgenerator, liquibase.executor, liquibase.snapshot, liquibase.logging, liquibase.diff, liquibase.structure, liquibase.structurecompare, liquibase.lockservice, liquibase.sdk.database, liquibase.ext]
14:24:08.864 [main] DEBUG liquibase.servicelocator.DefaultPackageScanClassResolver - Searching for: is assignable to LiquibaseCommand in package: liquibase/change
14:24:08.864 [main] DEBUG liquibase.servicelocator.DefaultPackageScanClassResolver - Searching for: is assignable to LiquibaseCommand in package: liquibase/changelog
14:24:08.864 [main] DEBUG liquibase.servicelocator.DefaultPackageScanClassResolver - Searching for: is assignable to LiquibaseCommand in package: liquibase/database
14:24:08.864 [main] DEBUG liquibase.servicelocator.DefaultPackageScanClassResolver - Searching for: is assignable to LiquibaseCommand in package: liquibase/parser
14:24:08.864 [main] DEBUG liquibase.servicelocator.DefaultPackageScanClassResolver - Searching for: is assignable to LiquibaseCommand in package: liquibase/precondition
14:24:08.864 [main] DEBUG liquibase.servicelocator.DefaultPackageScanClassResolver - Searching for: is assignable to LiquibaseCommand in package: liquibase/datatype
14:24:08.864 [main] DEBUG liquibase.servicelocator.DefaultPackageScanClassResolver - Searching for: is assignable to LiquibaseCommand in package: liquibase/serializer
14:24:08.864 [main] DEBUG liquibase.servicelocator.DefaultPackageScanClassResolver - Searching for: is assignable to LiquibaseCommand in package: liquibase/sqlgenerator
14:24:08.864 [main] DEBUG liquibase.servicelocator.DefaultPackageScanClassResolver - Searching for: is assignable to LiquibaseCommand in package: liquibase/executor
14:24:08.864 [main] DEBUG liquibase.servicelocator.DefaultPackageScanClassResolver - Searching for: is assignable to LiquibaseCommand in package: liquibase/snapshot
14:24:08.864 [main] DEBUG liquibase.servicelocator.DefaultPackageScanClassResolver - Searching for: is assignable to LiquibaseCommand in package: liquibase/logging
14:24:08.864 [main] DEBUG liquibase.servicelocator.DefaultPackageScanClassResolver - Searching for: is assignable to LiquibaseCommand in package: liquibase/diff
14:24:08.865 [main] DEBUG liquibase.servicelocator.DefaultPackageScanClassResolver - Searching for: is assignable to LiquibaseCommand in package: liquibase/structure
14:24:08.865 [main] DEBUG liquibase.servicelocator.DefaultPackageScanClassResolver - Searching for: is assignable to LiquibaseCommand in package: liquibase/structurecompare
14:24:08.865 [main] DEBUG liquibase.servicelocator.DefaultPackageScanClassResolver - No classes found in package: liquibase/structurecompare
14:24:08.865 [main] DEBUG liquibase.servicelocator.DefaultPackageScanClassResolver - Searching for: is assignable to LiquibaseCommand in package: liquibase/lockservice
14:24:08.865 [main] DEBUG liquibase.servicelocator.DefaultPackageScanClassResolver - Searching for: is assignable to LiquibaseCommand in package: liquibase/sdk/database
14:24:08.865 [main] DEBUG liquibase.servicelocator.DefaultPackageScanClassResolver - Searching for: is assignable to LiquibaseCommand in package: liquibase/ext
14:24:08.865 [main] DEBUG liquibase.servicelocator.DefaultPackageScanClassResolver - No classes found in package: liquibase/ext
14:24:08.865 [main] DEBUG liquibase.servicelocator.DefaultPackageScanClassResolver - Found: []
Error running command '--config=db/config/db-dev.yml --lb-drop-all --lb-default-schema=octopus'
liquibase.exception.UnexpectedLiquibaseException: Could not find command class for dropAll
        at liquibase.command.CommandFactory.getCommand(CommandFactory.java:60)
        at liquibase.Liquibase.dropAll(Liquibase.java:1146)
        at io.bootique.liquibase.command.DropAllCommand.lambda$run$0(DropAllCommand.java:78)
        at io.bootique.liquibase.LiquibaseRunner.runWithLiquibase(LiquibaseRunner.java:66)
        at io.bootique.liquibase.command.DropAllCommand.run(DropAllCommand.java:76)
        at io.bootique.run.DefaultRunner.run(DefaultRunner.java:43)
        at io.bootique.BQRuntime.run(BQRuntime.java:85)
        at io.bootique.Bootique.exec(Bootique.java:349)
        at net.manaty.octopusync.db.LiquibaseMain.main(LiquibaseMain.java:8)

Other commands (like Update) are not affected and work just fine.
This issue was fixed here: liquibase/liquibase#837 (the commit is present in liquibase-core:3.6.3, which works).

upgrade to liquibase 3.9.0

3.9.0 is available. Let's upgrade...

Preliminary runs show some test failures after the upgrade. Need a closer look...

Bridge Liquibase internal logger to SLF4J

LB logs via its own logger . Should be easy to bridge to our loggers. Perhaps LB module bridges it to SLF, and this will be automatically routed to Logback if Logback is present.

Replace 'changeLog' with 'changeLogs' and map Strings to ResourceFactory

We are doing 2 things here , combined in one task:

  • Adding support for multiple change logs in YAML, which potentially allows to cut down on the number of Liquibase "index" files, as the top-level change log can be described directly in BQ config. Also opens the door for handling modularity along the lines of #10.
  • Replacing Liquibase algorithm for resolving Strings to files with ResourceFactory, so that file paths are handled the same way as they are in other places in Bootique.

Upgrade Notes

'liquibase.changeLog' YAML config property is deprecated, but still supported. When migrating to 'changeLogs', ensure that you rewrite the paths to follow BQ ResourceFactory approach. Specifically, if the resource is on classpath, it needs to have "classpath:" prefix. Otherwise it will be treated as a file path. E.g.:

jdbc:
  test:
    url: jdbc:derby:target/derby/migrations1;create=true
    driver: org.apache.derby.jdbc.EmbeddedDriver
    maxActive: 2

liquibase:
  datasource: test
  changeLogs:
    - classpath:io/bootique/liquibase/changelog_1_2.yml

Same goes for files imported from Liquibase XML or YAML files. "relativeToChangelogFile" property in those is still supported. E.g.:

databaseChangeLog:
  - include:
      file: classpath:io/bootique/liquibase/changeset1.sql
      relativeToChangelogFile: false
  - include:
      file: changeset2.sql
      relativeToChangelogFile: true

Upgrades to latest BQ, JDBC, LB

Upgrading all dependencies. Latest Bootique 0.21, latest bootique-jdbc 0.13 (with test API bug fixes) and latest LB 3.5.3

Upgrade Bootique to 0.12

0.12 version of Bootique includes a completely redone command API. Need to upgrade Job commands to that new API.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.