├── .gitignore ├── .mvn └── wrapper │ ├── MavenWrapperDownloader.java │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── .travis.yml ├── DEVEL-README.md ├── LICENSE ├── README.md ├── jpa2ddl-core ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── devskiller │ │ └── jpa2ddl │ │ ├── Action.java │ │ ├── FileResolver.java │ │ ├── GenerationMode.java │ │ ├── GeneratorSettings.java │ │ ├── NoSequenceFilterProvider.java │ │ ├── SchemaGenerator.java │ │ ├── SchemaProcessor.java │ │ ├── dialects │ │ ├── H2MySQL57Dialect.java │ │ ├── H2MySQL8Dialect.java │ │ ├── H2PostgreSQL10Dialect.java │ │ └── H2PostgreSQL95Dialect.java │ │ └── engines │ │ ├── EngineDecorator.java │ │ ├── MySQLDecorator.java │ │ ├── NoOpDecorator.java │ │ ├── OracleDecorator.java │ │ ├── PostgreSQLDecorator.java │ │ └── SQLServerDecorator.java │ └── test │ ├── java │ └── com │ │ └── devskiller │ │ └── jpa2ddl │ │ ├── DatabaseComplexSchemaUpdateTest.java │ │ ├── DatabaseSchemaGeneratorTest.java │ │ ├── DatabaseSchemaUpdateTest.java │ │ ├── FileResolverTest.java │ │ ├── MetadataSchemaGeneratorTest.java │ │ ├── complex │ │ ├── Book.java │ │ └── Chapter.java │ │ └── sample │ │ └── User.java │ └── resources │ ├── complex_migration │ └── v1__jpa2ddl_init.sql │ ├── sample_default_migration │ └── v1__jpa2ddl_init.sql │ ├── sample_empty_migration │ └── v1__jpa2ddl_init.sql │ ├── sample_migration │ └── v1__jpa2ddl_init.sql │ └── sample_postgres_migration │ └── v1__jpa2ddl_init.sql ├── jpa2ddl-gradle-plugin ├── .gitignore ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── devskiller │ │ │ └── jpa2ddl │ │ │ ├── GeneratePlugin.java │ │ │ ├── GeneratePluginExtension.java │ │ │ └── GenerateTask.java │ └── resources │ │ └── META-INF │ │ └── gradle-plugins │ │ └── com.devskiller.jpa2ddl.properties │ └── test │ └── groovy │ └── com │ └── devskiller │ └── jpa2ddl │ └── GeneratePluginTest.groovy ├── jpa2ddl-maven-plugin ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── devskiller │ │ │ └── jpa2ddl │ │ │ └── GenerateMojo.java │ └── resources │ │ └── META-INF │ │ └── plexus │ │ └── components.xml │ └── test │ ├── java │ └── com │ │ └── devskiller │ │ └── jpa2ddl │ │ └── GenerateMojoTest.java │ └── projects │ ├── basic │ └── pom.xml │ └── full │ └── pom.xml ├── jpa2ddl-querydsl-processor ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── devskiller │ └── jpa2ddl │ └── querydsl │ └── QueryDslSchemaProcessor.java ├── jpa2ddl-samples ├── jpa2ddl-flyway-maven-sample │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── README.md │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── oss │ │ │ └── devskiller │ │ │ └── model │ │ │ └── User.java │ │ └── resources │ │ ├── db │ │ └── flyway.mv.db │ │ └── migrations │ │ └── v1__jpa2ddl.sql ├── jpa2ddl-querydsl-maven-sample │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── README.md │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── oss │ │ │ └── devskiller │ │ │ └── model │ │ │ └── User.java │ │ └── resources │ │ └── migrations │ │ └── v1__jpa2ddl.sql └── pom.xml ├── mvnw ├── mvnw.cmd └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | target 3 | *.iml 4 | *.releaseBackup 5 | release.properties -------------------------------------------------------------------------------- /.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import java.net.*; 17 | import java.io.*; 18 | import java.nio.channels.*; 19 | import java.util.Properties; 20 | 21 | public class MavenWrapperDownloader { 22 | 23 | private static final String WRAPPER_VERSION = "0.5.6"; 24 | /** 25 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 26 | */ 27 | private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" 28 | + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; 29 | 30 | /** 31 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 32 | * use instead of the default one. 33 | */ 34 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 35 | ".mvn/wrapper/maven-wrapper.properties"; 36 | 37 | /** 38 | * Path where the maven-wrapper.jar will be saved to. 39 | */ 40 | private static final String MAVEN_WRAPPER_JAR_PATH = 41 | ".mvn/wrapper/maven-wrapper.jar"; 42 | 43 | /** 44 | * Name of the property which should be used to override the default download url for the wrapper. 45 | */ 46 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 47 | 48 | public static void main(String args[]) { 49 | System.out.println("- Downloader started"); 50 | File baseDirectory = new File(args[0]); 51 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 52 | 53 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 54 | // wrapperUrl parameter. 55 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 56 | String url = DEFAULT_DOWNLOAD_URL; 57 | if(mavenWrapperPropertyFile.exists()) { 58 | FileInputStream mavenWrapperPropertyFileInputStream = null; 59 | try { 60 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 61 | Properties mavenWrapperProperties = new Properties(); 62 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 63 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 64 | } catch (IOException e) { 65 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 66 | } finally { 67 | try { 68 | if(mavenWrapperPropertyFileInputStream != null) { 69 | mavenWrapperPropertyFileInputStream.close(); 70 | } 71 | } catch (IOException e) { 72 | // Ignore ... 73 | } 74 | } 75 | } 76 | System.out.println("- Downloading from: " + url); 77 | 78 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 79 | if(!outputFile.getParentFile().exists()) { 80 | if(!outputFile.getParentFile().mkdirs()) { 81 | System.out.println( 82 | "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 83 | } 84 | } 85 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 86 | try { 87 | downloadFileFromURL(url, outputFile); 88 | System.out.println("Done"); 89 | System.exit(0); 90 | } catch (Throwable e) { 91 | System.out.println("- Error downloading"); 92 | e.printStackTrace(); 93 | System.exit(1); 94 | } 95 | } 96 | 97 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 98 | if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { 99 | String username = System.getenv("MVNW_USERNAME"); 100 | char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); 101 | Authenticator.setDefault(new Authenticator() { 102 | @Override 103 | protected PasswordAuthentication getPasswordAuthentication() { 104 | return new PasswordAuthentication(username, password); 105 | } 106 | }); 107 | } 108 | URL website = new URL(urlString); 109 | ReadableByteChannel rbc; 110 | rbc = Channels.newChannel(website.openStream()); 111 | FileOutputStream fos = new FileOutputStream(destination); 112 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 113 | fos.close(); 114 | rbc.close(); 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Devskiller/jpa2ddl/4652c4ecdc68d2aba31467a2c00279ed5fd3724d/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | dist: trusty 3 | group: edge 4 | 5 | language: java 6 | 7 | jdk: 8 | - oraclejdk8 9 | - oraclejdk11 10 | 11 | script: ./mvnw install 12 | 13 | cache: 14 | directories: 15 | - ~/.m2/repository 16 | - ~/.m2/wrapper 17 | 18 | before_cache: 19 | - rm -Rf ~/.m2/repository/com/devskiller/jpa2ddl/ -------------------------------------------------------------------------------- /DEVEL-README.md: -------------------------------------------------------------------------------- 1 | # Developers guide 2 | 3 | ## Releasing the new version 4 | 5 | ```shell 6 | mvn release:clean 7 | mvn release:prepare 8 | mvn release:perform 9 | git pushtags 10 | git add README.md 11 | git commit -m "Readme version update" 12 | git push 13 | ``` -------------------------------------------------------------------------------- /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 | [![Build Status](https://travis-ci.org/Devskiller/jpa2ddl.svg?branch=master)](https://travis-ci.org/Devskiller/jpa2ddl) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.devskiller.jpa2ddl/jpa2ddl-maven-plugin/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.devskiller.jpa2ddl/jpa2ddl-maven-plugin) 2 | 3 | # JPA Schema Generator Plugin 4 | 5 | ## Motivation 6 | 7 | Why another tool to dump the JPA schema? All tools that we've found were related to legacy versions of Hibernate or were covering just simple cases, without options to configure dialect or naming strategy. Also all of the tools we've found are based on the `SchemaExport` class, which does not always correlate with the runtime schema - for example due to the lack of support for the `Integrator` services, used to register `UserType` classes like JodaTime or similar. We were also looking for a tool that is be able to handle further schema migrations, not just dump the current version. 8 | 9 | ## Configuration parameters 10 | 11 | - `packages` (required): list of packages containing JPA entities 12 | - `outputPath`: output file for the generated schema. By default: 13 | - for `UPDATE` action: `BUILD_OUTPUT_DIR/generated-resources/scripts/` 14 | - for other actions: `BUILD_OUTPUT_DIR/generated-resources/scripts/database.sql` 15 | - `jpaProperties`: additional properties like dialect or naming strategies which should be used in generation task. By default `empty` 16 | - `formatOutput`: should the output be formatted. By default `true` 17 | - `skipSequences`: should the generator skip sequences creation. By default `false` 18 | - `delimiter`: delimiter used to separate statements. By default `;` 19 | - `action`: which statements should be generated. By default: `CREATE`. Possible values: 20 | - `DROP` 21 | - `CREATE` 22 | - `DROP_AND_CREATE` 23 | - `UPDATE` 24 | - `generationMode`: schema generation mode. By default `DATABASE`. Possible values: 25 | - `DATABASE`: generation based on setting up embedded database and dumping the schema 26 | - `METADATA`: generation based on static metadata 27 | - `processorProperties`: properties passed to external `SchemaProcessor` classes 28 | 29 | ### Custom H2 dialects 30 | 31 | H2 is often used to imitate native database engines, however with usage going beyond simple SQL it has huge limitations. 32 | To resolve some of them related to sequences we provide custom database dialects. 33 | 34 | - `com.devskiller.jpa2ddl.dialects.H2PostgreSQL95Dialect`: Postgres 9.5 dialect for H2 35 | - `com.devskiller.jpa2ddl.dialects.H2PostgreSQL10Dialect`: Postgres 10 dialect for H2 36 | - `com.devskiller.jpa2ddl.dialects.H2MySQL57Dialect`: MySQL 5.7 dialect for H2 37 | - `com.devskiller.jpa2ddl.dialects.H2MySQL80Dialect`: MySQL 8.0 dialect for H2 38 | 39 | If you need different dialects please build them using above examples. 40 | 41 | ## Maven Plugin 42 | 43 | You can run this plugin directly or integrate it into the default build lifecycle. 44 | 45 | ### Simple configuration example 46 | 47 | ```xml 48 | 49 | 50 | 51 | com.devskiller.jpa2ddl 52 | jpa2ddl-maven-plugin 53 | 0.9.12 54 | true 55 | 56 | 57 | com.test.model 58 | 59 | 60 | 61 | 62 | 63 | ``` 64 | 65 | ### Generate schema 66 | 67 | ```xml 68 | 69 | 70 | 71 | com.devskiller.jpa2ddl 72 | jpa2ddl-maven-plugin 73 | 0.9.12 74 | true 75 | 76 | ${basedir}/src/main/resources/database.sql 77 | 78 | com.test.model 79 | com.test.entities 80 | 81 | 82 | 83 | hibernate.dialect 84 | org.hibernate.dialect.MySQL57Dialect 85 | 86 | 87 | hibernate.default_schema 88 | prod 89 | 90 | 91 | true 92 | true 93 | ; 94 | DROP_AND_CREATE 95 | 96 | 97 | 98 | 99 | ``` 100 | 101 | ### Generate migrations 102 | 103 | It's also possible to generate automated migrations scripts. JPA2DDL supports [Flyway naming patterns](https://flywaydb.org/documentation/migration/sql) for versioned migrations. 104 | 105 | All subsequent migration scripts are saved in the `outputPath`, in the following layout: 106 | ```sh 107 | src/main/resources/migrations/ 108 | v1__jpa2ddl.sql 109 | v2__jpa2ddl.sql 110 | ... next 111 | ``` 112 | 113 | Please note that after generation you can change the name of the file to make it more descriptive following the filename pattern `v(N)__jpa2ddl(_custom_description).sql` - for example `v1__jpa2ddl_init.sql` 114 | 115 | Sample configuration: 116 | 117 | ```xml 118 | 119 | 120 | 121 | com.devskiller.jpa2ddl 122 | jpa2ddl-maven-plugin 123 | 0.9.12 124 | true 125 | 126 | ${basedir}/src/main/resources/migrations/ 127 | 128 | com.test.model 129 | com.test.entities 130 | 131 | 132 | 133 | hibernate.dialect 134 | org.hibernate.dialect.MySQL57Dialect 135 | 136 | 137 | true 138 | ; 139 | UPDATE 140 | 141 | 142 | 143 | 144 | ``` 145 | 146 | ### Direct invocation 147 | 148 | ``` 149 | ./mvnw com.devskiller.jpa2ddl:jpa2ddl-maven-plugin:0.9.12:generate 150 | ``` 151 | 152 | ## Gradle Plugin 153 | 154 | Below you can find a sample `build.gradle` script configuration: 155 | 156 | ```groovy 157 | buildscript { 158 | repositories { 159 | mavenCentral() 160 | } 161 | dependencies { 162 | classpath "com.devskiller.jpa2ddl:jpa2ddl-gradle-plugin:0.9.12" 163 | } 164 | } 165 | 166 | apply plugin: 'com.devskiller.jpa2ddl' 167 | 168 | jpa2ddl { 169 | packages = ['com.test.model'] 170 | } 171 | ``` 172 | 173 | ## Extending jpa2ddl with SchemaProcessors 174 | 175 | Sometimes more actions that just saving the database migrations are needed. 176 | Example of such use case is when there is a need to generate QueryDSL or JOOQ mappings. 177 | The `SchemaProcessor` mechanism in jpa2ddl resolves such needs. 178 | 179 | ### QueryDSL processor 180 | 181 | Additional dependency `jpa2ddl-querydsl-processor` provides the processor to generate mappings for QueryDSL. 182 | To enable it: 183 | - add a `jpa2ddl-querydsl-processor` dependency to the plugin (`plugin->dependencies->dependency`) 184 | - configure the processor in the `plugin->configiration->processorProperties` section: 185 | - `queryDslOutputPath`: output path for generated mapping classes 186 | - `queryDslOutputPackage`: optionally set package for generated classes 187 | 188 | ```xml 189 | 190 | 191 | 192 | com.devskiller.jpa2ddl 193 | jpa2ddl-maven-plugin 194 | ${project.version} 195 | true 196 | 197 | 198 | oss.devskiller.model 199 | 200 | UPDATE 201 | 202 | 203 | queryDslOutputPath 204 | ${project.build.directory}/generated-sources/query-dsl 205 | 206 | 207 | queryDslOutputPackage 208 | oss.devskiller.querydsl 209 | 210 | 211 | 212 | 213 | 214 | com.devskiller.jpa2ddl 215 | jpa2ddl-querydsl-processor 216 | ${project.version} 217 | 218 | 219 | 220 | 221 | 222 | ``` 223 | 224 | ### Building custom SchemaProcessors 225 | 226 | It's possible to build and inject your custom schema processors to jpa2ddl. 227 | The only thing you need to do is to implement the `com.devskiller.jpa2ddl.SchemaProcessor` interface, and add the jar with our implementation as a dependency for the plugin. 228 | 229 | Please refer to the [jpa2ddl-querydsl-processor](https://github.com/Devskiller/jpa2ddl/tree/master/jpa2ddl-querydsl-processor) to see an example. -------------------------------------------------------------------------------- /jpa2ddl-core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | com.devskiller.jpa2ddl 7 | jpa2ddl-parent 8 | 0.10.1-SNAPSHOT 9 | 10 | 11 | jpa2ddl-core 12 | 13 | ${project.artifactId} 14 | jpa2ddl core module 15 | 16 | 17 | 18 | org.hibernate 19 | hibernate-core 20 | 5.4.23.Final 21 | 22 | 23 | javax.validation 24 | validation-api 25 | 26 | 27 | 28 | 29 | javax.validation 30 | validation-api 31 | 2.0.1.Final 32 | 33 | 34 | 35 | net.oneandone.reflections8 36 | reflections8 37 | 0.11.7 38 | 39 | 40 | 41 | com.h2database 42 | h2 43 | 1.4.200 44 | 45 | 46 | 47 | javax.xml.bind 48 | jaxb-api 49 | 2.4.0-b180830.0359 50 | runtime 51 | 52 | 53 | 54 | org.glassfish.jaxb 55 | jaxb-runtime 56 | 2.4.0-b180830.0438 57 | runtime 58 | 59 | 60 | 61 | 62 | junit 63 | junit 64 | test 65 | 66 | 67 | org.assertj 68 | assertj-core 69 | test 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/main/java/com/devskiller/jpa2ddl/Action.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl; 2 | 3 | import org.hibernate.tool.hbm2ddl.SchemaExport; 4 | 5 | public enum Action { 6 | CREATE(SchemaExport.Action.CREATE, "create"), 7 | DROP(SchemaExport.Action.DROP, "drop"), 8 | DROP_AND_CREATE(SchemaExport.Action.BOTH, "drop-and-create"), 9 | UPDATE(SchemaExport.Action.NONE, "update"); 10 | 11 | private final SchemaExport.Action schemaExportAction; 12 | private final String schemaGenerationAction; 13 | 14 | Action(SchemaExport.Action schemaExportAction, String schemaGenerationAction) { 15 | this.schemaExportAction = schemaExportAction; 16 | this.schemaGenerationAction = schemaGenerationAction; 17 | } 18 | 19 | public SchemaExport.Action toSchemaExportAction() { 20 | return schemaExportAction; 21 | } 22 | 23 | public String toSchemaGenerationAction() { 24 | return schemaGenerationAction; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/main/java/com/devskiller/jpa2ddl/FileResolver.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.net.URISyntaxException; 6 | import java.net.URL; 7 | import java.nio.file.FileSystems; 8 | import java.nio.file.FileVisitResult; 9 | import java.nio.file.Files; 10 | import java.nio.file.Path; 11 | import java.nio.file.PathMatcher; 12 | import java.nio.file.Paths; 13 | import java.nio.file.SimpleFileVisitor; 14 | import java.nio.file.attribute.BasicFileAttributes; 15 | import java.util.ArrayList; 16 | import java.util.Arrays; 17 | import java.util.Collections; 18 | import java.util.Comparator; 19 | import java.util.Enumeration; 20 | import java.util.HashSet; 21 | import java.util.List; 22 | import java.util.Optional; 23 | import java.util.Set; 24 | import java.util.regex.Matcher; 25 | import java.util.regex.Pattern; 26 | import java.util.stream.Collectors; 27 | 28 | import static java.util.regex.Pattern.CASE_INSENSITIVE; 29 | 30 | class FileResolver { 31 | 32 | private final static Pattern FILENAME_PATTERN = Pattern.compile("v([0-9]+)__.+\\.sql", CASE_INSENSITIVE); 33 | private final static Pattern SCHEMA_FILENAME_PATTERN = Pattern.compile("v([0-9]+)__jpa2ddl.*\\.sql", CASE_INSENSITIVE); 34 | 35 | static File resolveNextMigrationFile(File migrationDir) { 36 | Optional lastFile = resolveExistingMigrations(migrationDir, true, false) 37 | .stream() 38 | .findFirst(); 39 | 40 | Long fileIndex = lastFile.map((Path input) -> FILENAME_PATTERN.matcher(input.getFileName().toString())) 41 | .map(matcher -> { 42 | if (matcher.find()) { 43 | return Long.valueOf(matcher.group(1)); 44 | } else { 45 | return 0L; 46 | } 47 | }).orElse(0L); 48 | 49 | return migrationDir.toPath().resolve("v" + ++fileIndex + "__jpa2ddl.sql").toFile(); 50 | } 51 | 52 | static List resolveExistingMigrations(File migrationsDir, boolean reversed, boolean onlySchemaMigrations) { 53 | if (!migrationsDir.exists()) { 54 | migrationsDir.mkdirs(); 55 | } 56 | 57 | File[] files = migrationsDir.listFiles(); 58 | 59 | if (files == null) { 60 | return Collections.emptyList(); 61 | } 62 | 63 | Comparator pathComparator = Comparator.comparingLong(FileResolver::compareVersionedMigrations); 64 | if (reversed) { 65 | pathComparator = pathComparator.reversed(); 66 | } 67 | return Arrays.stream(files) 68 | .map(File::toPath) 69 | .filter(path -> !onlySchemaMigrations || SCHEMA_FILENAME_PATTERN.matcher(path.getFileName().toString()).matches()) 70 | .sorted(pathComparator) 71 | .collect(Collectors.toList()); 72 | } 73 | 74 | static Set listClassNamesInPackage(String packageName) throws Exception { 75 | Set classes = new HashSet<>(); 76 | Enumeration resources = Thread.currentThread().getContextClassLoader().getResources(packageName.replace('.', File.separatorChar)); 77 | if (!resources.hasMoreElements()) { 78 | throw new IllegalStateException("No package found: " + packageName); 79 | } 80 | PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:*.class"); 81 | while (resources.hasMoreElements()) { 82 | URL resource = resources.nextElement(); 83 | Files.walkFileTree(Paths.get(resource.toURI()), new SimpleFileVisitor() { 84 | @Override 85 | public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) { 86 | if (pathMatcher.matches(path.getFileName())) { 87 | try { 88 | String className = Paths.get(resource.toURI()).relativize(path).toString().replace(File.separatorChar, '.'); 89 | classes.add(packageName + '.' + className.substring(0, className.length() - 6)); 90 | } catch (URISyntaxException e) { 91 | throw new IllegalStateException(e); 92 | } 93 | } 94 | return FileVisitResult.CONTINUE; 95 | } 96 | }); 97 | } 98 | return classes; 99 | } 100 | 101 | private static Long compareVersionedMigrations(Path path) { 102 | Matcher filenameMatcher = FILENAME_PATTERN.matcher(path.getFileName().toString()); 103 | if (filenameMatcher.find()) { 104 | return Long.valueOf(filenameMatcher.group(1)); 105 | } else { 106 | return Long.MIN_VALUE; 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/main/java/com/devskiller/jpa2ddl/GenerationMode.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl; 2 | 3 | public enum GenerationMode { 4 | 5 | /** 6 | * Generation based on setting up embedded database and dumping the schema 7 | */ 8 | DATABASE, 9 | 10 | /** 11 | * Generation based on static metadata 12 | */ 13 | METADATA 14 | } 15 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/main/java/com/devskiller/jpa2ddl/GeneratorSettings.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl; 2 | 3 | import java.io.File; 4 | import java.util.List; 5 | import java.util.Properties; 6 | 7 | class GeneratorSettings { 8 | 9 | private final GenerationMode generationMode; 10 | private final File outputPath; 11 | private final List packages; 12 | private final Action action; 13 | private final Properties jpaProperties; 14 | private final boolean formatOutput; 15 | private final String delimiter; 16 | private final boolean skipSequences; 17 | private final Properties processorProperties; 18 | 19 | GeneratorSettings(GenerationMode generationMode, File outputPath, List packages, Action action, 20 | Properties jpaProperties, boolean formatOutput, String delimiter, 21 | boolean skipSequences, Properties processorProperties) { 22 | this.generationMode = generationMode; 23 | this.outputPath = outputPath; 24 | this.packages = packages; 25 | this.action = action; 26 | this.jpaProperties = jpaProperties; 27 | this.formatOutput = formatOutput; 28 | this.delimiter = delimiter; 29 | this.skipSequences = skipSequences; 30 | this.processorProperties = processorProperties; 31 | } 32 | 33 | GenerationMode getGenerationMode() { 34 | return generationMode; 35 | } 36 | 37 | File getOutputPath() { 38 | return outputPath; 39 | } 40 | 41 | List getPackages() { 42 | return packages; 43 | } 44 | 45 | Action getAction() { 46 | return action; 47 | } 48 | 49 | Properties getJpaProperties() { 50 | return jpaProperties; 51 | } 52 | 53 | boolean isFormatOutput() { 54 | return formatOutput; 55 | } 56 | 57 | String getDelimiter() { 58 | return delimiter; 59 | } 60 | 61 | boolean isSkipSequences() { 62 | return skipSequences; 63 | } 64 | 65 | Properties getProcessorProperties() { 66 | return processorProperties; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/main/java/com/devskiller/jpa2ddl/NoSequenceFilterProvider.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl; 2 | 3 | import org.hibernate.boot.model.relational.Sequence; 4 | import org.hibernate.mapping.Table; 5 | import org.hibernate.tool.schema.internal.DefaultSchemaFilter; 6 | import org.hibernate.tool.schema.spi.SchemaFilter; 7 | import org.hibernate.tool.schema.spi.SchemaFilterProvider; 8 | 9 | public class NoSequenceFilterProvider implements SchemaFilterProvider { 10 | 11 | @Override 12 | public SchemaFilter getCreateFilter() { 13 | return NoSequenceSchemaFilter.INSTANCE; 14 | } 15 | 16 | @Override 17 | public SchemaFilter getDropFilter() { 18 | return NoSequenceSchemaFilter.INSTANCE; 19 | } 20 | 21 | @Override 22 | public SchemaFilter getMigrateFilter() { 23 | return NoSequenceSchemaFilter.INSTANCE; 24 | } 25 | 26 | @Override 27 | public SchemaFilter getValidateFilter() { 28 | return NoSequenceSchemaFilter.INSTANCE; 29 | } 30 | 31 | private static class NoSequenceSchemaFilter extends DefaultSchemaFilter { 32 | 33 | private static final SchemaFilter INSTANCE = new NoSequenceSchemaFilter(); 34 | 35 | @Override 36 | public boolean includeTable(Table table) { 37 | return !isIdentifierTable(table); 38 | } 39 | 40 | private boolean isIdentifierTable(Table table) { 41 | return !table.getInitCommands().isEmpty(); 42 | } 43 | 44 | @Override 45 | public boolean includeSequence(Sequence sequence) { 46 | return false; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/main/java/com/devskiller/jpa2ddl/SchemaGenerator.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl; 2 | 3 | import com.devskiller.jpa2ddl.engines.EngineDecorator; 4 | import org.hibernate.boot.MetadataSources; 5 | import org.hibernate.boot.registry.StandardServiceRegistryBuilder; 6 | import org.hibernate.tool.hbm2ddl.SchemaExport; 7 | import org.hibernate.tool.schema.TargetType; 8 | import org.reflections8.Reflections; 9 | import org.reflections8.scanners.SubTypesScanner; 10 | import org.reflections8.util.ConfigurationBuilder; 11 | 12 | import java.io.File; 13 | import java.net.URISyntaxException; 14 | import java.net.URL; 15 | import java.nio.file.Files; 16 | import java.nio.file.Path; 17 | import java.sql.Connection; 18 | import java.sql.DriverManager; 19 | import java.util.EnumSet; 20 | import java.util.List; 21 | import java.util.Set; 22 | import java.util.stream.Collectors; 23 | 24 | class SchemaGenerator { 25 | 26 | private static final String DB_URL = "jdbc:h2:mem:jpa2ddl"; 27 | private static final String HIBERNATE_DIALECT = "hibernate.dialect"; 28 | private static final String HIBERNATE_SCHEMA_FILTER_PROVIDER = "hibernate.hbm2ddl.schema_filter_provider"; 29 | 30 | void generate(GeneratorSettings settings) throws Exception { 31 | validateSettings(settings); 32 | 33 | if (settings.getJpaProperties().getProperty(HIBERNATE_DIALECT) == null) { 34 | settings.getJpaProperties().setProperty(HIBERNATE_DIALECT, "org.hibernate.dialect.H2Dialect"); 35 | } 36 | 37 | if (settings.isSkipSequences() && settings.getJpaProperties().getProperty(HIBERNATE_SCHEMA_FILTER_PROVIDER) == null) { 38 | settings.getJpaProperties().setProperty(HIBERNATE_SCHEMA_FILTER_PROVIDER, NoSequenceFilterProvider.class.getCanonicalName()); 39 | } 40 | 41 | File outputFile = settings.getOutputPath(); 42 | 43 | EngineDecorator engineDecorator = EngineDecorator.getEngineDecorator(settings.getJpaProperties().getProperty(HIBERNATE_DIALECT)); 44 | 45 | String dbUrl = getDbUrl(engineDecorator); 46 | 47 | if (settings.getGenerationMode() == GenerationMode.DATABASE) { 48 | 49 | if (settings.getAction() == Action.UPDATE) { 50 | outputFile = FileResolver.resolveNextMigrationFile(settings.getOutputPath()); 51 | } 52 | 53 | settings.getJpaProperties().setProperty("hibernate.connection.url", dbUrl); 54 | settings.getJpaProperties().setProperty("hibernate.connection.username", "sa"); 55 | settings.getJpaProperties().setProperty("hibernate.connection.password", ""); 56 | settings.getJpaProperties().setProperty("javax.persistence.schema-generation.scripts.action", settings.getAction().toSchemaGenerationAction()); 57 | settings.getJpaProperties().setProperty("javax.persistence.schema-generation.database.action", settings.getAction().toSchemaGenerationAction()); 58 | 59 | settings.getJpaProperties().setProperty("javax.persistence.schema-generation.scripts.create-target", outputFile.getAbsolutePath()); 60 | settings.getJpaProperties().setProperty("javax.persistence.schema-generation.scripts.drop-target", outputFile.getAbsolutePath()); 61 | 62 | settings.getJpaProperties().setProperty("hibernate.hbm2ddl.delimiter", settings.getDelimiter()); 63 | settings.getJpaProperties().setProperty("hibernate.format_sql", String.valueOf(settings.isFormatOutput())); 64 | } 65 | 66 | MetadataSources metadata = new MetadataSources( 67 | new StandardServiceRegistryBuilder() 68 | .applySettings(settings.getJpaProperties()) 69 | .build()); 70 | 71 | for (String packageName: settings.getPackages().stream().sorted().collect(Collectors.toList())) { 72 | FileResolver.listClassNamesInPackage(packageName).stream().sorted().forEach(metadata::addAnnotatedClassName); 73 | metadata.addPackage(packageName); 74 | } 75 | 76 | if (settings.getAction() != Action.UPDATE) { 77 | Files.deleteIfExists(settings.getOutputPath().toPath()); 78 | } 79 | 80 | if (settings.getGenerationMode() == GenerationMode.METADATA) { 81 | SchemaExport export = new SchemaExport(); 82 | export.setFormat(settings.isFormatOutput()); 83 | export.setDelimiter(settings.getDelimiter()); 84 | export.setOutputFile(outputFile.getAbsolutePath()); 85 | export.execute(EnumSet.of(TargetType.SCRIPT), settings.getAction().toSchemaExportAction(), metadata.buildMetadata()); 86 | } else { 87 | Class.forName("org.h2.Driver"); // walkaround for the "No suitable driver found" caused by driver being not registered in the DriverManager 88 | Connection connection = DriverManager.getConnection(dbUrl, "SA", ""); 89 | engineDecorator.decorateDatabaseInitialization(connection); 90 | 91 | if (settings.getAction() == Action.UPDATE) { 92 | List resolvedMigrations = FileResolver.resolveExistingMigrations(settings.getOutputPath(), false, true); 93 | for (Path resolvedMigration : resolvedMigrations) { 94 | String statement = new String(Files.readAllBytes(resolvedMigration)); 95 | connection.prepareStatement(statement).execute(); 96 | } 97 | } 98 | 99 | metadata.buildMetadata().buildSessionFactory().close(); 100 | 101 | executePostProcessors(settings, connection); 102 | 103 | connection.close(); 104 | } 105 | 106 | if (outputFile.exists()) { 107 | if (outputFile.length() == 0) { 108 | Files.delete(outputFile.toPath()); 109 | } else { 110 | List lines = Files.readAllLines(outputFile.toPath()) 111 | .stream() 112 | .map(line -> line.replaceAll("(?i)JPA2DDL\\.(PUBLIC\\.)?", "")) 113 | .collect(Collectors.toList()); 114 | Files.write(outputFile.toPath(), lines); 115 | } 116 | } 117 | } 118 | 119 | private void executePostProcessors(GeneratorSettings settings, Connection connection) throws Exception { 120 | ConfigurationBuilder configuration = ConfigurationBuilder.build(".*") 121 | .setExpandSuperTypes(false) 122 | .setScanners(new SubTypesScanner(true)); 123 | configuration.setUrls(getExistingUrls(configuration.getUrls())); 124 | Reflections reflections = new Reflections(configuration); 125 | 126 | Set> schemaProcessorClasses = reflections.getSubTypesOf(SchemaProcessor.class); 127 | 128 | for (Class schemaProcessorClass : schemaProcessorClasses) { 129 | SchemaProcessor schemaProcessor = schemaProcessorClass.getDeclaredConstructor().newInstance(); 130 | schemaProcessor.postProcess(connection, settings.getProcessorProperties()); 131 | } 132 | } 133 | 134 | private Set getExistingUrls(Set urls) { 135 | return urls.stream() 136 | .filter(url -> { 137 | try { 138 | return new File(url.toURI()).exists(); 139 | } catch (URISyntaxException e) { 140 | throw new RuntimeException(e); 141 | } 142 | }) 143 | .collect(Collectors.toSet()); 144 | } 145 | 146 | private String getDbUrl(EngineDecorator engineDecorator) { 147 | return engineDecorator.decorateConnectionString(DB_URL); 148 | } 149 | 150 | private void validateSettings(GeneratorSettings settings) { 151 | if (settings.getAction() == Action.UPDATE) { 152 | if (settings.getOutputPath().exists() && !settings.getOutputPath().isDirectory()) { 153 | throw new IllegalArgumentException("For UPDATE action outputPath must be a directory"); 154 | } 155 | if (settings.getGenerationMode() != GenerationMode.DATABASE) { 156 | throw new IllegalArgumentException("For UPDATE action generation mode must be set to DATABASE"); 157 | } 158 | } 159 | } 160 | 161 | } 162 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/main/java/com/devskiller/jpa2ddl/SchemaProcessor.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl; 2 | 3 | import java.sql.Connection; 4 | import java.util.Properties; 5 | 6 | public interface SchemaProcessor { 7 | 8 | void postProcess(Connection connection, Properties properties); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/main/java/com/devskiller/jpa2ddl/dialects/H2MySQL57Dialect.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl.dialects; 2 | 3 | import org.hibernate.dialect.MySQL57Dialect; 4 | import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorH2DatabaseImpl; 5 | import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor; 6 | 7 | public class H2MySQL57Dialect extends MySQL57Dialect { 8 | 9 | @Override 10 | public SequenceInformationExtractor getSequenceInformationExtractor() { 11 | return new SequenceInformationExtractorH2DatabaseImpl(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/main/java/com/devskiller/jpa2ddl/dialects/H2MySQL8Dialect.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl.dialects; 2 | 3 | import org.hibernate.dialect.MySQL8Dialect; 4 | import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorH2DatabaseImpl; 5 | import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor; 6 | 7 | public class H2MySQL8Dialect extends MySQL8Dialect { 8 | 9 | @Override 10 | public SequenceInformationExtractor getSequenceInformationExtractor() { 11 | return new SequenceInformationExtractorH2DatabaseImpl(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/main/java/com/devskiller/jpa2ddl/dialects/H2PostgreSQL10Dialect.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl.dialects; 2 | 3 | import org.hibernate.dialect.PostgreSQL10Dialect; 4 | import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorH2DatabaseImpl; 5 | import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor; 6 | 7 | public class H2PostgreSQL10Dialect extends PostgreSQL10Dialect { 8 | 9 | @Override 10 | public SequenceInformationExtractor getSequenceInformationExtractor() { 11 | return new SequenceInformationExtractorH2DatabaseImpl(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/main/java/com/devskiller/jpa2ddl/dialects/H2PostgreSQL95Dialect.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl.dialects; 2 | 3 | import org.hibernate.dialect.PostgreSQL95Dialect; 4 | import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorH2DatabaseImpl; 5 | import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor; 6 | 7 | public class H2PostgreSQL95Dialect extends PostgreSQL95Dialect { 8 | 9 | @Override 10 | public SequenceInformationExtractor getSequenceInformationExtractor() { 11 | return new SequenceInformationExtractorH2DatabaseImpl(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/main/java/com/devskiller/jpa2ddl/engines/EngineDecorator.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl.engines; 2 | 3 | import java.io.IOException; 4 | import java.sql.Connection; 5 | import java.sql.SQLException; 6 | 7 | import org.hibernate.dialect.MySQLDialect; 8 | import org.hibernate.dialect.Oracle8iDialect; 9 | import org.hibernate.dialect.PostgreSQL81Dialect; 10 | import org.hibernate.dialect.SQLServerDialect; 11 | 12 | public abstract class EngineDecorator { 13 | 14 | public static EngineDecorator getEngineDecorator(String dialect) throws ClassNotFoundException { 15 | Class dialectClass = Class.forName(dialect); 16 | if (MySQLDialect.class.isAssignableFrom(dialectClass)) { 17 | return new MySQLDecorator(); 18 | } else if (PostgreSQL81Dialect.class.isAssignableFrom(dialectClass)) { 19 | return new PostgreSQLDecorator(); 20 | } else if (Oracle8iDialect.class.isAssignableFrom(dialectClass)) { 21 | return new OracleDecorator(); 22 | } else if (SQLServerDialect.class.isAssignableFrom(dialectClass)) { 23 | return new SQLServerDecorator(); 24 | } 25 | return new NoOpDecorator(); 26 | 27 | } 28 | 29 | public String decorateConnectionString(String connectionString) { 30 | return connectionString; 31 | } 32 | 33 | public void decorateDatabaseInitialization(Connection connection) throws IOException, SQLException { 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/main/java/com/devskiller/jpa2ddl/engines/MySQLDecorator.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl.engines; 2 | 3 | class MySQLDecorator extends EngineDecorator { 4 | 5 | @Override 6 | public String decorateConnectionString(String connectionString) { 7 | return connectionString + ";MODE=MYSQL;DATABASE_TO_UPPER=FALSE"; 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/main/java/com/devskiller/jpa2ddl/engines/NoOpDecorator.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl.engines; 2 | 3 | class NoOpDecorator extends EngineDecorator { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/main/java/com/devskiller/jpa2ddl/engines/OracleDecorator.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl.engines; 2 | 3 | import java.sql.Connection; 4 | import java.sql.SQLException; 5 | 6 | class OracleDecorator extends EngineDecorator { 7 | 8 | private static final String SEQUENCES_VIEW = "CREATE VIEW ALL_SEQUENCES(SEQUENCE_NAME, SEQUENCE_OWNER) AS SELECT SEQUENCE_NAME, '' FROM INFORMATION_SCHEMA.SEQUENCES;"; 9 | private static final String EMPTY_SYNONYMS = "CREATE TABLE ALL_SYNONYMS (SYNONYM_NAME VARCHAR2(30), TABLE_OWNER VARCHAR2(30), TABLE_NAME VARCHAR2(30));"; 10 | 11 | @Override 12 | public String decorateConnectionString(String connectionString) { 13 | return connectionString + ";MODE=Oracle"; 14 | } 15 | 16 | @Override 17 | public void decorateDatabaseInitialization(Connection connection) throws SQLException { 18 | connection.prepareStatement(SEQUENCES_VIEW + "\n" + EMPTY_SYNONYMS).execute(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/main/java/com/devskiller/jpa2ddl/engines/PostgreSQLDecorator.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl.engines; 2 | 3 | import java.io.IOException; 4 | import java.sql.Connection; 5 | import java.sql.SQLException; 6 | 7 | import org.h2.util.Utils; 8 | 9 | class PostgreSQLDecorator extends EngineDecorator { 10 | 11 | @Override 12 | public String decorateConnectionString(String connectionString) { 13 | return connectionString + ";MODE=PostgreSQL;INIT=set search_path to pg_catalog,public;"; 14 | } 15 | 16 | @Override 17 | public void decorateDatabaseInitialization(Connection connection) throws IOException, SQLException { 18 | String dbInit = new String(Utils.getResource("/org/h2/server/pg/pg_catalog.sql")); 19 | connection.prepareStatement(dbInit).execute(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/main/java/com/devskiller/jpa2ddl/engines/SQLServerDecorator.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl.engines; 2 | 3 | class SQLServerDecorator extends EngineDecorator { 4 | 5 | @Override 6 | public String decorateConnectionString(String connectionString) { 7 | return connectionString + ";MODE=MSSQLServer"; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/test/java/com/devskiller/jpa2ddl/DatabaseComplexSchemaUpdateTest.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl; 2 | 3 | import com.devskiller.jpa2ddl.dialects.H2MySQL57Dialect; 4 | import com.devskiller.jpa2ddl.dialects.H2PostgreSQL95Dialect; 5 | import org.hibernate.dialect.MySQL57Dialect; 6 | import org.hibernate.dialect.Oracle12cDialect; 7 | import org.hibernate.dialect.PostgreSQL9Dialect; 8 | import org.junit.Ignore; 9 | import org.junit.Rule; 10 | import org.junit.Test; 11 | import org.junit.rules.TemporaryFolder; 12 | 13 | import java.io.File; 14 | import java.nio.file.Files; 15 | import java.nio.file.Paths; 16 | import java.util.Arrays; 17 | import java.util.Properties; 18 | 19 | import static org.assertj.core.api.Assertions.assertThat; 20 | 21 | public class DatabaseComplexSchemaUpdateTest { 22 | 23 | @Rule 24 | public TemporaryFolder tempFolder = new TemporaryFolder(); 25 | 26 | @Test 27 | @Ignore("should be resolved by introducing test containers in #40") 28 | public void shouldGenerateSchemaUpdate() throws Exception { 29 | // given 30 | File outputPath = tempFolder.newFolder(); 31 | 32 | Files.copy(Paths.get(getClass().getClassLoader().getResource("complex_migration/v1__jpa2ddl_init.sql").toURI()), 33 | outputPath.toPath().resolve("v1__jpa2ddl_init.sql")); 34 | 35 | Properties jpaProperties = new Properties(); 36 | jpaProperties.setProperty("hibernate.dialect", H2MySQL57Dialect.class.getCanonicalName()); 37 | 38 | SchemaGenerator schemaGenerator = new SchemaGenerator(); 39 | 40 | // when 41 | schemaGenerator.generate(new GeneratorSettings(GenerationMode.DATABASE, outputPath, 42 | Arrays.asList("com.devskiller.jpa2ddl.complex"), Action.UPDATE, jpaProperties, true, ";", false, null)); 43 | 44 | // then 45 | String sql = new String(Files.readAllBytes(outputPath.toPath().resolve("v2__jpa2ddl.sql"))); 46 | assertThat(sql).doesNotContain("alter table Book_Chapter"); 47 | assertThat(sql).doesNotContain("drop index"); 48 | assertThat(sql).doesNotContain("add constraint"); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/test/java/com/devskiller/jpa2ddl/DatabaseSchemaGeneratorTest.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl; 2 | 3 | import java.io.File; 4 | import java.nio.file.Files; 5 | import java.util.Arrays; 6 | import java.util.Properties; 7 | 8 | import org.junit.Rule; 9 | import org.junit.Test; 10 | import org.junit.rules.TemporaryFolder; 11 | 12 | import static org.assertj.core.api.Assertions.assertThat; 13 | 14 | public class DatabaseSchemaGeneratorTest { 15 | 16 | @Rule 17 | public TemporaryFolder tempFolder = new TemporaryFolder(); 18 | 19 | @Test 20 | public void shouldGenerateSchemaFromDatabaseWithDropAndCreate() throws Exception { 21 | // given 22 | SchemaGenerator schemaGenerator = new SchemaGenerator(); 23 | File outputFile = tempFolder.newFile(); 24 | File outputDir = tempFolder.newFolder(); 25 | 26 | // when 27 | schemaGenerator.generate(new GeneratorSettings(GenerationMode.DATABASE, outputFile, 28 | Arrays.asList("com.devskiller.jpa2ddl.sample"), Action.DROP_AND_CREATE, new Properties(), true, ";", false, null)); 29 | 30 | // then 31 | String sql = new String(Files.readAllBytes(outputFile.toPath())); 32 | assertThat(sql).contains("create table User"); 33 | assertThat(sql).contains("drop table if exists User"); 34 | } 35 | 36 | @Test 37 | public void shouldGenerateSchemaFromDatabaseWithDrop() throws Exception { 38 | // given 39 | SchemaGenerator schemaGenerator = new SchemaGenerator(); 40 | File outputFile = tempFolder.newFile(); 41 | 42 | // when 43 | schemaGenerator.generate(new GeneratorSettings(GenerationMode.DATABASE, outputFile, 44 | Arrays.asList("com.devskiller.jpa2ddl.sample"), Action.DROP, new Properties(), true, ";", false, null)); 45 | 46 | // then 47 | String sql = new String(Files.readAllBytes(outputFile.toPath())); 48 | assertThat(sql).doesNotContain("create table User"); 49 | assertThat(sql).contains("drop table if exists User"); 50 | } 51 | 52 | @Test 53 | public void shouldGenerateSchemaFromDatabaseWithCreate() throws Exception { 54 | // given 55 | SchemaGenerator schemaGenerator = new SchemaGenerator(); 56 | File outputFile = tempFolder.newFile(); 57 | File outputDir = tempFolder.newFolder(); 58 | 59 | // when 60 | schemaGenerator.generate(new GeneratorSettings(GenerationMode.DATABASE, outputFile, 61 | Arrays.asList("com.devskiller.jpa2ddl.sample"), Action.CREATE, new Properties(), true, ";", false, null)); 62 | 63 | // then 64 | String sql = new String(Files.readAllBytes(outputFile.toPath())); 65 | assertThat(sql).contains("create table User"); 66 | assertThat(sql).doesNotContain("drop table User"); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/test/java/com/devskiller/jpa2ddl/DatabaseSchemaUpdateTest.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl; 2 | 3 | import com.devskiller.jpa2ddl.dialects.H2PostgreSQL95Dialect; 4 | import org.hibernate.dialect.MySQL57Dialect; 5 | import org.hibernate.dialect.Oracle12cDialect; 6 | import org.hibernate.dialect.PostgreSQL10Dialect; 7 | import org.junit.Rule; 8 | import org.junit.Test; 9 | import org.junit.rules.TemporaryFolder; 10 | 11 | import java.io.File; 12 | import java.nio.file.Files; 13 | import java.nio.file.Paths; 14 | import java.util.Arrays; 15 | import java.util.Properties; 16 | 17 | import static org.assertj.core.api.Assertions.assertThat; 18 | 19 | public class DatabaseSchemaUpdateTest { 20 | 21 | @Rule 22 | public TemporaryFolder tempFolder = new TemporaryFolder(); 23 | 24 | @Test 25 | public void shouldGenerateSchemaUpdate() throws Exception { 26 | // given 27 | File outputPath = tempFolder.newFolder(); 28 | 29 | Files.copy(Paths.get(getClass().getClassLoader().getResource("sample_migration/v1__jpa2ddl_init.sql").toURI()), 30 | outputPath.toPath().resolve("v1__jpa2ddl_init.sql")); 31 | 32 | Properties jpaProperties = new Properties(); 33 | jpaProperties.setProperty("hibernate.dialect", MySQL57Dialect.class.getCanonicalName()); 34 | jpaProperties.setProperty("hibernate.default_schema", "prod"); 35 | 36 | SchemaGenerator schemaGenerator = new SchemaGenerator(); 37 | 38 | // when 39 | schemaGenerator.generate(new GeneratorSettings(GenerationMode.DATABASE, outputPath, 40 | Arrays.asList("com.devskiller.jpa2ddl.sample"), Action.UPDATE, jpaProperties, true, ";", false, null)); 41 | 42 | // then 43 | String sql = new String(Files.readAllBytes(outputPath.toPath().resolve("v2__jpa2ddl.sql"))); 44 | assertThat(sql).containsIgnoringCase("alter table prod.User"); 45 | assertThat(sql).containsIgnoringCase("add column email varchar(255);"); 46 | assertThat(sql).containsIgnoringCase("create table prod.hibernate_sequence"); 47 | assertThat(sql).containsIgnoringCase("insert into prod.hibernate_sequence values"); 48 | assertThat(sql).doesNotContain("create table prod.User"); 49 | } 50 | 51 | @Test 52 | public void shouldGenerateDefaultSchemaUpdate() throws Exception { 53 | // given 54 | File outputPath = tempFolder.newFolder(); 55 | 56 | Files.copy(Paths.get(getClass().getClassLoader().getResource("sample_default_migration/v1__jpa2ddl_init.sql").toURI()), 57 | outputPath.toPath().resolve("v1__jpa2ddl_init.sql")); 58 | 59 | Properties jpaProperties = new Properties(); 60 | jpaProperties.setProperty("hibernate.dialect", MySQL57Dialect.class.getCanonicalName()); 61 | 62 | SchemaGenerator schemaGenerator = new SchemaGenerator(); 63 | 64 | // when 65 | schemaGenerator.generate(new GeneratorSettings(GenerationMode.DATABASE, outputPath, 66 | Arrays.asList("com.devskiller.jpa2ddl.sample"), Action.UPDATE, jpaProperties, true, ";", true, null)); 67 | 68 | // then 69 | String sql = new String(Files.readAllBytes(outputPath.toPath().resolve("v2__jpa2ddl.sql"))); 70 | assertThat(sql).containsIgnoringCase("alter table User"); 71 | assertThat(sql).containsIgnoringCase("add column email"); 72 | assertThat(sql).doesNotContain("create table User"); 73 | assertThat(sql).doesNotContain("create table hibernate_sequence"); 74 | assertThat(sql).doesNotContain("insert into hibernate_sequence values"); 75 | } 76 | 77 | 78 | @Test 79 | public void shouldSkipGenerationIfNoChanges() throws Exception { 80 | // given 81 | File outputPath = tempFolder.newFolder(); 82 | 83 | Files.copy(Paths.get(getClass().getClassLoader().getResource("sample_empty_migration/v1__jpa2ddl_init.sql").toURI()), 84 | outputPath.toPath().resolve("v1__jpa2ddl_init.sql")); 85 | 86 | Properties jpaProperties = new Properties(); 87 | jpaProperties.setProperty("hibernate.dialect", MySQL57Dialect.class.getCanonicalName()); 88 | 89 | SchemaGenerator schemaGenerator = new SchemaGenerator(); 90 | 91 | // when 92 | schemaGenerator.generate(new GeneratorSettings(GenerationMode.DATABASE, outputPath, 93 | Arrays.asList("com.devskiller.jpa2ddl.sample"), Action.UPDATE, jpaProperties, true, ";", true, null)); 94 | 95 | // then 96 | File migrationFile = outputPath.toPath().resolve("v2__jpa2ddl.sql").toFile(); 97 | assertThat(migrationFile).doesNotExist(); 98 | } 99 | 100 | @Test 101 | public void shouldGenerateSchemaFromDatabaseWithUpdateWithPostgresDialect() throws Exception { 102 | // given 103 | File outputPath = tempFolder.newFolder(); 104 | Properties jpaProperties = new Properties(); 105 | jpaProperties.setProperty("hibernate.dialect", PostgreSQL10Dialect.class.getCanonicalName()); 106 | jpaProperties.setProperty("hibernate.default_schema", "public"); 107 | 108 | SchemaGenerator schemaGenerator = new SchemaGenerator(); 109 | 110 | // when 111 | schemaGenerator.generate(new GeneratorSettings(GenerationMode.DATABASE, outputPath, 112 | Arrays.asList("com.devskiller.jpa2ddl.sample"), Action.UPDATE, jpaProperties, true, ";", false, null)); 113 | 114 | // then 115 | String sql = new String(Files.readAllBytes(outputPath.toPath().resolve("v1__jpa2ddl.sql"))); 116 | assertThat(sql).contains("create table public.User"); 117 | assertThat(sql).doesNotContain("drop table public.User"); 118 | } 119 | 120 | @Test 121 | public void shouldGenerateDefaultSchemaUpdateWithPostgresDialect() throws Exception { 122 | // given 123 | File outputPath = tempFolder.newFolder(); 124 | 125 | Files.copy(Paths.get(getClass().getClassLoader().getResource("sample_postgres_migration/v1__jpa2ddl_init.sql").toURI()), 126 | outputPath.toPath().resolve("v1__jpa2ddl_init.sql")); 127 | 128 | Properties jpaProperties = new Properties(); 129 | jpaProperties.setProperty("hibernate.dialect", H2PostgreSQL95Dialect.class.getCanonicalName()); 130 | 131 | SchemaGenerator schemaGenerator = new SchemaGenerator(); 132 | 133 | // when 134 | schemaGenerator.generate(new GeneratorSettings(GenerationMode.DATABASE, outputPath, 135 | Arrays.asList("com.devskiller.jpa2ddl.sample"), Action.UPDATE, jpaProperties, true, ";", true, null)); 136 | 137 | // then 138 | String sql = new String(Files.readAllBytes(outputPath.toPath().resolve("v2__jpa2ddl.sql"))); 139 | assertThat(sql).containsIgnoringCase("alter table if exists User"); 140 | assertThat(sql).containsIgnoringCase("add column email"); 141 | assertThat(sql).doesNotContain("create table User"); 142 | assertThat(sql).doesNotContain("create sequence"); 143 | } 144 | 145 | @Test 146 | public void shouldGenerateSchemaFromDatabaseWithUpdateWithOracleDialect() throws Exception { 147 | // given 148 | File outputPath = tempFolder.newFolder(); 149 | Properties jpaProperties = new Properties(); 150 | jpaProperties.setProperty("hibernate.dialect", Oracle12cDialect.class.getCanonicalName()); 151 | 152 | SchemaGenerator schemaGenerator = new SchemaGenerator(); 153 | 154 | // when 155 | schemaGenerator.generate(new GeneratorSettings(GenerationMode.DATABASE, outputPath, 156 | Arrays.asList("com.devskiller.jpa2ddl.sample"), Action.UPDATE, jpaProperties, true, ";", false, null)); 157 | 158 | // then 159 | String sql = new String(Files.readAllBytes(outputPath.toPath().resolve("v1__jpa2ddl.sql"))); 160 | assertThat(sql).contains("create table User"); 161 | assertThat(sql).doesNotContain("drop table User"); 162 | } 163 | 164 | 165 | } 166 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/test/java/com/devskiller/jpa2ddl/FileResolverTest.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl; 2 | 3 | import java.io.File; 4 | import java.nio.file.Path; 5 | import java.util.List; 6 | 7 | import org.junit.Rule; 8 | import org.junit.Test; 9 | import org.junit.rules.TemporaryFolder; 10 | 11 | import static org.assertj.core.api.Assertions.assertThat; 12 | 13 | public class FileResolverTest { 14 | 15 | @Rule 16 | public TemporaryFolder tempFolder = new TemporaryFolder(); 17 | 18 | @Test 19 | public void shouldReturnExistingMigrations() throws Exception { 20 | // given 21 | File migrationsDir = tempFolder.newFolder(); 22 | 23 | Path first = migrationsDir.toPath().resolve("v1__jpa2ddl_init.sql"); 24 | first.toFile().createNewFile(); 25 | Path second = migrationsDir.toPath().resolve("v2__my_description.sql"); 26 | second.toFile().createNewFile(); 27 | Path third = migrationsDir.toPath().resolve("v3__jpa2ddl.sql"); 28 | third.toFile().createNewFile(); 29 | 30 | // when 31 | List file = FileResolver.resolveExistingMigrations(migrationsDir, false, true); 32 | 33 | // then 34 | assertThat(file).containsSequence( 35 | first, 36 | third 37 | ); 38 | } 39 | 40 | @Test 41 | public void shouldResolveFirstMigration() throws Exception { 42 | // given 43 | File migrationsDir = tempFolder.newFolder(); 44 | 45 | // when 46 | File file = FileResolver.resolveNextMigrationFile(migrationsDir); 47 | 48 | // then 49 | assertThat(file.toPath()).isEqualTo(migrationsDir.toPath().resolve("v1__jpa2ddl.sql")); 50 | } 51 | 52 | @Test 53 | public void shouldResolveNextMigration() throws Exception { 54 | // given 55 | File migrationsDir = tempFolder.newFolder(); 56 | migrationsDir.toPath().resolve("v1__jpa2ddl.sql").toFile().createNewFile(); 57 | migrationsDir.toPath().resolve("v2__my_description.sql").toFile().createNewFile(); 58 | 59 | // when 60 | File file = FileResolver.resolveNextMigrationFile(migrationsDir); 61 | 62 | // then 63 | assertThat(file.toPath()).isEqualTo(migrationsDir.toPath().resolve("v3__jpa2ddl.sql")); 64 | } 65 | 66 | } -------------------------------------------------------------------------------- /jpa2ddl-core/src/test/java/com/devskiller/jpa2ddl/MetadataSchemaGeneratorTest.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl; 2 | 3 | import java.io.File; 4 | import java.nio.file.Files; 5 | import java.util.Arrays; 6 | import java.util.Properties; 7 | 8 | import org.junit.Rule; 9 | import org.junit.Test; 10 | import org.junit.rules.TemporaryFolder; 11 | 12 | import static org.assertj.core.api.Assertions.assertThat; 13 | 14 | public class MetadataSchemaGeneratorTest { 15 | 16 | @Rule 17 | public TemporaryFolder tempFolder = new TemporaryFolder(); 18 | 19 | @Test 20 | public void shouldGenerateSchemaFromMetadataWithDropAndCreate() throws Exception { 21 | // given 22 | SchemaGenerator schemaGenerator = new SchemaGenerator(); 23 | File outputFile = tempFolder.newFile(); 24 | 25 | // when 26 | schemaGenerator.generate(new GeneratorSettings(GenerationMode.METADATA, outputFile, 27 | Arrays.asList("com.devskiller.jpa2ddl.sample"), Action.DROP_AND_CREATE, new Properties(), true, ";", false, null)); 28 | 29 | // then 30 | String sql = new String(Files.readAllBytes(outputFile.toPath())); 31 | assertThat(sql).contains("create table User"); 32 | assertThat(sql).contains("drop table if exists User"); 33 | } 34 | 35 | @Test 36 | public void shouldGenerateSchemaFromMetadataWithDrop() throws Exception { 37 | // given 38 | SchemaGenerator schemaGenerator = new SchemaGenerator(); 39 | File outputFile = tempFolder.newFile(); 40 | 41 | // when 42 | schemaGenerator.generate(new GeneratorSettings(GenerationMode.METADATA, outputFile, 43 | Arrays.asList("com.devskiller.jpa2ddl.sample"), Action.DROP, new Properties(), true, ";", false, null)); 44 | 45 | // then 46 | String sql = new String(Files.readAllBytes(outputFile.toPath())); 47 | assertThat(sql).doesNotContain("create table User"); 48 | assertThat(sql).contains("drop table if exists User"); 49 | } 50 | 51 | @Test 52 | public void shouldGenerateSchemaFromMetadataWithCreate() throws Exception { 53 | // given 54 | SchemaGenerator schemaGenerator = new SchemaGenerator(); 55 | File outputFile = tempFolder.newFile(); 56 | 57 | // when 58 | schemaGenerator.generate(new GeneratorSettings(GenerationMode.METADATA, outputFile, 59 | Arrays.asList("com.devskiller.jpa2ddl.sample"), Action.CREATE, new Properties(), true, ";", false, null)); 60 | 61 | // then 62 | String sql = new String(Files.readAllBytes(outputFile.toPath())); 63 | assertThat(sql).contains("create table User"); 64 | assertThat(sql).doesNotContain("drop table User"); 65 | } 66 | 67 | @Test 68 | public void shouldGenerateSchemaFromH2() throws Exception { 69 | 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/test/java/com/devskiller/jpa2ddl/complex/Book.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl.complex; 2 | 3 | import org.hibernate.annotations.OnDelete; 4 | import org.hibernate.annotations.OnDeleteAction; 5 | 6 | import javax.persistence.CollectionTable; 7 | import javax.persistence.ElementCollection; 8 | import javax.persistence.Entity; 9 | import javax.persistence.Id; 10 | import javax.persistence.Index; 11 | import javax.persistence.JoinColumn; 12 | import java.util.HashSet; 13 | import java.util.Set; 14 | 15 | @Entity 16 | class Book { 17 | 18 | @Id 19 | private Long id; 20 | 21 | @ElementCollection 22 | @JoinColumn 23 | @OnDelete(action = OnDeleteAction.CASCADE) 24 | @CollectionTable(indexes = {@Index(name = "fk_book_chapter", columnList = "book_id")}) 25 | public final Set chapters = new HashSet<>(); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/test/java/com/devskiller/jpa2ddl/complex/Chapter.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl.complex; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.Id; 5 | 6 | @Entity 7 | class Chapter { 8 | 9 | @Id 10 | private Long id; 11 | } 12 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/test/java/com/devskiller/jpa2ddl/sample/User.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl.sample; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.GenerationType; 6 | import javax.persistence.Id; 7 | import java.util.Date; 8 | 9 | @Entity 10 | class User { 11 | 12 | @Id 13 | @GeneratedValue(strategy = GenerationType.SEQUENCE) 14 | private long id; 15 | 16 | private Date date; 17 | 18 | private String email; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/test/resources/complex_migration/v1__jpa2ddl_init.sql: -------------------------------------------------------------------------------- 1 | drop table if exists Book CASCADE ; 2 | 3 | drop table if exists Book_Chapter CASCADE ; 4 | 5 | drop table if exists Chapter CASCADE ; 6 | 7 | create table Book ( 8 | id bigint not null, 9 | primary key (id) 10 | ); 11 | 12 | create table Book_Chapter ( 13 | Book_id bigint not null, 14 | chapters_id bigint not null, 15 | primary key (Book_id, chapters_id) 16 | ); 17 | 18 | create table Chapter ( 19 | id bigint not null, 20 | primary key (id) 21 | ); 22 | create index fk_book_chapter on Book_Chapter (Book_id); 23 | 24 | alter table Book_Chapter 25 | add constraint UK_tokwoktdrnoke2coi76lqff1s unique (chapters_id); 26 | 27 | alter table Book_Chapter 28 | add constraint FKcsndnril8gfgxo6f7osu292dr 29 | foreign key (chapters_id) 30 | references Chapter; 31 | 32 | alter table Book_Chapter 33 | add constraint FKrylp6x2fsgdveg71fhss6riby 34 | foreign key (Book_id) 35 | references Book 36 | on delete cascade; 37 | -------------------------------------------------------------------------------- /jpa2ddl-core/src/test/resources/sample_default_migration/v1__jpa2ddl_init.sql: -------------------------------------------------------------------------------- 1 | create table User ( 2 | id bigint not null, 3 | date datetime(6), 4 | primary key (id) 5 | ) engine=InnoDB; -------------------------------------------------------------------------------- /jpa2ddl-core/src/test/resources/sample_empty_migration/v1__jpa2ddl_init.sql: -------------------------------------------------------------------------------- 1 | create table User ( 2 | id bigint not null, 3 | date datetime(6), 4 | email varchar(255), 5 | primary key (id) 6 | ) engine=InnoDB; -------------------------------------------------------------------------------- /jpa2ddl-core/src/test/resources/sample_migration/v1__jpa2ddl_init.sql: -------------------------------------------------------------------------------- 1 | CREATE SCHEMA prod; 2 | 3 | create table prod.User ( 4 | id bigint not null, 5 | date datetime(6), 6 | primary key (id) 7 | ) engine=InnoDB; -------------------------------------------------------------------------------- /jpa2ddl-core/src/test/resources/sample_postgres_migration/v1__jpa2ddl_init.sql: -------------------------------------------------------------------------------- 1 | create table User ( 2 | id int8 not null, 3 | date timestamp, 4 | primary key (id) 5 | ); 6 | 7 | create sequence hibernate_sequence start 1 increment 1; -------------------------------------------------------------------------------- /jpa2ddl-gradle-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | out/ 3 | .gradle -------------------------------------------------------------------------------- /jpa2ddl-gradle-plugin/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'groovy' 3 | id 'java-gradle-plugin' 4 | } 5 | 6 | repositories { 7 | mavenLocal() 8 | mavenCentral() 9 | } 10 | 11 | group = 'com.devskiller.jpa2ddl' 12 | project.version = findProperty('jpa2ddlVersion') ?: '1.0.0-SNAPSHOT' 13 | 14 | sourceCompatibility = 1.8 15 | targetCompatibility = 1.8 16 | 17 | dependencies { 18 | compile gradleApi() 19 | compile localGroovy() 20 | compile "com.devskiller.jpa2ddl:jpa2ddl-core:${findProperty('jpa2ddlVersion') ?: '+'}" 21 | testCompile gradleTestKit() 22 | testCompile 'junit:junit:4.12' 23 | testCompile 'org.assertj:assertj-core:3.8.0' 24 | } 25 | 26 | task sourcesJar(type: Jar, dependsOn: classes) { 27 | classifier = 'sources' 28 | from sourceSets.main.allSource 29 | } 30 | 31 | task javadocJar(type: Jar, dependsOn: javadoc) { 32 | classifier = 'javadoc' 33 | from javadoc.destinationDir 34 | } 35 | 36 | task groovydocJar(type: Jar, dependsOn: groovydoc) { 37 | classifier = 'groovydoc' 38 | from groovydoc.destinationDir 39 | } 40 | 41 | artifacts { 42 | archives sourcesJar 43 | archives javadocJar 44 | archives groovydocJar 45 | } 46 | 47 | wrapper { 48 | gradleVersion = '6.3' 49 | } -------------------------------------------------------------------------------- /jpa2ddl-gradle-plugin/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.daemon=false -------------------------------------------------------------------------------- /jpa2ddl-gradle-plugin/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Devskiller/jpa2ddl/4652c4ecdc68d2aba31467a2c00279ed5fd3724d/jpa2ddl-gradle-plugin/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /jpa2ddl-gradle-plugin/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip 6 | -------------------------------------------------------------------------------- /jpa2ddl-gradle-plugin/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /jpa2ddl-gradle-plugin/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /jpa2ddl-gradle-plugin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | com.devskiller.jpa2ddl 7 | jpa2ddl-parent 8 | 0.10.1-SNAPSHOT 9 | 10 | 11 | jpa2ddl-gradle-plugin 12 | 13 | ${project.artifactId} 14 | jpa2ddl Gradle Plugin 15 | 16 | pom 17 | 18 | 19 | ./ 20 | 21 | 22 | 23 | 24 | com.devskiller.jpa2ddl 25 | jpa2ddl-core 26 | ${project.version} 27 | 28 | 29 | 30 | 31 | 32 | 33 | org.apache.maven.plugins 34 | maven-clean-plugin 35 | 3.0.0 36 | 37 | 38 | 39 | build 40 | 41 | 42 | target 43 | 44 | 45 | 46 | 47 | 48 | org.codehaus.mojo 49 | exec-maven-plugin 50 | 1.6.0 51 | 52 | 53 | gradle 54 | package 55 | 56 | ${script.prefix}gradlew 57 | 58 | clean 59 | build 60 | -Pjpa2ddlVersion=${project.version} 61 | 62 | 63 | 64 | exec 65 | 66 | 67 | 68 | 69 | 70 | org.codehaus.mojo 71 | build-helper-maven-plugin 72 | 1.12 73 | 74 | 75 | attach-artifacts 76 | package 77 | 78 | attach-artifact 79 | 80 | 81 | 82 | 83 | build/libs/${project.artifactId}-${project.version}.jar 84 | jar 85 | 86 | 87 | build/libs/${project.artifactId}-${project.version}-groovydoc.jar 88 | jar 89 | groovydoc 90 | 91 | 92 | build/libs/${project.artifactId}-${project.version}-javadoc.jar 93 | jar 94 | javadoc 95 | 96 | 97 | build/libs/${project.artifactId}-${project.version}-sources.jar 98 | jar 99 | sources 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | windows 112 | 113 | 114 | windows 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /jpa2ddl-gradle-plugin/src/main/java/com/devskiller/jpa2ddl/GeneratePlugin.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl; 2 | 3 | import java.io.File; 4 | import java.util.HashMap; 5 | import java.util.HashSet; 6 | import java.util.Set; 7 | 8 | import org.gradle.api.Plugin; 9 | import org.gradle.api.Project; 10 | import org.gradle.api.internal.file.UnionFileCollection; 11 | import org.gradle.api.plugins.BasePlugin; 12 | import org.gradle.api.plugins.JavaBasePlugin; 13 | import org.gradle.api.tasks.SourceSet; 14 | import org.gradle.api.tasks.SourceSetContainer; 15 | 16 | class GeneratePlugin implements Plugin { 17 | 18 | private static final String EXTENSION_NAME = "jpa2ddl"; 19 | private static final String TASK_NAME = "generateDdl"; 20 | 21 | @Override 22 | public void apply(Project project) { 23 | GeneratePluginExtension generatePluginExtension = project.getExtensions().create(EXTENSION_NAME, 24 | GeneratePluginExtension.class, project); 25 | 26 | GenerateTask generateTask = project.getTasks().create(TASK_NAME, GenerateTask.class); 27 | generateTask.setGroup(BasePlugin.BUILD_GROUP); 28 | generateTask.setDescription("Generates DDL scripts based on JPA model."); 29 | generateTask.setExtension(generatePluginExtension); 30 | generateTask.dependsOn(JavaBasePlugin.BUILD_TASK_NAME); 31 | 32 | 33 | project.afterEvaluate(evaluatedProject -> { 34 | fillDefaults(evaluatedProject, generatePluginExtension); 35 | SourceSetContainer sourceSets = (SourceSetContainer) project.getProperties().get("sourceSets"); 36 | Set paths; 37 | if (sourceSets != null) { 38 | UnionFileCollection mainClasspath = (UnionFileCollection) sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath(); 39 | paths = mainClasspath.getFiles(); 40 | } else { 41 | paths = new HashSet<>(); 42 | } 43 | generateTask.setOutputClassesDirs(paths); 44 | }); 45 | } 46 | 47 | private void fillDefaults(Project project, GeneratePluginExtension generatePluginExtension) { 48 | if (!generatePluginExtension.getPackagesProvider().isPresent()) { 49 | throw new IllegalArgumentException("JPA2DDL: No packages property found - it must point to model packages"); 50 | } 51 | if (!generatePluginExtension.getActionProvider().isPresent()) { 52 | generatePluginExtension.setAction(Action.CREATE); 53 | } 54 | if (!generatePluginExtension.getGenerationModeProvider().isPresent()) { 55 | generatePluginExtension.setGenerationMode(GenerationMode.DATABASE); 56 | } 57 | if (!generatePluginExtension.getDelimiterProvider().isPresent()) { 58 | generatePluginExtension.setDelimiter(";"); 59 | } 60 | if (!generatePluginExtension.getFormatOutputProvider().isPresent()) { 61 | generatePluginExtension.setFormatOutput(true); 62 | } 63 | if (!generatePluginExtension.getSkipSequencesProvider().isPresent()) { 64 | generatePluginExtension.setSkipSequences(false); 65 | } 66 | if (!generatePluginExtension.getJpaPropertiesProvider().isPresent()) { 67 | generatePluginExtension.setJpaProperties(new HashMap<>()); 68 | } 69 | if (!generatePluginExtension.getOutputPathProvider().isPresent()) { 70 | String filePath = generatePluginExtension.getAction() == Action.UPDATE ? "scripts/" : "scripts/database.sql"; 71 | generatePluginExtension.setOutputPath(project.getBuildDir().toPath().resolve("generated-resources/main/" + filePath).toFile()); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /jpa2ddl-gradle-plugin/src/main/java/com/devskiller/jpa2ddl/GeneratePluginExtension.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl; 2 | 3 | import org.gradle.api.Project; 4 | import org.gradle.api.file.RegularFileProperty; 5 | import org.gradle.api.provider.ListProperty; 6 | import org.gradle.api.provider.MapProperty; 7 | import org.gradle.api.provider.Property; 8 | import org.gradle.api.provider.Provider; 9 | 10 | import java.io.File; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | public class GeneratePluginExtension { 15 | 16 | private final RegularFileProperty outputPath; 17 | private final Property generationMode; 18 | private final ListProperty packages; 19 | private final Property action; 20 | private final MapProperty jpaProperties; 21 | private final Property formatOutput; 22 | private final Property skipSequences; 23 | private final Property delimiter; 24 | private final MapProperty processorProperties; 25 | 26 | public GeneratePluginExtension(Project project) { 27 | outputPath = project.getObjects().fileProperty(); 28 | generationMode = project.getObjects().property(GenerationMode.class); 29 | packages = project.getObjects().listProperty(String.class); 30 | action = project.getObjects().property(Action.class); 31 | jpaProperties = project.getObjects().mapProperty(String.class, String.class); 32 | formatOutput = project.getObjects().property(Boolean.class); 33 | skipSequences = project.getObjects().property(Boolean.class); 34 | delimiter = project.getObjects().property(String.class); 35 | processorProperties = project.getObjects().mapProperty(String.class, String.class); 36 | } 37 | 38 | public File getOutputPath() { 39 | return outputPath.getAsFile().get(); 40 | } 41 | 42 | public void setOutputPath(File outputPath) { 43 | this.outputPath.set(outputPath); 44 | } 45 | 46 | public GenerationMode getGenerationMode() { 47 | return generationMode.get(); 48 | } 49 | 50 | public void setGenerationMode(GenerationMode generationMode) { 51 | this.generationMode.set(generationMode); 52 | } 53 | 54 | public List getPackages() { 55 | return packages.get(); 56 | } 57 | 58 | public void setPackages(List packages) { 59 | this.packages.set(packages); 60 | } 61 | 62 | public Action getAction() { 63 | return action.get(); 64 | } 65 | 66 | public void setAction(Action action) { 67 | this.action.set(action); 68 | } 69 | 70 | public Map getJpaProperties() { 71 | return jpaProperties.get(); 72 | } 73 | 74 | public void setJpaProperties(Map jpaProperties) { 75 | this.jpaProperties.set(jpaProperties); 76 | } 77 | 78 | public Boolean getFormatOutput() { 79 | return formatOutput.get(); 80 | } 81 | 82 | public void setFormatOutput(Boolean formatOutput) { 83 | this.formatOutput.set(formatOutput); 84 | } 85 | 86 | public Boolean getSkipSequences() { 87 | return skipSequences.get(); 88 | } 89 | 90 | public void setSkipSequences(Boolean skipSequences) { 91 | this.skipSequences.set(skipSequences); 92 | } 93 | 94 | public String getDelimiter() { 95 | return delimiter.get(); 96 | } 97 | 98 | public void setDelimiter(String delimiter) { 99 | this.delimiter.set(delimiter); 100 | } 101 | 102 | public Map getProcessorProperties() { 103 | return processorProperties.get(); 104 | } 105 | 106 | public void setProcessorProperties(Map processorProperties) { 107 | this.processorProperties.set(processorProperties); 108 | } 109 | 110 | public Provider getOutputPathProvider() { 111 | return outputPath.getAsFile(); 112 | } 113 | 114 | public Provider getGenerationModeProvider() { 115 | return generationMode; 116 | } 117 | 118 | public Provider> getPackagesProvider() { 119 | return packages; 120 | } 121 | 122 | public Provider getActionProvider() { 123 | return action; 124 | } 125 | 126 | public Provider> getJpaPropertiesProvider() { 127 | return jpaProperties; 128 | } 129 | 130 | public Provider> getProcessorPropertiesProvider() { 131 | return processorProperties; 132 | } 133 | 134 | public Provider getFormatOutputProvider() { 135 | return formatOutput; 136 | } 137 | 138 | public Provider getSkipSequencesProvider() { 139 | return skipSequences; 140 | } 141 | 142 | public Provider getDelimiterProvider() { 143 | return delimiter; 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /jpa2ddl-gradle-plugin/src/main/java/com/devskiller/jpa2ddl/GenerateTask.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl; 2 | 3 | import java.io.File; 4 | import java.net.MalformedURLException; 5 | import java.net.URL; 6 | import java.net.URLClassLoader; 7 | import java.util.Map; 8 | import java.util.Properties; 9 | import java.util.Set; 10 | 11 | import org.gradle.api.DefaultTask; 12 | import org.gradle.api.tasks.Input; 13 | import org.gradle.api.tasks.TaskAction; 14 | 15 | public class GenerateTask extends DefaultTask { 16 | 17 | private GeneratePluginExtension extension; 18 | private Set outputClassesDirs; 19 | 20 | void setExtension(GeneratePluginExtension extension) { 21 | this.extension = extension; 22 | } 23 | 24 | @TaskAction 25 | public void generateModel() throws Exception { 26 | getLogger().info("Running schema generation..."); 27 | GeneratorSettings settings = getSettings(); 28 | URL[] urls = outputClassesDirs.stream() 29 | .map(path -> { 30 | try { 31 | return path.toURI().toURL(); 32 | } catch (MalformedURLException e) { 33 | throw new IllegalStateException("Cannot build URL from sourceSets", e); 34 | } 35 | }) 36 | .toArray(URL[]::new); 37 | ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); 38 | URLClassLoader urlClassLoader = new URLClassLoader(urls, originalClassLoader); 39 | Thread.currentThread().setContextClassLoader(urlClassLoader); 40 | new SchemaGenerator().generate(settings); 41 | Thread.currentThread().setContextClassLoader(originalClassLoader); 42 | getLogger().info("Schema saved to " + extension.getOutputPath()); 43 | } 44 | 45 | @Input 46 | GeneratorSettings getSettings() { 47 | return new GeneratorSettings(extension.getGenerationMode(), 48 | extension.getOutputPath(), 49 | extension.getPackages(), 50 | extension.getAction(), 51 | convertToProperties(extension.getJpaProperties()), 52 | extension.getFormatOutput(), 53 | extension.getDelimiter(), 54 | extension.getSkipSequences(), 55 | convertToProperties(extension.getProcessorProperties())); 56 | } 57 | 58 | public void setOutputClassesDirs(Set outputClassesDirs) { 59 | this.outputClassesDirs = outputClassesDirs; 60 | } 61 | 62 | private Properties convertToProperties(Map map) { 63 | Properties props = new Properties(); 64 | for (String key : map.keySet()) { 65 | props.setProperty(key, map.get(key)); 66 | } 67 | return props; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /jpa2ddl-gradle-plugin/src/main/resources/META-INF/gradle-plugins/com.devskiller.jpa2ddl.properties: -------------------------------------------------------------------------------- 1 | implementation-class=com.devskiller.jpa2ddl.GeneratePlugin -------------------------------------------------------------------------------- /jpa2ddl-gradle-plugin/src/test/groovy/com/devskiller/jpa2ddl/GeneratePluginTest.groovy: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl 2 | 3 | import java.nio.file.Files 4 | 5 | import org.gradle.api.Project 6 | import org.gradle.api.internal.project.ProjectInternal 7 | import org.gradle.testfixtures.ProjectBuilder 8 | import org.junit.Rule 9 | import org.junit.Test 10 | import org.junit.rules.TemporaryFolder 11 | 12 | import static org.assertj.core.api.Assertions.assertThat 13 | 14 | class GeneratePluginTest { 15 | 16 | @Rule 17 | public final TemporaryFolder testProjectDir = new TemporaryFolder() 18 | 19 | @Test 20 | void shouldAddTaskToProject() { 21 | File buildFile = testProjectDir.newFile("build.gradle") 22 | 23 | Files.write(buildFile.toPath(), "jpa2ddl {packages=['com.test']\njpaProperties=['hibernate.dialect':'org.hibernate.dialect.H2Dialect']}".getBytes()) 24 | 25 | Project project = ProjectBuilder.builder() 26 | .withProjectDir(testProjectDir.getRoot()) 27 | .build() 28 | 29 | project.pluginManager.apply 'com.devskiller.jpa2ddl' 30 | 31 | ((ProjectInternal) project).evaluate() 32 | 33 | GenerateTask task = (GenerateTask) project.tasks.generateDdl 34 | 35 | GeneratorSettings settings = task.getSettings() 36 | assertThat(settings.getAction()).isEqualTo(Action.CREATE) 37 | assertThat(settings.getDelimiter()).isEqualTo(";") 38 | assertThat(settings.getGenerationMode()).isEqualTo(GenerationMode.DATABASE) 39 | assertThat(settings.getJpaProperties()).contains(new MapEntry("hibernate.dialect", "org.hibernate.dialect.H2Dialect")) 40 | assertThat(settings.getPackages()).containsOnly("com.test") 41 | // assertThat(settings.getOutputPath()).isEqualTo(testProjectDir.getRoot().toPath().resolve("build/generated-resources/main/scripts/database.sql").toFile()) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /jpa2ddl-maven-plugin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | com.devskiller.jpa2ddl 7 | jpa2ddl-parent 8 | 0.10.1-SNAPSHOT 9 | 10 | 11 | jpa2ddl-maven-plugin 12 | 13 | ${project.artifactId} 14 | jpa2ddl Maven Plugin 15 | 16 | takari-maven-plugin 17 | 18 | 19 | 3.6.3 20 | 3.6.0 21 | 2.9.2 22 | 23 | 24 | 25 | 26 | com.devskiller.jpa2ddl 27 | jpa2ddl-core 28 | ${project.version} 29 | 30 | 31 | 32 | org.apache.maven 33 | maven-plugin-api 34 | ${mavenVersion} 35 | provided 36 | 37 | 38 | org.apache.maven.plugin-tools 39 | maven-plugin-annotations 40 | ${mavenPluginVersion} 41 | provided 42 | 43 | 44 | org.apache.maven 45 | maven-core 46 | ${mavenVersion} 47 | provided 48 | 49 | 50 | 51 | 52 | junit 53 | junit 54 | test 55 | 56 | 57 | org.apache.maven 58 | maven-compat 59 | ${mavenVersion} 60 | test 61 | 62 | 63 | io.takari.maven.plugins 64 | takari-plugin-testing 65 | ${it-project.version} 66 | test 67 | 68 | 69 | org.assertj 70 | assertj-core 71 | test 72 | 73 | 74 | 75 | 76 | 77 | 78 | io.takari.maven.plugins 79 | takari-lifecycle-plugin 80 | 2.0.0 81 | true 82 | 83 | none 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /jpa2ddl-maven-plugin/src/main/java/com/devskiller/jpa2ddl/GenerateMojo.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl; 2 | 3 | import java.io.File; 4 | import java.net.MalformedURLException; 5 | import java.net.URL; 6 | import java.nio.file.Paths; 7 | import java.util.List; 8 | import java.util.Properties; 9 | 10 | import org.apache.maven.artifact.DependencyResolutionRequiredException; 11 | import org.apache.maven.model.Dependency; 12 | import org.apache.maven.plugin.AbstractMojo; 13 | import org.apache.maven.plugin.MojoExecutionException; 14 | import org.apache.maven.plugin.MojoFailureException; 15 | import org.apache.maven.plugin.descriptor.PluginDescriptor; 16 | import org.apache.maven.plugins.annotations.LifecyclePhase; 17 | import org.apache.maven.plugins.annotations.Mojo; 18 | import org.apache.maven.plugins.annotations.Parameter; 19 | import org.apache.maven.plugins.annotations.ResolutionScope; 20 | import org.apache.maven.project.MavenProject; 21 | 22 | import static java.util.Objects.isNull; 23 | 24 | /** 25 | * Goal to generate database schema based on the JPA entities 26 | */ 27 | @Mojo(name = "generate", defaultPhase = LifecyclePhase.PROCESS_CLASSES, requiresDependencyResolution = ResolutionScope.COMPILE) 28 | public class GenerateMojo extends AbstractMojo { 29 | 30 | /** 31 | * Output path for the generated schema. 32 | */ 33 | @Parameter 34 | private File outputPath; 35 | 36 | /** 37 | * List of packages containing JPA entities 38 | */ 39 | @Parameter(required = true) 40 | private List packages; 41 | 42 | /** 43 | * Additional properties like dialect or naming strategies which should be used in generation task 44 | */ 45 | @Parameter 46 | private Properties jpaProperties; 47 | 48 | /** 49 | * Should we format the output 50 | */ 51 | @Parameter(defaultValue = "true") 52 | private boolean formatOutput; 53 | 54 | /** 55 | * Should we skip sequence generation 56 | */ 57 | @Parameter(defaultValue = "false") 58 | private boolean skipSequences; 59 | 60 | /** 61 | * Delimiter used to separate statements 62 | */ 63 | @Parameter(defaultValue = ";") 64 | private String delimiter; 65 | 66 | /** 67 | * Action describing which statements should be generated. Possible values: 68 | * CREATE 69 | * DROP 70 | * DROP_AND_CREATE 71 | * UPDATE 72 | */ 73 | @Parameter(defaultValue = "CREATE") 74 | private Action action; 75 | 76 | /** 77 | * Schema generation mode. Possible values: 78 | * DATABASE - Default - generation based on setting up embedded database and dumping the schema. 79 | * METADATA - generation based on static metadata 80 | */ 81 | @Parameter(defaultValue = "DATABASE") 82 | private GenerationMode generationMode; 83 | 84 | /** 85 | * Additional properties for external processors 86 | */ 87 | @Parameter 88 | private Properties processorProperties; 89 | 90 | @Parameter(defaultValue = "${project}", readonly = true) 91 | private MavenProject project; 92 | 93 | @Parameter(defaultValue = "${plugin}", readonly = true) 94 | private PluginDescriptor descriptor; 95 | 96 | public void execute() throws MojoExecutionException { 97 | getLog().info("Running schema generation..."); 98 | if (isNull(jpaProperties)) { 99 | jpaProperties = new Properties(); 100 | } 101 | 102 | if (outputPath == null) { 103 | if (action == Action.UPDATE) { 104 | outputPath = Paths.get(project.getBuild().getDirectory()).resolve("generated-resources/scripts").toFile(); 105 | } else { 106 | outputPath = Paths.get(project.getBuild().getDirectory()).resolve("generated-resources/scripts/database.sql").toFile(); 107 | } 108 | } 109 | 110 | SchemaGenerator schemaGenerator = new SchemaGenerator(); 111 | List compileSourceRoots = project.getCompileSourceRoots(); 112 | compileSourceRoots.stream().map(this::mapPathToURL).forEach(url -> descriptor.getClassRealm().addURL(url)); 113 | try { 114 | project.getCompileClasspathElements().stream().map(this::mapPathToURL).forEach(url -> descriptor.getClassRealm().addURL(url)); 115 | } catch (DependencyResolutionRequiredException e) { 116 | throw new IllegalStateException(e); 117 | } 118 | 119 | GeneratorSettings settings = new GeneratorSettings( 120 | generationMode, outputPath, packages, action, jpaProperties, formatOutput, delimiter, skipSequences, processorProperties); 121 | try { 122 | schemaGenerator.generate(settings); 123 | getLog().info("Schema saved to " + outputPath); 124 | } catch (Exception e) { 125 | throw new MojoExecutionException(e.getMessage(), e); 126 | } 127 | } 128 | 129 | private URL mapPathToURL(String path) { 130 | try { 131 | return Paths.get(path).toUri().toURL(); 132 | } catch (MalformedURLException e) { 133 | throw new IllegalStateException(e); 134 | } 135 | } 136 | 137 | List getPackages() { 138 | return packages; 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /jpa2ddl-maven-plugin/src/main/resources/META-INF/plexus/components.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | org.apache.maven.lifecycle.Lifecycle 6 | org.apache.maven.lifecycle.Lifecycle 7 | jpa2ddl 8 | 9 | jpa2ddl 10 | 11 | 12 | com.devskiller.jpa2ddl:jpa2ddl-maven-plugin:${project.version}:generate 13 | 14 | 15 | 16 | 17 | com.devskiller.jpa2ddl:jpa2ddl-maven-plugin:${project.version}:generate 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /jpa2ddl-maven-plugin/src/test/java/com/devskiller/jpa2ddl/GenerateMojoTest.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl; 2 | 3 | import java.io.File; 4 | 5 | import io.takari.maven.testing.TestMavenRuntime; 6 | import io.takari.maven.testing.TestResources; 7 | import org.junit.Rule; 8 | import org.junit.Test; 9 | 10 | import static org.assertj.core.api.Assertions.assertThat; 11 | 12 | public class GenerateMojoTest { 13 | 14 | @Rule 15 | public final TestResources resources = new TestResources(); 16 | 17 | @Rule 18 | public final TestMavenRuntime maven = new TestMavenRuntime(); 19 | 20 | @Test 21 | public void testBasic() throws Exception { 22 | File basedir = resources.getBasedir("basic"); 23 | GenerateMojo generate = (GenerateMojo) maven.lookupConfiguredMojo(maven.newMavenSession(maven.readMavenProject(basedir)), maven.newMojoExecution("generate")); 24 | assertThat(generate.getPackages()).containsOnly("com.test.model"); 25 | } 26 | 27 | @Test 28 | public void testFull() throws Exception { 29 | File basedir = resources.getBasedir("full"); 30 | GenerateMojo generate = (GenerateMojo) maven.lookupConfiguredMojo(maven.newMavenSession(maven.readMavenProject(basedir)), maven.newMojoExecution("generate")); 31 | assertThat(generate.getPackages()).containsOnly("com.test.model", "com.test.entities"); 32 | } 33 | } -------------------------------------------------------------------------------- /jpa2ddl-maven-plugin/src/test/projects/basic/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.devskiller.jpa2ddl 7 | sample-project 8 | 0.1 9 | 10 | 11 | 12 | 13 | com.devskiller.jpa2ddl 14 | jpa2ddl-maven-plugin 15 | 16 | 17 | com.test.model 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /jpa2ddl-maven-plugin/src/test/projects/full/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.devskiller.jpa2ddl 7 | sample-project 8 | 0.1 9 | 10 | 11 | 12 | 13 | com.devskiller.jpa2ddl 14 | jpa2ddl-maven-plugin 15 | 16 | mydb.sql 17 | 18 | com.test.model 19 | com.test.entities 20 | 21 | 22 | 23 | hibernate.dialect 24 | org.hibernate.dialect.MySQL57Dialect 25 | 26 | 27 | true 28 | ; 29 | DROP_AND_CREATE 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /jpa2ddl-querydsl-processor/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | com.devskiller.jpa2ddl 7 | jpa2ddl-parent 8 | 0.10.1-SNAPSHOT 9 | 10 | 11 | jpa2ddl-querydsl-processor 12 | 13 | ${project.artifactId} 14 | jpa2ddl QuerySQL Processor 15 | 16 | jar 17 | 18 | 19 | 20 | com.devskiller.jpa2ddl 21 | jpa2ddl-core 22 | ${project.version} 23 | 24 | 25 | com.querydsl 26 | querydsl-sql-codegen 27 | 4.4.0 28 | 29 | 30 | javax.annotation 31 | javax.annotation-api 32 | 1.3.1 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /jpa2ddl-querydsl-processor/src/main/java/com/devskiller/jpa2ddl/querydsl/QueryDslSchemaProcessor.java: -------------------------------------------------------------------------------- 1 | package com.devskiller.jpa2ddl.querydsl; 2 | 3 | import com.devskiller.jpa2ddl.SchemaProcessor; 4 | import com.querydsl.sql.codegen.MetaDataExporter; 5 | 6 | import java.io.File; 7 | import java.sql.Connection; 8 | import java.sql.DatabaseMetaData; 9 | import java.sql.SQLException; 10 | import java.util.Properties; 11 | 12 | public class QueryDslSchemaProcessor implements SchemaProcessor { 13 | 14 | @Override 15 | public void postProcess(Connection connection, Properties properties) { 16 | String queryDslOutputPath = properties.getProperty("queryDslOutputPath"); 17 | String queryDslOutputPackage = properties.getProperty("queryDslOutputPackage"); 18 | 19 | if (queryDslOutputPath == null || queryDslOutputPath.length() == 0) { 20 | throw new IllegalArgumentException("queryDslOutputPath must be set"); 21 | } 22 | 23 | try { 24 | DatabaseMetaData metaData = connection.getMetaData(); 25 | MetaDataExporter metaDataExporter = new MetaDataExporter(); 26 | metaDataExporter.setTargetFolder(new File(queryDslOutputPath)); 27 | if (queryDslOutputPackage != null) { 28 | metaDataExporter.setPackageName(queryDslOutputPackage); 29 | } 30 | metaDataExporter.export(metaData); 31 | } catch (SQLException e) { 32 | throw new IllegalStateException(e); 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /jpa2ddl-samples/jpa2ddl-flyway-maven-sample/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Devskiller/jpa2ddl/4652c4ecdc68d2aba31467a2c00279ed5fd3724d/jpa2ddl-samples/jpa2ddl-flyway-maven-sample/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /jpa2ddl-samples/jpa2ddl-flyway-maven-sample/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip -------------------------------------------------------------------------------- /jpa2ddl-samples/jpa2ddl-flyway-maven-sample/README.md: -------------------------------------------------------------------------------- 1 | # Flyway with Maven sample 2 | 3 | This project shows a sample setup for Flyway migrations based on Maven. 4 | 5 | The existing DB schema can be found in the `src/main/resources/migrations/v1_jpa2ddl.sql` file. 6 | 7 | It's already been applied in an h2 database located in the `src/main/resources/db` directory. 8 | 9 | There is already a modified `oss.devskiller.model.User` entity which contains two additional fields: `email` and `age`. 10 | 11 | Now we want to generate the migration script and apply it to the database. 12 | 13 | ## Schema migration with JPA2DDL and Flyway 14 | 15 | The first step you need to take is to build the project. 16 | It can be done with the `./mvnw clean package` command. 17 | As you can see, a new migration file has been created: `v2_jpa2ddl.sql`. 18 | It contains alter statements which add two new fields. 19 | 20 | We can check Flyway migrations status with command `./mvnw flyway:info` 21 | 22 | ``` 23 | +-----------+---------+-------------+------+---------------------+---------+ 24 | | Category | Version | Description | Type | Installed On | State | 25 | +-----------+---------+-------------+------+---------------------+---------+ 26 | | Versioned | 1 | jpa2ddl | SQL | 2018-03-14 16:43:23 | Success | 27 | | Versioned | 2 | jpa2ddl | SQL | | Pending | 28 | +-----------+---------+-------------+------+---------------------+---------+ 29 | ``` 30 | 31 | As you can see, Flyway has found the new migration and it's ready to be applied. 32 | To do so, simply invoke `./mvnw flyway:migrate`. Flyway will now migrate the database schema: 33 | 34 | ``` 35 | [INFO] Successfully validated 2 migrations (execution time 00:00.011s) 36 | [INFO] Current version of schema "PUBLIC": 1 37 | [INFO] Migrating schema "PUBLIC" to version 2 - jpa2ddl 38 | [INFO] Successfully applied 1 migration to schema "PUBLIC" (execution time 00:00.027s) 39 | ``` 40 | 41 | Now you can check if everything has finished correctly by checking the info one more time: 42 | 43 | ``` 44 | +-----------+---------+-------------+------+---------------------+---------+ 45 | | Category | Version | Description | Type | Installed On | State | 46 | +-----------+---------+-------------+------+---------------------+---------+ 47 | | Versioned | 1 | jpa2ddl | SQL | 2018-03-14 16:43:23 | Success | 48 | | Versioned | 2 | jpa2ddl | SQL | 2018-03-14 16:52:35 | Success | 49 | +-----------+---------+-------------+------+---------------------+---------+ 50 | ``` -------------------------------------------------------------------------------- /jpa2ddl-samples/jpa2ddl-flyway-maven-sample/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | if [ "$MVNW_VERBOSE" = true ]; then 205 | echo $MAVEN_PROJECTBASEDIR 206 | fi 207 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 208 | 209 | # For Cygwin, switch paths to Windows format before running java 210 | if $cygwin; then 211 | [ -n "$M2_HOME" ] && 212 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 213 | [ -n "$JAVA_HOME" ] && 214 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 215 | [ -n "$CLASSPATH" ] && 216 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 217 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 218 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 219 | fi 220 | 221 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 222 | 223 | exec "$JAVACMD" \ 224 | $MAVEN_OPTS \ 225 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 226 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 227 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 228 | -------------------------------------------------------------------------------- /jpa2ddl-samples/jpa2ddl-flyway-maven-sample/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /jpa2ddl-samples/jpa2ddl-flyway-maven-sample/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | com.devskiller.jpa2ddl 7 | jpa2ddl-samples 8 | 0.9.17-SNAPSHOT 9 | 10 | 11 | jpa2ddl-flyway-maven-sample 12 | 13 | ${project.artifactId} 14 | jpa2ddl flyway with maven sample 15 | 16 | 17 | 1.8 18 | 1.8 19 | UTF-8 20 | 7.0 21 | 5.4.23.Final 22 | 23 | ${basedir}/src/main/resources/migrations/ 24 | ${basedir}/src/main/resources/db/flyway 25 | 26 | 27 | 28 | 29 | javax 30 | javaee-api 31 | ${javaee-api-version} 32 | compile 33 | 34 | 35 | 36 | org.hibernate 37 | hibernate-core 38 | ${hibernate-version} 39 | 40 | 41 | 42 | 43 | 44 | 45 | com.devskiller.jpa2ddl 46 | jpa2ddl-maven-plugin 47 | ${project.version} 48 | 49 | 50 | generate 51 | 52 | generate 53 | 54 | 55 | 56 | 57 | 58 | oss.devskiller.model 59 | 60 | ${migrations-dir} 61 | UPDATE 62 | 63 | 64 | 65 | 66 | org.flywaydb 67 | flyway-maven-plugin 68 | 5.0.7 69 | 70 | org.h2.Driver 71 | jdbc:h2:file:${db-file} 72 | 73 | filesystem:${migrations-dir} 74 | 75 | v 76 | 77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /jpa2ddl-samples/jpa2ddl-flyway-maven-sample/src/main/java/oss/devskiller/model/User.java: -------------------------------------------------------------------------------- 1 | package oss.devskiller.model; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.Id; 5 | 6 | @Entity 7 | class User { 8 | 9 | @Id 10 | private Long id; 11 | 12 | private String name; 13 | 14 | private String email; 15 | 16 | private int age; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /jpa2ddl-samples/jpa2ddl-flyway-maven-sample/src/main/resources/db/flyway.mv.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Devskiller/jpa2ddl/4652c4ecdc68d2aba31467a2c00279ed5fd3724d/jpa2ddl-samples/jpa2ddl-flyway-maven-sample/src/main/resources/db/flyway.mv.db -------------------------------------------------------------------------------- /jpa2ddl-samples/jpa2ddl-flyway-maven-sample/src/main/resources/migrations/v1__jpa2ddl.sql: -------------------------------------------------------------------------------- 1 | 2 | create table User ( 3 | id bigint not null, 4 | name varchar(255), 5 | primary key (id) 6 | ); 7 | -------------------------------------------------------------------------------- /jpa2ddl-samples/jpa2ddl-querydsl-maven-sample/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Devskiller/jpa2ddl/4652c4ecdc68d2aba31467a2c00279ed5fd3724d/jpa2ddl-samples/jpa2ddl-querydsl-maven-sample/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /jpa2ddl-samples/jpa2ddl-querydsl-maven-sample/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip -------------------------------------------------------------------------------- /jpa2ddl-samples/jpa2ddl-querydsl-maven-sample/README.md: -------------------------------------------------------------------------------- 1 | # Flyway with Maven sample 2 | 3 | This project shows a sample setup for Flyway migrations based on Maven. 4 | 5 | The existing DB schema can be found in the `src/main/resources/migrations/v1_jpa2ddl.sql` file. 6 | 7 | It's already been applied in an h2 database located in the `src/main/resources/db` directory. 8 | 9 | There is already a modified `oss.devskiller.model.User` entity which contains two additional fields: `email` and `age`. 10 | 11 | Now we want to generate the migration script and apply it to the database. 12 | 13 | ## Schema migration with JPA2DDL and Flyway 14 | 15 | The first step you need to take is to build the project. 16 | It can be done with the `./mvnw clean package` command. 17 | As you can see, a new migration file has been created: `v2_jpa2ddl.sql`. 18 | It contains alter statements which add two new fields. 19 | 20 | We can check Flyway migrations status with command `./mvnw flyway:info` 21 | 22 | ``` 23 | +-----------+---------+-------------+------+---------------------+---------+ 24 | | Category | Version | Description | Type | Installed On | State | 25 | +-----------+---------+-------------+------+---------------------+---------+ 26 | | Versioned | 1 | jpa2ddl | SQL | 2018-03-14 16:43:23 | Success | 27 | | Versioned | 2 | jpa2ddl | SQL | | Pending | 28 | +-----------+---------+-------------+------+---------------------+---------+ 29 | ``` 30 | 31 | As you can see, Flyway has found the new migration and it's ready to be applied. 32 | To do so, simply invoke `./mvnw flyway:migrate`. Flyway will now migrate the database schema: 33 | 34 | ``` 35 | [INFO] Successfully validated 2 migrations (execution time 00:00.011s) 36 | [INFO] Current version of schema "PUBLIC": 1 37 | [INFO] Migrating schema "PUBLIC" to version 2 - jpa2ddl 38 | [INFO] Successfully applied 1 migration to schema "PUBLIC" (execution time 00:00.027s) 39 | ``` 40 | 41 | Now you can check if everything has finished correctly by checking the info one more time: 42 | 43 | ``` 44 | +-----------+---------+-------------+------+---------------------+---------+ 45 | | Category | Version | Description | Type | Installed On | State | 46 | +-----------+---------+-------------+------+---------------------+---------+ 47 | | Versioned | 1 | jpa2ddl | SQL | 2018-03-14 16:43:23 | Success | 48 | | Versioned | 2 | jpa2ddl | SQL | 2018-03-14 16:52:35 | Success | 49 | +-----------+---------+-------------+------+---------------------+---------+ 50 | ``` -------------------------------------------------------------------------------- /jpa2ddl-samples/jpa2ddl-querydsl-maven-sample/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | if [ "$MVNW_VERBOSE" = true ]; then 205 | echo $MAVEN_PROJECTBASEDIR 206 | fi 207 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 208 | 209 | # For Cygwin, switch paths to Windows format before running java 210 | if $cygwin; then 211 | [ -n "$M2_HOME" ] && 212 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 213 | [ -n "$JAVA_HOME" ] && 214 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 215 | [ -n "$CLASSPATH" ] && 216 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 217 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 218 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 219 | fi 220 | 221 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 222 | 223 | exec "$JAVACMD" \ 224 | $MAVEN_OPTS \ 225 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 226 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 227 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 228 | -------------------------------------------------------------------------------- /jpa2ddl-samples/jpa2ddl-querydsl-maven-sample/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /jpa2ddl-samples/jpa2ddl-querydsl-maven-sample/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | com.devskiller.jpa2ddl 7 | jpa2ddl-samples 8 | 0.9.17-SNAPSHOT 9 | 10 | 11 | jpa2ddl-querydsl-maven-sample 12 | 13 | ${project.artifactId} 14 | jpa2ddl querydsl with maven sample 15 | 16 | 17 | 1.8 18 | 1.8 19 | UTF-8 20 | 7.0 21 | 5.4.23.Final 22 | 23 | 24 | 25 | 26 | javax 27 | javaee-api 28 | ${javaee-api-version} 29 | compile 30 | 31 | 32 | 33 | org.hibernate 34 | hibernate-core 35 | ${hibernate-version} 36 | 37 | 38 | 39 | 40 | 41 | 42 | com.devskiller.jpa2ddl 43 | jpa2ddl-maven-plugin 44 | ${project.version} 45 | true 46 | 47 | 48 | oss.devskiller.model 49 | 50 | UPDATE 51 | 52 | 53 | queryDslOutputPath 54 | ${project.build.directory}/generated-sources/query-dsl 55 | 56 | 57 | queryDslOutputPackage 58 | oss.devskiller.querydsl 59 | 60 | 61 | 62 | 63 | 64 | com.devskiller.jpa2ddl 65 | jpa2ddl-querydsl-processor 66 | ${project.version} 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /jpa2ddl-samples/jpa2ddl-querydsl-maven-sample/src/main/java/oss/devskiller/model/User.java: -------------------------------------------------------------------------------- 1 | package oss.devskiller.model; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.Id; 5 | 6 | @Entity 7 | class User { 8 | 9 | @Id 10 | private Long id; 11 | 12 | private String name; 13 | 14 | private String email; 15 | 16 | private int age; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /jpa2ddl-samples/jpa2ddl-querydsl-maven-sample/src/main/resources/migrations/v1__jpa2ddl.sql: -------------------------------------------------------------------------------- 1 | 2 | create table User ( 3 | id bigint not null, 4 | name varchar(255), 5 | primary key (id) 6 | ); 7 | -------------------------------------------------------------------------------- /jpa2ddl-samples/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | com.devskiller.jpa2ddl 7 | jpa2ddl-parent 8 | 0.9.17-SNAPSHOT 9 | 10 | 11 | jpa2ddl-samples 12 | ${project.artifactId} 13 | jpa2ddl samples 14 | 15 | pom 16 | 17 | 18 | true 19 | true 20 | true 21 | 22 | 23 | 24 | jpa2ddl-flyway-maven-sample 25 | jpa2ddl-querydsl-maven-sample 26 | 27 | 28 | 29 | 30 | 31 | maven-install-plugin 32 | 2.5.2 33 | 34 | true 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | fi 118 | 119 | if [ -z "$JAVA_HOME" ]; then 120 | javaExecutable="`which javac`" 121 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 122 | # readlink(1) is not available as standard on Solaris 10. 123 | readLink=`which readlink` 124 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 125 | if $darwin ; then 126 | javaHome="`dirname \"$javaExecutable\"`" 127 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 128 | else 129 | javaExecutable="`readlink -f \"$javaExecutable\"`" 130 | fi 131 | javaHome="`dirname \"$javaExecutable\"`" 132 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 133 | JAVA_HOME="$javaHome" 134 | export JAVA_HOME 135 | fi 136 | fi 137 | fi 138 | 139 | if [ -z "$JAVACMD" ] ; then 140 | if [ -n "$JAVA_HOME" ] ; then 141 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 142 | # IBM's JDK on AIX uses strange locations for the executables 143 | JAVACMD="$JAVA_HOME/jre/sh/java" 144 | else 145 | JAVACMD="$JAVA_HOME/bin/java" 146 | fi 147 | else 148 | JAVACMD="`which java`" 149 | fi 150 | fi 151 | 152 | if [ ! -x "$JAVACMD" ] ; then 153 | echo "Error: JAVA_HOME is not defined correctly." >&2 154 | echo " We cannot execute $JAVACMD" >&2 155 | exit 1 156 | fi 157 | 158 | if [ -z "$JAVA_HOME" ] ; then 159 | echo "Warning: JAVA_HOME environment variable is not set." 160 | fi 161 | 162 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 163 | 164 | # traverses directory structure from process work directory to filesystem root 165 | # first directory with .mvn subdirectory is considered project base directory 166 | find_maven_basedir() { 167 | 168 | if [ -z "$1" ] 169 | then 170 | echo "Path not specified to find_maven_basedir" 171 | return 1 172 | fi 173 | 174 | basedir="$1" 175 | wdir="$1" 176 | while [ "$wdir" != '/' ] ; do 177 | if [ -d "$wdir"/.mvn ] ; then 178 | basedir=$wdir 179 | break 180 | fi 181 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 182 | if [ -d "${wdir}" ]; then 183 | wdir=`cd "$wdir/.."; pwd` 184 | fi 185 | # end of workaround 186 | done 187 | echo "${basedir}" 188 | } 189 | 190 | # concatenates all lines of a file 191 | concat_lines() { 192 | if [ -f "$1" ]; then 193 | echo "$(tr -s '\n' ' ' < "$1")" 194 | fi 195 | } 196 | 197 | BASE_DIR=`find_maven_basedir "$(pwd)"` 198 | if [ -z "$BASE_DIR" ]; then 199 | exit 1; 200 | fi 201 | 202 | ########################################################################################## 203 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 204 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 205 | ########################################################################################## 206 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 207 | if [ "$MVNW_VERBOSE" = true ]; then 208 | echo "Found .mvn/wrapper/maven-wrapper.jar" 209 | fi 210 | else 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 213 | fi 214 | if [ -n "$MVNW_REPOURL" ]; then 215 | jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 216 | else 217 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 218 | fi 219 | while IFS="=" read key value; do 220 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 221 | esac 222 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 223 | if [ "$MVNW_VERBOSE" = true ]; then 224 | echo "Downloading from: $jarUrl" 225 | fi 226 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 227 | if $cygwin; then 228 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 229 | fi 230 | 231 | if command -v wget > /dev/null; then 232 | if [ "$MVNW_VERBOSE" = true ]; then 233 | echo "Found wget ... using wget" 234 | fi 235 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 236 | wget "$jarUrl" -O "$wrapperJarPath" 237 | else 238 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" 239 | fi 240 | elif command -v curl > /dev/null; then 241 | if [ "$MVNW_VERBOSE" = true ]; then 242 | echo "Found curl ... using curl" 243 | fi 244 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 245 | curl -o "$wrapperJarPath" "$jarUrl" -f 246 | else 247 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 248 | fi 249 | 250 | else 251 | if [ "$MVNW_VERBOSE" = true ]; then 252 | echo "Falling back to using Java to download" 253 | fi 254 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 255 | # For Cygwin, switch paths to Windows format before running javac 256 | if $cygwin; then 257 | javaClass=`cygpath --path --windows "$javaClass"` 258 | fi 259 | if [ -e "$javaClass" ]; then 260 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 261 | if [ "$MVNW_VERBOSE" = true ]; then 262 | echo " - Compiling MavenWrapperDownloader.java ..." 263 | fi 264 | # Compiling the Java class 265 | ("$JAVA_HOME/bin/javac" "$javaClass") 266 | fi 267 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 268 | # Running the downloader 269 | if [ "$MVNW_VERBOSE" = true ]; then 270 | echo " - Running MavenWrapperDownloader.java ..." 271 | fi 272 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 273 | fi 274 | fi 275 | fi 276 | fi 277 | ########################################################################################## 278 | # End of extension 279 | ########################################################################################## 280 | 281 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 282 | if [ "$MVNW_VERBOSE" = true ]; then 283 | echo $MAVEN_PROJECTBASEDIR 284 | fi 285 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 286 | 287 | # For Cygwin, switch paths to Windows format before running java 288 | if $cygwin; then 289 | [ -n "$M2_HOME" ] && 290 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 291 | [ -n "$JAVA_HOME" ] && 292 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 293 | [ -n "$CLASSPATH" ] && 294 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 295 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 296 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 297 | fi 298 | 299 | # Provide a "standardized" way to retrieve the CLI args that will 300 | # work with both Windows and non-Windows executions. 301 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 302 | export MAVEN_CMD_LINE_ARGS 303 | 304 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 305 | 306 | exec "$JAVACMD" \ 307 | $MAVEN_OPTS \ 308 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 309 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 310 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 311 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 124 | 125 | FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 162 | if ERRORLEVEL 1 goto error 163 | goto end 164 | 165 | :error 166 | set ERROR_CODE=1 167 | 168 | :end 169 | @endlocal & set ERROR_CODE=%ERROR_CODE% 170 | 171 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 172 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 173 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 174 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 175 | :skipRcPost 176 | 177 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 178 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 179 | 180 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 181 | 182 | exit /B %ERROR_CODE% 183 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | com.devskiller.jpa2ddl 6 | jpa2ddl-parent 7 | 0.10.1-SNAPSHOT 8 | 9 | ${project.artifactId} 10 | jpa2ddl parent 11 | https://github.com/Devskiller/jpa2ddl 12 | 13 | pom 14 | 15 | 16 | 17 | Apache 2 18 | http://www.apache.org/licenses/LICENSE-2.0.txt 19 | repo 20 | A business-friendly OSS license 21 | 22 | 23 | 24 | 25 | 26 | jkubrynski 27 | Jakub Kubrynski 28 | 29 | 30 | 31 | 32 | scm:git:https://github.com/Devskiller/jpa2ddl 33 | scm:git:git@github.com:Devskiller/jpa2ddl 34 | https://github.com/Devskiller/jpa2ddl 35 | HEAD 36 | 37 | 38 | 39 | jpa2ddl-core 40 | jpa2ddl-maven-plugin 41 | jpa2ddl-querydsl-processor 42 | 43 | jpa2ddl-gradle-plugin 44 | 45 | 46 | 47 | 48 | oss 49 | Sonatype Nexus Snapshots 50 | https://oss.sonatype.org/content/repositories/snapshots 51 | 52 | 53 | oss 54 | Nexus Release Repository 55 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 56 | 57 | 58 | 59 | 60 | GitHub Issues 61 | https://github.com/Devskiller/jpa2ddl/issues 62 | 63 | 64 | 65 | Travis 66 | https://travis-ci.org/Devskiller/jpa2ddl 67 | 68 | 69 | 70 | 1.8 71 | 1.8 72 | UTF-8 73 | UTF-8 74 | 75 | 76 | 77 | 78 | 79 | junit 80 | junit 81 | 4.13.1 82 | test 83 | 84 | 85 | org.assertj 86 | assertj-core 87 | 3.13.2 88 | test 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | org.apache.maven.plugins 97 | maven-release-plugin 98 | 3.0.0-M1 99 | 100 | true 101 | false 102 | true 103 | release 104 | @{project.version} 105 | clean install 106 | 107 | 108 | 109 | org.apache.maven.plugins 110 | maven-surefire-plugin 111 | 2.22.2 112 | 113 | 114 | 115 | 116 | 117 | 118 | release 119 | 120 | 121 | 122 | org.apache.maven.plugins 123 | maven-gpg-plugin 124 | 1.6 125 | 126 | 127 | sign-artifacts 128 | verify 129 | 130 | sign 131 | 132 | 133 | 134 | 135 | 136 | org.apache.maven.plugins 137 | maven-source-plugin 138 | 3.2.1 139 | 140 | 141 | attach-sources 142 | 143 | jar-no-fork 144 | 145 | 146 | 147 | 148 | 149 | org.apache.maven.plugins 150 | maven-javadoc-plugin 151 | 3.2.0 152 | 153 | 154 | attach-javadocs 155 | 156 | jar 157 | 158 | 159 | 160 | 161 | 162 | org.sonatype.plugins 163 | nexus-staging-maven-plugin 164 | 1.6.8 165 | true 166 | 167 | sonatype-nexus-staging 168 | https://oss.sonatype.org/ 169 | false 170 | 171 | 172 | 173 | com.google.code.maven-replacer-plugin 174 | replacer 175 | 1.5.3 176 | 177 | 178 | process-sources 179 | 180 | replace 181 | 182 | 183 | 184 | 185 | README.md 186 | 187 | 188 | (\d+\.\d+\.\d+(\-SNAPSHOT)?) 189 | ${project.version} 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | --------------------------------------------------------------------------------