├── .github └── workflows │ └── check.yml ├── .gitignore ├── LICENSE ├── README.md ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src ├── main ├── kotlin │ └── ch │ │ └── ayedo │ │ └── jooqmodelator │ │ ├── core │ │ ├── DockerClientExtensions.kt │ │ ├── HealthCheck.kt │ │ ├── Migration.kt │ │ ├── Modelator.kt │ │ └── configuration │ │ │ ├── Configuration.kt │ │ │ └── DatabaseConfiguration.kt │ │ └── gradle │ │ ├── JooqModelatorExtension.kt │ │ ├── JooqModelatorPlugin.kt │ │ └── JooqModelatorTask.kt └── resources │ └── META-INF │ └── gradle-plugins │ └── ch.ayedo.jooqmodelator.properties └── test ├── kotlin └── ch │ └── ayedo │ └── jooqmodelator │ ├── GradleApplyTest.kt │ └── IntegrationTest.kt └── resources ├── liquibase-yml-migrations └── databaseChangeLog.yml ├── migrations ├── V1__flyway_test.sql └── databaseChangeLog.xml └── migrationsB ├── V2__flyway_test.sql └── add.second.table.xml /.github/workflows/check.yml: -------------------------------------------------------------------------------- 1 | name: Check 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | tags: 8 | - '*' 9 | 10 | pull_request: 11 | branches: 12 | - master 13 | 14 | jobs: 15 | build: 16 | 17 | runs-on: ubuntu-latest 18 | 19 | steps: 20 | - name: Checkout repository 21 | uses: actions/checkout@v1 22 | 23 | - name: Set up JDK 1.11 24 | uses: actions/setup-java@v1 25 | with: 26 | java-version: 1.11 27 | 28 | - name: Cache global .gradle folder 29 | uses: actions/cache@v2 30 | with: 31 | path: ~/.gradle/caches 32 | key: global-gradle-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/*.kt*') }} 33 | restore-keys: | 34 | gradle-cache-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }} 35 | 36 | - name: Check with Gradle 37 | run: ./gradlew check 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # IntelliJ 2 | .idea 3 | *.iml 4 | 5 | .gradle 6 | /build/ 7 | 8 | # Ignore Gradle GUI config 9 | gradle-app.setting 10 | 11 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 12 | !gradle-wrapper.jar 13 | 14 | # Cache of project 15 | .gradletasknamecache 16 | 17 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 18 | # gradle/wrapper/gradle-wrapper.properties 19 | 20 | .DS_Store 21 | 22 | /out/ 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Jooq-Modelator 2 | ============== 3 | 4 | [![GitHub license](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://raw.githubusercontent.com/ayedo/jooq-modelator/master/LICENSE) [![Github Workflow Status](https://github.com/ayedo/jooq-modelator/workflows/Check/badge.svg)](https://github.com/ayedo/jooq-modelator/actions) 5 | 6 | ## Overview 7 | 8 | This gradle plugin generates Jooq metamodel classes from Flyway & Liquibase migration files. It does so by running them against a dockerized database, and then running the Jooq generator against that database. 9 | 10 | It solves the following problems: 11 | 12 | - No need to maintain and run local databases for builds 13 | - You can run migrations against your very own RDMS, as opposed to an in memory H2 in compatibility mode like other plugins do 14 | - The plugin is incremental end-to-end, and only runs if the migrations have changed, or the target metamodel folder has changed 15 | 16 | ## How it works 17 | 18 | The plugin tries to pull the image with a provided tag from the docker store if necessary. It will then create a container of that image, or reuse an existing container. The plugin uses a key to tag the containers it has created. Then the container is started. 19 | 20 | A health check waits for the database inside the container to start. The health check is RDBMs and docker independent, as the plugin sends a SQL statement, and waits for its successful execution. 21 | 22 | When the database is ready, the migrators are run against it. 23 | 24 | After the migrations the jooq-generator is run. 25 | 26 | ## Requirements 27 | 28 | You need to have Docker installed. 29 | 30 | The plugin has been tested with Version 18.06.1-ce-mac73 (26764). 31 | 32 | ## Supported Technologies 33 | 34 | Two migration engines are supported: 35 | 36 | - Flyway (version '6.5.1') 37 | - Liquibase (version '3.10.1') 38 | 39 | __For Liquibase there are limitations:__ 40 | 41 | - You cannot choose the name of your database change log. __It has to be named 'databaseChangeLog'__. The file ending does not matter, and can be any of the supported file types. 42 | - All migration files need be located within the configured migrations folders (see section 'Configuration'). This is required for incremental build support. 43 | 44 | All databases which you can run in a Docker container, and for which a JDBC driver can be provided, are supported. The plugin has been successfully tested with Postgres 9.6, and MariaDB 10.2. 45 | 46 | Due to backwards incompatible changes in the API, __no jooq generator version older than 3.11.0 is currently supported__. 47 | 48 | ## Installation 49 | 50 | Add the following to your *build.gradle* plugin configuration block: 51 | 52 | plugins { 53 | id 'ch.ayedo.jooqmodelator' version '3.9.0' 54 | } 55 | 56 | ## Configuration 57 | 58 | To configure the plugin you need to add two things: 59 | 60 | - A 'jooqModelator' plugin configuration extension (subsection "Plugin Configuration") 61 | - A 'jooqModelatorRuntime' configuration in the dependencies for your database driver (subsection "Database Configuration") 62 | 63 | For example projects please see section "Example Projects". 64 | 65 | ### Plugin Configuration 66 | 67 | Add the following to your build script: 68 | 69 | 70 | jooqModelator { 71 | 72 | // JOOQ RELATED CONFIGURATION 73 | 74 | // The version of the jooq-generator that should be used 75 | // The dependency is added, and loaded dynamically. 76 | // Only versions 3.11.0 and later are supported. 77 | jooqVersion = '3.12.0' // required, this is an example 78 | 79 | // Which edition of the jooq-generator to be used. 80 | // Possible values are: "OSS", "PRO", "PRO_JAVA_6", or "TRIAL". 81 | jooqEdition = 'OSS' // required, this is an example 82 | 83 | // The path to the XML jooq configuration file 84 | jooqConfigPath = '/var/folders/temp/jooqConfig.xml' // required, this is an example 85 | 86 | // The path to where the metamodel will be generated to. 87 | // Important: this needs to be kept in sync with the path configured in the jooqConfig.xml 88 | // the reason it needs to be configured here again is for incremental build support to work 89 | jooqOutputPath = '/var/folders/temp/ch/acme/metamodel' // required, this is an example 90 | 91 | // MIGRATION ENGINE RELATED CONFIGURATION 92 | 93 | // Which migration engine to use. 94 | // Possible values are: 'FLYWAY', or 'LIQUIBASE'. 95 | migrationEngine = 'FLYWAY' // required, this is an example 96 | 97 | // a list of paths to the folders containing the migration files 98 | migrationsPaths = ['/var/folders/temp/migrations'] // required, this is an example 99 | 100 | // DOCKER RELATED CONFIGURATION 101 | 102 | // The tag of the image that will be pulled, and used to create the db container 103 | dockerTag = 'postgres:11.5' // required, this is an example 104 | 105 | // The environment variables to be passed to the docker container 106 | dockerEnv = ['POSTGRES_DB=postgres', 'POSTGRES_USER=postgres', 'POSTGRES_PASSWORD=secret'] // required, this is an example 107 | 108 | // The container port bindings to use on host and container respectively 109 | dockerHostPort = 5432 // required, this is an example 110 | 111 | dockerContainerPort = 5432 // required, this is an example 112 | 113 | // The plugin labels the containers it creates, and uses 114 | // the following labelkey as key to do so. 115 | // Should normally be left to the default 116 | labelKey = 'ch.ayedo.jooqmodelator' // Not required. This is the default 117 | 118 | // HEALTH CHECK RELATED CONFIGURATION 119 | 120 | // How long to wait in between failed retries. In milliseconds. 121 | delayMs = 500 // Not required. This is the default 122 | 123 | // How long to maximally wait for the database to react to the healthcheck. In milliseconds. 124 | maxDurationMs = 20000 // Not required. This is the default 125 | 126 | // The SQL statement to send to the database server as part of the health check. 127 | sql = 'SELECT 1' // Not required. This is the default 128 | } 129 | 130 | ### Database Configuration 131 | 132 | You add your database drivers as follows: 133 | 134 | dependencies { 135 | // Add your JDBC drivers, and generator extensions here 136 | jooqModelatorRuntime('org.postgresql:postgresql:42.2.6') 137 | } 138 | 139 | ### Configuration Changes 140 | 141 | When you change the `dockerTag`, `dockerEnv`, `dockerHostPort`, or `dockerContainerPort` a new container will be created. The old one is not deleted. 142 | 143 | ## Usage 144 | 145 | The plugins adds a task named *generateJooqMetamodel* to your build. 146 | Use it to generate the Jooq metamodel. 147 | 148 | ./gradlew generateJooqMetamodel 149 | 150 | Please note: the first time you run the plugin it might take a long time to download missing docker images. 151 | 152 | ## Example Projects 153 | 154 | ### Flyway 155 | 156 | Postgres: [click here](https://github.com/ayedo/jooq-modelator-examples/tree/flywayPostgres) 157 | 158 | MariaDb: [click here](https://github.com/ayedo/jooq-modelator-examples/tree/flywayMariaDb) 159 | 160 | ### Liquibase 161 | 162 | Postgres: [click here](https://github.com/ayedo/jooq-modelator-examples/tree/liquibasePostgres) 163 | 164 | MariaDb: [click here](https://github.com/ayedo/jooq-modelator-examples/tree/liquibaseMariaDb) 165 | 166 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ayedo/jooq-modelator/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto init 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto init 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :init 68 | @rem Get command-line arguments, handling Windows variants 69 | 70 | if not "%OS%" == "Windows_NT" goto win9xME_args 71 | 72 | :win9xME_args 73 | @rem Slurp the command line arguments. 74 | set CMD_LINE_ARGS= 75 | set _SKIP=2 76 | 77 | :win9xME_args_slurp 78 | if "x%~1" == "x" goto execute 79 | 80 | set CMD_LINE_ARGS=%* 81 | 82 | :execute 83 | @rem Setup the command line 84 | 85 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 86 | 87 | 88 | @rem Execute Gradle 89 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 90 | 91 | :end 92 | @rem End local scope for the variables with windows NT shell 93 | if "%ERRORLEVEL%"=="0" goto mainEnd 94 | 95 | :fail 96 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 97 | rem the _cmd.exe /c_ return code! 98 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 99 | exit /b 1 100 | 101 | :mainEnd 102 | if "%OS%"=="Windows_NT" endlocal 103 | 104 | :omega 105 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'jooqmodelator' 2 | 3 | -------------------------------------------------------------------------------- /src/main/kotlin/ch/ayedo/jooqmodelator/core/DockerClientExtensions.kt: -------------------------------------------------------------------------------- 1 | package ch.ayedo.jooqmodelator.core 2 | 3 | import com.spotify.docker.client.DockerClient 4 | import com.spotify.docker.client.DockerClient.ListContainersParam.allContainers 5 | import com.spotify.docker.client.DockerClient.ListImagesParam.byName 6 | 7 | fun DockerClient.imageExists(tag: String) = this.listImages(byName(tag)).isNotEmpty() 8 | 9 | // like the ".use(...)" extension function on Closable, but for running a container 10 | fun DockerClient.useContainer(containerId: String, fn: () -> T) = 11 | try { 12 | this.restartContainer(containerId) 13 | fn() 14 | } finally { 15 | val info = this.inspectContainer(containerId) 16 | if (info.state().running() == true) { 17 | this.stopContainer(containerId, 10) 18 | } 19 | } 20 | 21 | fun DockerClient.findLabeledContainers(key: String, value: String) = 22 | this.listContainers(allContainers()) 23 | .filter { container -> 24 | container.labels()?.get(key) == value 25 | } -------------------------------------------------------------------------------- /src/main/kotlin/ch/ayedo/jooqmodelator/core/HealthCheck.kt: -------------------------------------------------------------------------------- 1 | package ch.ayedo.jooqmodelator.core 2 | 3 | import ch.ayedo.jooqmodelator.core.configuration.DatabaseConfig 4 | import ch.ayedo.jooqmodelator.core.configuration.HealthCheckConfig 5 | import net.jodah.failsafe.RetryPolicy 6 | import org.flywaydb.core.internal.jdbc.DriverDataSource 7 | import org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection 8 | import java.sql.Connection 9 | import java.time.Duration 10 | 11 | interface HealthChecker { 12 | 13 | /* blocks until the database processes queries */ 14 | fun waitForDatabase() 15 | 16 | companion object { 17 | fun getDefault(databaseConfig: DatabaseConfig, healthCheckConfig: HealthCheckConfig): HealthChecker { 18 | return FlywayDependentHealthChecker(databaseConfig, healthCheckConfig) 19 | } 20 | } 21 | } 22 | 23 | /* uses Flyway's exposed JDBC tooling to connect to the database */ 24 | class FlywayDependentHealthChecker(databaseConfig: DatabaseConfig, healthCheckConfig: HealthCheckConfig) : HealthChecker { 25 | 26 | private val sql = healthCheckConfig.sql 27 | 28 | private val driverDataSource = with(databaseConfig) { 29 | DriverDataSource(Thread.currentThread().contextClassLoader, driver, url, user, password, null) 30 | } 31 | 32 | private val retryPolicy = RetryPolicy().apply { 33 | val (delayMs, maxDurationMs) = healthCheckConfig 34 | 35 | withDelay(Duration.ofMillis(delayMs)) 36 | withMaxDuration(Duration.ofMillis(maxDurationMs)) 37 | } 38 | 39 | @Suppress("RedundantLambdaArrow") 40 | override fun waitForDatabase() { 41 | 42 | net.jodah.failsafe.Failsafe.with(retryPolicy).run { _ -> 43 | 44 | // for some reason 'use' does not work anymore 45 | var connection: Connection? = null 46 | 47 | try { 48 | 49 | connection = openConnection(driverDataSource, 10) 50 | 51 | connection.createStatement().execute(sql) 52 | 53 | } finally { 54 | connection?.close() 55 | } 56 | 57 | } 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /src/main/kotlin/ch/ayedo/jooqmodelator/core/Migration.kt: -------------------------------------------------------------------------------- 1 | package ch.ayedo.jooqmodelator.core 2 | 3 | import ch.ayedo.jooqmodelator.core.configuration.DatabaseConfig 4 | import ch.ayedo.jooqmodelator.core.configuration.MigrationConfig 5 | import ch.ayedo.jooqmodelator.core.configuration.MigrationEngine.FLYWAY 6 | import ch.ayedo.jooqmodelator.core.configuration.MigrationEngine.LIQUIBASE 7 | import liquibase.Contexts 8 | import liquibase.Liquibase 9 | import liquibase.database.DatabaseFactory 10 | import liquibase.database.jvm.JdbcConnection 11 | import liquibase.resource.FileSystemResourceAccessor 12 | import org.flywaydb.core.Flyway 13 | import org.flywaydb.core.internal.jdbc.DriverDataSource 14 | import org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection 15 | import java.io.File 16 | import java.nio.file.Path 17 | 18 | @Suppress("SpellCheckingInspection") 19 | interface Migrator { 20 | 21 | /* deletes all objects in the database */ 22 | fun clean() 23 | 24 | /* applies all migrations to the database */ 25 | fun migrate() 26 | 27 | companion object { 28 | fun fromConfig(migrationConfig: MigrationConfig, databaseConfig: DatabaseConfig) = 29 | when (migrationConfig.engine) { 30 | FLYWAY -> FlywayMigrator(databaseConfig, migrationConfig.migrationsPaths) 31 | LIQUIBASE -> LiquibaseMigrator(databaseConfig, migrationConfig.migrationsPaths) 32 | } 33 | } 34 | } 35 | 36 | class FlywayMigrator(databaseConfig: DatabaseConfig, migrationsPaths: List) : Migrator { 37 | 38 | private val flyway = Flyway.configure().apply { 39 | with(databaseConfig) { 40 | dataSource(url, user, password) 41 | } 42 | 43 | 44 | val fileSystemPaths = migrationsPaths.map({ "filesystem:$it" }).toTypedArray() 45 | 46 | locations(*fileSystemPaths) 47 | }.load() 48 | 49 | override fun clean() { 50 | flyway.clean() 51 | } 52 | 53 | override fun migrate() { 54 | flyway.migrate() 55 | } 56 | 57 | } 58 | 59 | class LiquibaseMigrator(databaseConfig: DatabaseConfig, migrationsPaths: List) : Migrator { 60 | 61 | private val liquibase: Liquibase 62 | 63 | init { 64 | // TODO: not sure whether connection is closed correctly in this migrator 65 | val database = with(databaseConfig) { 66 | // Ugly workaround so that Liquibase uses the contextClassLoader 67 | val flywayDataSource = DriverDataSource(Thread.currentThread().contextClassLoader, driver, url, user, password, null) 68 | val connection = openConnection(flywayDataSource, 10) 69 | DatabaseFactory.getInstance().findCorrectDatabaseImplementation(JdbcConnection(connection)) 70 | } 71 | 72 | val changeLogFiles = migrationsPaths 73 | .map { path -> path.toFile() } 74 | .flatMap { file: File -> 75 | file.listFiles { pathName -> pathName.nameWithoutExtension == "databaseChangeLog" }?.toList() 76 | ?: emptyList() 77 | } 78 | 79 | if (changeLogFiles.isEmpty()) { 80 | throw IllegalStateException("Cannot find liquibase changelog file. It must be named 'databaseChangeLog'.") 81 | } 82 | 83 | if (changeLogFiles.size > 1) { 84 | throw IllegalStateException("More than one file named databaseChangeLog found in migrations folders:\nFiles: ${changeLogFiles.joinToString(prefix = "[", separator = ",", postfix = "]") { it.absolutePath }}") 85 | } 86 | 87 | liquibase = Liquibase(changeLogFiles.first().toString(), FileSystemResourceAccessor(), database) 88 | } 89 | 90 | override fun clean() { 91 | liquibase.dropAll() 92 | } 93 | 94 | override fun migrate() { 95 | val nullContext: Contexts? = null 96 | liquibase.update(nullContext) 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /src/main/kotlin/ch/ayedo/jooqmodelator/core/Modelator.kt: -------------------------------------------------------------------------------- 1 | package ch.ayedo.jooqmodelator.core 2 | 3 | import ch.ayedo.jooqmodelator.core.configuration.Configuration 4 | import ch.ayedo.jooqmodelator.core.configuration.DatabaseConfig 5 | import com.spotify.docker.client.DefaultDockerClient 6 | import org.slf4j.LoggerFactory 7 | 8 | @Suppress("SpellCheckingInspection") 9 | class Modelator(configuration: Configuration) { 10 | 11 | private val log = LoggerFactory.getLogger(Modelator::class.java) 12 | 13 | private val dockerConfig = configuration.dockerConfig 14 | 15 | private val healthCheckConfig = configuration.healthCheckConfig 16 | 17 | private val jooqConfigPath = configuration.jooqConfigPath 18 | 19 | private val databaseConfig = DatabaseConfig.fromJooqConfig(jooqConfigPath) 20 | 21 | private val migrationConfig = configuration.migrationConfig 22 | 23 | private fun connectToDocker() = DefaultDockerClient.fromEnv().build()!! 24 | 25 | fun generate() { 26 | connectToDocker().use { docker -> 27 | val tag = dockerConfig.tag 28 | 29 | if (!docker.imageExists(tag)) { 30 | docker.pull(tag) 31 | } 32 | 33 | val existingContainers = docker.findLabeledContainers(key = dockerConfig.labelKey, value = dockerConfig.labelValue) 34 | 35 | val containerId = 36 | if (existingContainers.isEmpty()) { 37 | docker.createContainer(dockerConfig.toContainerConfig()).id()!! 38 | } else { 39 | if (existingContainers.size > 1) { 40 | log.warn("More than one container with tag ${dockerConfig.labelKey}=$tag has been found. " + 41 | "Using the one which was most recently created") 42 | } 43 | existingContainers.sortedBy { it.created() }.map { it.id() }.first() 44 | } 45 | 46 | docker.useContainer(containerId) { 47 | waitForDatabase() 48 | migrateDatabase() 49 | runJooqGenerator() 50 | } 51 | } 52 | } 53 | 54 | private fun waitForDatabase() { 55 | val healthChecker = HealthChecker.getDefault(databaseConfig, healthCheckConfig) 56 | 57 | healthChecker.waitForDatabase() 58 | } 59 | 60 | private fun migrateDatabase() { 61 | val migrator = Migrator.fromConfig(migrationConfig, databaseConfig) 62 | 63 | with(migrator) { 64 | clean() 65 | migrate() 66 | } 67 | } 68 | 69 | private fun runJooqGenerator() { 70 | val jooqConfig = jooqConfigPath.toFile().readText() 71 | 72 | val generationTool = Class.forName("org.jooq.codegen.GenerationTool", true, Thread.currentThread().contextClassLoader) 73 | 74 | val generateMethod = generationTool.getDeclaredMethod("generate", String::class.java) 75 | 76 | generateMethod.invoke(generationTool, jooqConfig) 77 | } 78 | 79 | } -------------------------------------------------------------------------------- /src/main/kotlin/ch/ayedo/jooqmodelator/core/configuration/Configuration.kt: -------------------------------------------------------------------------------- 1 | package ch.ayedo.jooqmodelator.core.configuration 2 | 3 | import com.spotify.docker.client.messages.ContainerConfig 4 | import com.spotify.docker.client.messages.HostConfig 5 | import com.spotify.docker.client.messages.PortBinding 6 | import java.nio.file.Path 7 | 8 | data class Configuration(val dockerConfig: DockerConfig, 9 | val healthCheckConfig: HealthCheckConfig, 10 | val migrationConfig: MigrationConfig, 11 | val jooqConfigPath: Path) 12 | 13 | data class MigrationConfig(val engine: MigrationEngine, val migrationsPaths: List) 14 | 15 | enum class MigrationEngine { 16 | FLYWAY, 17 | LIQUIBASE 18 | } 19 | 20 | @Suppress("SpellCheckingInspection") 21 | data class DockerConfig(val tag: String, 22 | val labelKey: String = "ch.ayedo.jooqmodelator", 23 | val env: List, 24 | val portMapping: PortMapping) { 25 | 26 | val labelValue = "tag=$tag cport=${portMapping.container} hport=${portMapping.host} env=[${env.joinToString()}]" 27 | 28 | fun toContainerConfig(): ContainerConfig? { 29 | val hostConfig = createHostConfig() 30 | 31 | return ContainerConfig.builder() 32 | .hostConfig(hostConfig) 33 | .image(tag) 34 | .env(env) 35 | .exposedPorts(portMapping.container.toString()) 36 | .labels(mapOf(labelKey to labelValue)) 37 | .build() 38 | } 39 | 40 | private fun createHostConfig(): HostConfig { 41 | 42 | val defaultPortBinding: PortBinding = PortBinding.of("0.0.0.0", portMapping.host) 43 | val portBindings = mapOf(portMapping.container.toString() to listOf(defaultPortBinding)) 44 | 45 | return HostConfig.builder() 46 | .portBindings(portBindings) 47 | .build() 48 | } 49 | } 50 | 51 | data class PortMapping(val host: Int, val container: Int) 52 | 53 | data class HealthCheckConfig(val delayMs: Long = 500, val maxDurationMs: Long = 20000, val sql: String = "SELECT 1") 54 | -------------------------------------------------------------------------------- /src/main/kotlin/ch/ayedo/jooqmodelator/core/configuration/DatabaseConfiguration.kt: -------------------------------------------------------------------------------- 1 | package ch.ayedo.jooqmodelator.core.configuration 2 | 3 | import java.nio.charset.Charset 4 | import java.nio.file.Path 5 | import javax.xml.stream.XMLInputFactory 6 | import javax.xml.stream.XMLStreamReader 7 | 8 | data class DatabaseConfig(val driver: String, val url: String, val user: String, val password: String) { 9 | 10 | companion object { 11 | 12 | fun fromJooqConfig(jooqConfigPath: Path): DatabaseConfig { 13 | 14 | val factory = XMLInputFactory.newInstance() 15 | 16 | val reader = jooqConfigPath.toFile().reader(Charset.forName("UTF-8")) 17 | 18 | val xmlStreamReader = factory.createXMLStreamReader(reader) 19 | 20 | return try { 21 | 22 | skipToTag(xmlStreamReader, "jdbc") 23 | 24 | skipToTag(xmlStreamReader, "driver") 25 | val driver = xmlStreamReader.elementText 26 | 27 | skipToTag(xmlStreamReader, "url") 28 | val url = xmlStreamReader.elementText 29 | 30 | skipToTag(xmlStreamReader, "user") 31 | val user = xmlStreamReader.elementText 32 | 33 | skipToTag(xmlStreamReader, "password") 34 | val password = xmlStreamReader.elementText 35 | 36 | DatabaseConfig(driver, url, user, password) 37 | 38 | } catch (e: Exception) { 39 | throw IllegalStateException("Could not parse database configuration from jooq configuration file.\n" + 40 | "[XMLStreamReader=${xmlStreamReader::class.java} jooqConfigPath=${jooqConfigPath.toAbsolutePath()}\n" + 41 | "content=${jooqConfigPath.toFile().readText()}]", e) 42 | } finally { 43 | xmlStreamReader.close() 44 | } 45 | } 46 | 47 | private fun skipToTag(xmlStreamReader: XMLStreamReader, tag: String) { 48 | xmlStreamReader.nextTag() 49 | 50 | while (xmlStreamReader.localName != tag) { 51 | xmlStreamReader.nextTag() 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/kotlin/ch/ayedo/jooqmodelator/gradle/JooqModelatorExtension.kt: -------------------------------------------------------------------------------- 1 | package ch.ayedo.jooqmodelator.gradle 2 | 3 | 4 | @Suppress("SpellCheckingInspection") 5 | open class JooqModelatorExtension { 6 | 7 | var jooqVersion: String? = null 8 | 9 | var jooqEdition: String? = null 10 | 11 | var jooqConfigPath: String? = null 12 | 13 | var jooqOutputPath: String? = null 14 | 15 | var migrationsPaths: List? = null 16 | 17 | var dockerTag: String? = null 18 | 19 | var dockerEnv: List = emptyList() 20 | 21 | var dockerHostPort: Int? = null 22 | 23 | var dockerContainerPort: Int? = null 24 | 25 | var migrationEngine: String? = null 26 | 27 | var delayMs: Long = 500 28 | 29 | var maxDurationMs: Long = 20000 30 | 31 | var sql: String = "SELECT 1" 32 | 33 | var labelKey: String = "ch.ayedo.jooqmodelator" 34 | } 35 | -------------------------------------------------------------------------------- /src/main/kotlin/ch/ayedo/jooqmodelator/gradle/JooqModelatorPlugin.kt: -------------------------------------------------------------------------------- 1 | package ch.ayedo.jooqmodelator.gradle 2 | 3 | import org.gradle.api.Plugin 4 | import org.gradle.api.Project 5 | import org.gradle.api.artifacts.Configuration 6 | import java.nio.file.Paths 7 | 8 | @Suppress("SpellCheckingInspection") 9 | open class JooqModelatorPlugin : Plugin { 10 | 11 | override fun apply(project: Project) { 12 | 13 | project.extensions.create("jooqModelator", JooqModelatorExtension::class.java) 14 | 15 | val modelatorRuntime = project.configurations.create("jooqModelatorRuntime") 16 | 17 | modelatorRuntime.description = "Add JDBC drivers or generator extensions here." 18 | 19 | project.afterEvaluate { 20 | 21 | val config = project.extensions.findByType(JooqModelatorExtension::class.java)!! 22 | 23 | addJooqDependency(project, modelatorRuntime, config) 24 | 25 | val task = project.tasks.create("generateJooqMetamodel", JooqModelatorTask::class.java).apply { 26 | description = "Generates the jOOQ metamodel from migrations files using a dockerized database." 27 | 28 | jooqConfigPath = Paths.get(config.jooqConfigPath 29 | ?: throw IncompletePluginConfigurationException("path to the jOOQ generator configuration (jooqConfigPath)")) 30 | 31 | jooqOutputPath = Paths.get(config.jooqOutputPath 32 | ?: throw IncompletePluginConfigurationException("path to the output directory (jooqOutputPath)")) 33 | 34 | migrationsPaths = config.migrationsPaths?.map { strPath -> Paths.get(strPath) } 35 | ?: throw IncompletePluginConfigurationException("path to the migration files (migrationsPaths)") 36 | 37 | dockerLabelKey = config.labelKey 38 | 39 | dockerEnv = config.dockerEnv 40 | 41 | dockerTag = config.dockerTag 42 | ?: throw IncompletePluginConfigurationException("docker image tag (dockerTag)") 43 | 44 | dockerHostPort = config.dockerHostPort 45 | ?: throw IncompletePluginConfigurationException("docker host port (dockerHostPort)") 46 | 47 | dockerContainerPort = config.dockerContainerPort 48 | ?: throw IncompletePluginConfigurationException("docker container port (dockerContainerPort)") 49 | 50 | migrationEngine = config.migrationEngine 51 | ?: throw IncompletePluginConfigurationException("migration engine (migrationEngine)") 52 | 53 | delayMs = config.delayMs 54 | 55 | maxDurationMs = config.maxDurationMs 56 | 57 | sql = config.sql 58 | 59 | jooqClasspath = modelatorRuntime.map { entry -> entry.toURI().toURL() } 60 | } 61 | 62 | // substitute for @InputDirectories 63 | for (migrationPath in task.migrationsPaths) { 64 | task.inputs.dir(migrationPath) 65 | } 66 | } 67 | 68 | 69 | } 70 | 71 | private fun addJooqDependency(project: Project, modelatorRuntime: Configuration, config: JooqModelatorExtension) { 72 | val jooqVersion = config.jooqVersion 73 | ?: throw IncompletePluginConfigurationException("jOOQ version (jooqVersion)") 74 | 75 | project.dependencies.add(modelatorRuntime.name, "${jooqEditionToGroupId(config.jooqEdition)}:jooq-codegen:${jooqVersion}") 76 | } 77 | 78 | // source: https://github.com/etiennestuder/gradle-jooq-plugin 79 | private fun jooqEditionToGroupId(edition: String?) = when (edition) { 80 | "OSS" -> "org.jooq" 81 | "PRO" -> "org.jooq.pro" 82 | "PRO_JAVA_6" -> "org.jooq.pro-java-6" 83 | "TRIAL" -> "org.jooq.trial" 84 | else -> throw IllegalArgumentException("Wrong jooqModelator plugin configuration: jOOQ Edition incorrect. Must be one of ['OSS, 'PRO', 'PRO_JAVA_6', 'TRIAL']") 85 | 86 | } 87 | 88 | class IncompletePluginConfigurationException(missing: String) : IllegalArgumentException( 89 | "Incomplete jooqModelator plugin configuration: $missing is missing" 90 | ) 91 | 92 | } -------------------------------------------------------------------------------- /src/main/kotlin/ch/ayedo/jooqmodelator/gradle/JooqModelatorTask.kt: -------------------------------------------------------------------------------- 1 | package ch.ayedo.jooqmodelator.gradle 2 | 3 | import ch.ayedo.jooqmodelator.core.Modelator 4 | import ch.ayedo.jooqmodelator.core.configuration.Configuration 5 | import ch.ayedo.jooqmodelator.core.configuration.DockerConfig 6 | import ch.ayedo.jooqmodelator.core.configuration.HealthCheckConfig 7 | import ch.ayedo.jooqmodelator.core.configuration.MigrationConfig 8 | import ch.ayedo.jooqmodelator.core.configuration.MigrationEngine 9 | import ch.ayedo.jooqmodelator.core.configuration.PortMapping 10 | import org.gradle.api.DefaultTask 11 | import org.gradle.api.tasks.Input 12 | import org.gradle.api.tasks.InputFile 13 | import org.gradle.api.tasks.InputFiles 14 | import org.gradle.api.tasks.OutputDirectory 15 | import org.gradle.api.tasks.TaskAction 16 | import java.net.URL 17 | import java.net.URLClassLoader 18 | import java.nio.file.Path 19 | 20 | 21 | @Suppress("SpellCheckingInspection") 22 | open class JooqModelatorTask : DefaultTask() { 23 | 24 | @InputFile 25 | lateinit var jooqConfigPath: Path 26 | 27 | @OutputDirectory 28 | lateinit var jooqOutputPath: Path 29 | 30 | @InputFiles 31 | lateinit var migrationsPaths: List 32 | 33 | @Input 34 | lateinit var dockerLabelKey: String 35 | 36 | @Input 37 | lateinit var dockerTag: String 38 | 39 | @Input 40 | lateinit var dockerEnv: List 41 | 42 | @Input 43 | var dockerHostPort: Int = 5432 44 | 45 | @Input 46 | var dockerContainerPort: Int = 5432 47 | 48 | @Input 49 | lateinit var migrationEngine: String 50 | 51 | @Input 52 | var delayMs: Long = 500 53 | 54 | @Input 55 | var maxDurationMs: Long = 20000 56 | 57 | @Input 58 | lateinit var sql: String 59 | 60 | @Input 61 | lateinit var jooqClasspath: List 62 | 63 | @TaskAction 64 | fun generateMetamodel() { 65 | 66 | val dockerConfig = DockerConfig(dockerTag, dockerLabelKey, dockerEnv, PortMapping(dockerHostPort, dockerContainerPort)) 67 | 68 | val healthCheckConfig = HealthCheckConfig(delayMs, maxDurationMs, sql) 69 | 70 | val migrationsConfig = MigrationConfig(MigrationEngine.valueOf(migrationEngine), migrationsPaths) 71 | 72 | val config = Configuration(dockerConfig, healthCheckConfig, migrationsConfig, jooqConfigPath) 73 | 74 | val classLoader = URLClassLoader(jooqClasspath.toTypedArray(), this.javaClass.classLoader) 75 | 76 | Thread.currentThread().contextClassLoader = classLoader 77 | 78 | Modelator(config).generate() 79 | } 80 | } -------------------------------------------------------------------------------- /src/main/resources/META-INF/gradle-plugins/ch.ayedo.jooqmodelator.properties: -------------------------------------------------------------------------------- 1 | implementation-class=ch.ayedo.jooqmodelator.gradle.JooqModelatorPlugin -------------------------------------------------------------------------------- /src/test/kotlin/ch/ayedo/jooqmodelator/GradleApplyTest.kt: -------------------------------------------------------------------------------- 1 | package ch.ayedo.jooqmodelator 2 | 3 | import ch.ayedo.jooqmodelator.gradle.JooqModelatorTask 4 | import org.gradle.testfixtures.ProjectBuilder 5 | import org.junit.jupiter.api.Assertions.assertTrue 6 | import org.junit.jupiter.api.Test 7 | 8 | class GradleApplyTest { 9 | 10 | @Test 11 | fun addPluginToProject() { 12 | 13 | val project = ProjectBuilder.builder().build() 14 | 15 | project.pluginManager.apply("ch.ayedo.jooqmodelator") 16 | 17 | val taskLookup = project.task(hashMapOf("type" to JooqModelatorTask::class.java), "generateJooqMetamodel") 18 | 19 | assertTrue(taskLookup is JooqModelatorTask) 20 | 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /src/test/kotlin/ch/ayedo/jooqmodelator/IntegrationTest.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("SpellCheckingInspection") 2 | 3 | package ch.ayedo.jooqmodelator 4 | 5 | import ch.ayedo.jooqmodelator.IntegrationTest.Database.MARIADB 6 | import ch.ayedo.jooqmodelator.IntegrationTest.Database.POSTGRES 7 | import ch.ayedo.jooqmodelator.core.configuration.Configuration 8 | import ch.ayedo.jooqmodelator.core.configuration.DockerConfig 9 | import ch.ayedo.jooqmodelator.core.configuration.HealthCheckConfig 10 | import ch.ayedo.jooqmodelator.core.configuration.MigrationConfig 11 | import ch.ayedo.jooqmodelator.core.configuration.MigrationEngine 12 | import ch.ayedo.jooqmodelator.core.configuration.MigrationEngine.FLYWAY 13 | import ch.ayedo.jooqmodelator.core.configuration.MigrationEngine.LIQUIBASE 14 | import ch.ayedo.jooqmodelator.core.configuration.PortMapping 15 | import org.gradle.internal.impldep.org.junit.Rule 16 | import org.gradle.internal.impldep.org.junit.rules.TemporaryFolder 17 | import org.gradle.testkit.runner.GradleRunner 18 | import org.gradle.testkit.runner.TaskOutcome 19 | import org.gradle.testkit.runner.TaskOutcome.SUCCESS 20 | import org.gradle.testkit.runner.TaskOutcome.UP_TO_DATE 21 | import org.junit.jupiter.api.Assertions 22 | import org.junit.jupiter.api.Test 23 | import java.io.File 24 | import java.nio.file.Files 25 | import java.nio.file.Path 26 | import java.nio.file.Paths 27 | import java.nio.file.StandardCopyOption.REPLACE_EXISTING 28 | 29 | private const val DEFAULT_JOOQ_VERSION = "3.13.2" 30 | private const val PG_DRIVER_VERSION = "42.2.14" 31 | private const val MARIADB_DRIVER_VERSION = "2.6.0" 32 | 33 | class IntegrationTest { 34 | 35 | private enum class Database( 36 | val version: String, 37 | val defaultPort: Int, 38 | val db: String, 39 | val user: String, 40 | val password: String, 41 | val rootPassword: String = "", 42 | private val dialectVersion: String? = version.replace(".", "_"), 43 | private val subdir: String = "" 44 | ) { 45 | POSTGRES( 46 | version = "12.3", 47 | defaultPort = 5432, 48 | db = "postgres", 49 | user = "postgres", 50 | password = "secret", 51 | dialectVersion = null 52 | ), 53 | MARIADB( 54 | version = "10.2", 55 | defaultPort = 3306, 56 | db = "maria", 57 | user = "root", 58 | password = "pass", 59 | rootPassword = "pass", 60 | subdir = "maria" 61 | ); 62 | 63 | val subdirPath get() = "/$subdir" 64 | val dialect get() = dialectVersion?.let { "name_$dialectVersion" } ?: name 65 | } 66 | 67 | @Rule 68 | private val tempDir = TemporaryFolder().also { it.create() } 69 | 70 | private val jooqPackageName = "ch.ayedo.jooqmodelator.test" 71 | 72 | private val jooqPackagePath = "/" + jooqPackageName.replace(".", "/") 73 | 74 | @Test 75 | fun flywayPostgres() { 76 | 77 | val database = POSTGRES 78 | val config = createJooqConfig(database) 79 | .asConfig(FLYWAY) { 80 | newPostgresConfig() 81 | } 82 | 83 | createBuildFile(config) 84 | 85 | assertBuildOutcome(SUCCESS) 86 | 87 | assertExistingTables(database, "Tab", "Tabtwo") 88 | 89 | } 90 | 91 | @Test 92 | fun liquibasePostgres() { 93 | val database = POSTGRES 94 | val config = createJooqConfig(database) 95 | .asConfig(LIQUIBASE) { 96 | newPostgresConfig() 97 | } 98 | 99 | createBuildFile(config) 100 | 101 | assertBuildOutcome(SUCCESS) 102 | 103 | assertExistingTables(database, "Tab", "Tabtwo") 104 | 105 | } 106 | 107 | @Test 108 | fun flywayMariaDb() { 109 | 110 | val database = MARIADB 111 | val config = createJooqConfig(database) 112 | .asConfig(FLYWAY) { 113 | newMariaDbConfig() 114 | } 115 | 116 | createBuildFile(config) 117 | 118 | assertBuildOutcome(SUCCESS) 119 | 120 | assertExistingTables(database, "Tab", "Tabtwo") 121 | 122 | } 123 | 124 | @Test 125 | fun liquibaseMariaDb() { 126 | 127 | val database = MARIADB 128 | val config = createJooqConfig(database) 129 | .asConfig(LIQUIBASE) { 130 | newMariaDbConfig() 131 | } 132 | 133 | createBuildFile(config) 134 | 135 | assertBuildOutcome(SUCCESS) 136 | 137 | assertExistingTables(database, "Tab", "Tabtwo") 138 | 139 | } 140 | 141 | 142 | @Test 143 | fun incrementalBuildTest() { 144 | 145 | val database = POSTGRES 146 | val config = createJooqConfig(database) 147 | .asConfig(FLYWAY) { 148 | newPostgresConfig() 149 | } 150 | 151 | createBuildFile(config) 152 | 153 | assertBuildOutcome(SUCCESS) 154 | 155 | assertBuildOutcome(UP_TO_DATE) 156 | 157 | assertExistingTables(database, "Tab", "Tabtwo") 158 | 159 | } 160 | 161 | @Test 162 | fun incrementalBuildChangeFilesTest() { 163 | 164 | val additionalMigrationsDir = tempDir.newFolder("migrationsC").toPath() 165 | 166 | val database = POSTGRES 167 | val config = createJooqConfig(database) 168 | .asConfig(FLYWAY, migrationPaths = migrationsFromResources("/migrations") + listOf(additionalMigrationsDir)) { 169 | newPostgresConfig() 170 | } 171 | 172 | createBuildFile(config) 173 | 174 | assertBuildOutcome(SUCCESS) 175 | 176 | assertBuildOutcome(UP_TO_DATE) 177 | 178 | assertExistingTables(database, "Tab") 179 | assertNotExistingTables(database, "Tabtwo") 180 | 181 | Files.copy(migrationsFromResources("/migrationsB/V2__flyway_test.sql").first(), additionalMigrationsDir.resolve("V2__flyway_test.sql"), REPLACE_EXISTING) 182 | 183 | assertBuildOutcome(SUCCESS) 184 | 185 | assertExistingTables(database, "Tabtwo") 186 | 187 | } 188 | 189 | private fun assertExistingTables(database: Database, vararg tableNames: String) = 190 | tableNames.forEach { 191 | Assertions.assertTrue( 192 | fileExists("${tempDir.root.absolutePath}$jooqPackagePath${database.subdirPath}/tables/$it.java"), 193 | "Expected file does not exist." 194 | ) 195 | } 196 | 197 | private fun assertNotExistingTables(database: Database, vararg tableNames: String) = 198 | tableNames.forEach { 199 | Assertions.assertFalse( 200 | fileExists("${tempDir.root.absolutePath}$jooqPackagePath${database.subdirPath}/tables/$it.java"), 201 | "File was expected to not exist." 202 | ) 203 | } 204 | 205 | @Test 206 | fun changePortsTest() { 207 | 208 | val firstPort = 2346 209 | val secondPort = POSTGRES.defaultPort 210 | 211 | val config = createJooqConfig(POSTGRES, port = firstPort) 212 | .asConfig(FLYWAY) { 213 | newPostgresConfig(hostPort = firstPort) 214 | } 215 | 216 | createBuildFile(config) 217 | 218 | assertBuildOutcome(SUCCESS) 219 | 220 | 221 | val newConfig = createJooqConfig(POSTGRES, port = secondPort) 222 | .asConfig(FLYWAY) { 223 | newPostgresConfig(hostPort = secondPort) 224 | } 225 | 226 | createBuildFile(newConfig) 227 | 228 | assertBuildOutcome(SUCCESS) 229 | 230 | } 231 | 232 | @Test 233 | fun liquibaseYamlTest() { 234 | 235 | val config = createJooqConfig(POSTGRES) 236 | .asConfig(LIQUIBASE, migrationPaths = migrationsFromResources("/liquibase-yml-migrations")) { 237 | newPostgresConfig() 238 | } 239 | 240 | createBuildFile(config) 241 | 242 | assertBuildOutcome(SUCCESS) 243 | 244 | 245 | } 246 | 247 | private fun createJooqConfig( 248 | database: Database, 249 | databaseName: String = database.db, 250 | port: Int = database.defaultPort, 251 | user: String = database.user, 252 | password: String = database.password, 253 | dialect: String = database.dialect 254 | ): File { 255 | 256 | File("${tempDir.root.absolutePath}/jooqConfig.xml").delete() 257 | 258 | return tempDir.newFile("jooqConfig.xml").also { 259 | val configFilePath = tempDir.root.absolutePath 260 | 261 | val content = when (database) { 262 | POSTGRES -> jooqPostgresConfig(configFilePath, port, databaseName, user, password, dialect) 263 | MARIADB -> jooqMariaDbConfig(configFilePath, port, databaseName, user, password, dialect) 264 | } 265 | 266 | it.writeText(content) 267 | } 268 | } 269 | 270 | private fun jooqPostgresConfig(target: String, port: Int = POSTGRES.defaultPort, database: String, user: String, password: String, dialect: String) = """ 271 | 272 | 273 | 274 | org.postgresql.Driver 275 | jdbc:postgresql://localhost:$port/$database?loggerLevel=DEBUG 276 | $user 277 | $password 278 | 279 | 280 | 281 | org.jooq.meta.postgres.PostgresDatabase 282 | public 283 | 284 | 285 | $jooqPackageName 286 | $target 287 | 288 | 289 | 290 | key = 'dialect' 291 | value = '$dialect' 292 | 293 | 294 | 295 | 296 | """.trimIndent() 297 | 298 | private fun jooqMariaDbConfig(target: String, port: Int = MARIADB.defaultPort, database: String, user: String, password: String, dialect: String) = """ 299 | 300 | 301 | 302 | org.mariadb.jdbc.Driver 303 | jdbc:mariadb://localhost:$port/$database 304 | $user 305 | $password 306 | 307 | 308 | 309 | org.jooq.meta.mariadb.MariaDBDatabase 310 | 311 | 312 | $jooqPackageName 313 | $target 314 | 315 | 316 | 317 | key = 'dialect' 318 | value = '$dialect' 319 | 320 | 321 | 322 | 323 | """.trimIndent() 324 | 325 | 326 | private fun migrationsFromResources(vararg paths: String): List = paths.map { path -> getResourcePath(path) } 327 | 328 | private fun fileExists(fileName: String) = File(fileName).exists() 329 | 330 | private fun getResourcePath(path: String): Path = Paths.get(this.javaClass.getResource(path).toURI()) 331 | 332 | private fun createBuildFile(config: Configuration) { 333 | 334 | File("${tempDir.root.absolutePath}/build.gradle").delete() 335 | 336 | tempDir.newFile("build.gradle").also { 337 | val buildFileText = buildFileFromConfiguration(config, tempDir.root.absolutePath + jooqPackagePath) 338 | 339 | it.writeText(buildFileText) 340 | } 341 | } 342 | 343 | private fun assertBuildOutcome(targetOutcome: TaskOutcome) { 344 | 345 | val result = GradleRunner.create() 346 | .withPluginClasspath() 347 | .withProjectDir(tempDir.root) 348 | .withArguments("generateJooqMetamodel", "--stacktrace") 349 | .withDebug(true) 350 | .build() 351 | 352 | Assertions.assertTrue(result.task(":generateJooqMetamodel")?.outcome == targetOutcome) 353 | 354 | println(result.output) 355 | } 356 | 357 | private fun newPostgresConfig(hostPort: Int = POSTGRES.defaultPort): DockerConfig = DockerConfig( 358 | tag = "postgres:${POSTGRES.version}", 359 | env = listOf("POSTGRES_DB=${POSTGRES.db}", "POSTGRES_USER=${POSTGRES.user}", "POSTGRES_PASSWORD=${POSTGRES.password}"), 360 | portMapping = PortMapping(hostPort, POSTGRES.defaultPort)) 361 | 362 | private fun newMariaDbConfig(): DockerConfig = DockerConfig( 363 | tag = "mariadb:${MARIADB.version}", 364 | env = listOf("MYSQL_DATABASE=${MARIADB.db}", "MYSQL_ROOT_PASSWORD=${MARIADB.rootPassword}", "MYSQL_PASSWORD=${MARIADB.password}"), 365 | portMapping = PortMapping(MARIADB.defaultPort, MARIADB.defaultPort)) 366 | 367 | private fun buildFileFromConfiguration(config: Configuration, jooqOutputPath: String, jooqVersion: String = DEFAULT_JOOQ_VERSION, jooqEdition: String = "OSS") = 368 | """ 369 | plugins { 370 | id 'ch.ayedo.jooqmodelator' 371 | } 372 | 373 | jooqModelator { 374 | 375 | jooqVersion = '$jooqVersion' 376 | 377 | jooqEdition = '$jooqEdition' 378 | 379 | jooqConfigPath = '${config.jooqConfigPath}' 380 | 381 | jooqOutputPath = '$jooqOutputPath' 382 | 383 | migrationsPaths = ${config.migrationConfig.migrationsPaths.joinToString(prefix = "[", postfix = "]") { "'$it'" }} 384 | 385 | dockerTag = '${config.dockerConfig.tag}' 386 | 387 | dockerEnv = ${config.dockerConfig.env.joinToString(prefix = "[", postfix = "]") { "'$it'" }} 388 | 389 | dockerHostPort = ${config.dockerConfig.portMapping.host} 390 | 391 | dockerContainerPort = ${config.dockerConfig.portMapping.container} 392 | 393 | labelKey = '${config.dockerConfig.labelKey}' 394 | 395 | migrationEngine = '${config.migrationConfig.engine}' 396 | 397 | delayMs = ${config.healthCheckConfig.delayMs} 398 | 399 | maxDurationMs = ${config.healthCheckConfig.maxDurationMs} 400 | 401 | sql = '${config.healthCheckConfig.sql}' 402 | 403 | } 404 | 405 | repositories { 406 | jcenter() 407 | } 408 | 409 | dependencies { 410 | jooqModelatorRuntime('org.postgresql:postgresql:$PG_DRIVER_VERSION') 411 | jooqModelatorRuntime('org.mariadb.jdbc:mariadb-java-client:$MARIADB_DRIVER_VERSION') 412 | jooqModelatorRuntime('org.yaml:snakeyaml:1.26') 413 | } 414 | 415 | """.trimIndent() 416 | 417 | private fun File.asConfig( 418 | migrationEngine: MigrationEngine, 419 | migrationPaths: List = migrationsFromResources("/migrations", "/migrationsB"), 420 | dockerConfigProvider: () -> DockerConfig 421 | ): Configuration = 422 | Configuration( 423 | dockerConfig = dockerConfigProvider(), 424 | healthCheckConfig = HealthCheckConfig(), 425 | migrationConfig = MigrationConfig(engine = migrationEngine, migrationsPaths = migrationPaths), 426 | jooqConfigPath = toPath() 427 | ) 428 | 429 | } 430 | -------------------------------------------------------------------------------- /src/test/resources/liquibase-yml-migrations/databaseChangeLog.yml: -------------------------------------------------------------------------------- 1 | databaseChangeLog: 2 | 3 | - changeSet: 4 | id: 1 5 | author: bob 6 | changes: 7 | - createTable: 8 | tableName: tab 9 | columns: 10 | - column: 11 | name: id 12 | type: int 13 | autoIncrement: true 14 | constraints: 15 | primaryKey: true 16 | nullable: false 17 | - column: 18 | name: firstname 19 | type: varchar(50) 20 | - column: 21 | name: state 22 | type: char(2) 23 | -------------------------------------------------------------------------------- /src/test/resources/migrations/V1__flyway_test.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE tab ( 2 | col INTEGER PRIMARY KEY 3 | ); -------------------------------------------------------------------------------- /src/test/resources/migrations/databaseChangeLog.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/test/resources/migrationsB/V2__flyway_test.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE tabTwo ( 2 | col INTEGER PRIMARY KEY 3 | ); -------------------------------------------------------------------------------- /src/test/resources/migrationsB/add.second.table.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | --------------------------------------------------------------------------------