Repository: quarkiverse/quarkus-mongock Branch: main Commit: 0ad1878670a1 Files: 44 Total size: 55.5 KB Directory structure: gitextract_9fegdl4h/ ├── .all-contributorsrc ├── .github/ │ ├── CODEOWNERS │ ├── dependabot.yml │ ├── project.yml │ └── workflows/ │ ├── build.yml │ ├── deploy-snapshots.yml.disabled │ ├── pre-release.yml │ ├── quarkus-snapshot.yaml │ ├── release-perform.yml │ └── release-prepare.yml ├── .gitignore ├── LICENSE ├── README.md ├── deployment/ │ ├── pom.xml │ └── src/ │ ├── main/ │ │ └── java/ │ │ └── io/ │ │ └── quarkiverse/ │ │ └── mongock/ │ │ └── deployment/ │ │ ├── MongockEnabled.java │ │ └── MongockProcessor.java │ └── test/ │ ├── java/ │ │ └── io/ │ │ └── quarkiverse/ │ │ └── mongock/ │ │ └── test/ │ │ └── MongockDisabledTest.java │ └── resources/ │ └── application-migrate-at-start.properties ├── docs/ │ ├── antora.yml │ ├── modules/ │ │ └── ROOT/ │ │ ├── assets/ │ │ │ └── images/ │ │ │ └── .keepme │ │ ├── nav.adoc │ │ └── pages/ │ │ ├── includes/ │ │ │ ├── attributes.adoc │ │ │ └── quarkus-mongock.adoc │ │ └── index.adoc │ ├── pom.xml │ └── templates/ │ └── includes/ │ └── attributes.adoc ├── integration-tests/ │ ├── pom.xml │ └── src/ │ ├── main/ │ │ ├── java/ │ │ │ └── io/ │ │ │ └── quarkiverse/ │ │ │ └── mongock/ │ │ │ └── it/ │ │ │ ├── Fruit.java │ │ │ ├── FruitMigrationChangeUnit.java │ │ │ └── FruitResource.java │ │ └── resources/ │ │ └── application.properties │ └── test/ │ └── java/ │ └── io/ │ └── quarkiverse/ │ └── mongock/ │ └── it/ │ ├── MongockIT.java │ ├── MongockMigrateAtStartIT.java │ ├── MongockMigrateAtStartTest.java │ ├── MongockTest.java │ └── MongockTestUtils.java ├── pom.xml └── runtime/ ├── pom.xml └── src/ └── main/ ├── java/ │ └── io/ │ └── quarkiverse/ │ └── mongock/ │ ├── MongockFactory.java │ └── runtime/ │ ├── MongockBuildTimeConfig.java │ ├── MongockRecorder.java │ ├── MongockRuntimeConfig.java │ └── graal/ │ └── OrgReflectionsSubstitutions.java └── resources/ └── META-INF/ └── quarkus-extension.yaml ================================================ FILE CONTENTS ================================================ ================================================ FILE: .all-contributorsrc ================================================ { "files": [ "README.md" ], "imageSize": 100, "commit": false, "commitType": "docs", "commitConvention": "angular", "contributors": [ { "login": "tms0", "name": "Valentin Day", "avatar_url": "https://avatars.githubusercontent.com/u/5920998?v=4", "profile": "https://colibris.xyz", "contributions": [ "code", "maintenance" ] }, { "login": "mswiderski", "name": "Maciej Swiderski", "avatar_url": "https://avatars.githubusercontent.com/u/904474?v=4", "profile": "https://automatiko.io", "contributions": [ "code" ] } ], "contributorsPerLine": 7, "skipCi": true, "repoType": "github", "repoHost": "https://github.com", "projectName": "quarkus-mongock", "projectOwner": "quarkiverse" } ================================================ FILE: .github/CODEOWNERS ================================================ # Lines starting with '#' are comments. # Each line is a file pattern followed by one or more owners. # More details are here: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners # The '*' pattern is global owners. # Order is important. The last matching pattern has the most precedence. # The folders are ordered as follows: # In each subsection folders are ordered first by depth, then alphabetically. # This should make it easy to add new rules without breaking existing ones. * @quarkiverse/quarkiverse-mongock ================================================ FILE: .github/dependabot.yml ================================================ # To get started with Dependabot version updates, you'll need to specify which # package ecosystems to update and where the package manifests are located. # Please see the documentation for all configuration options: # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates version: 2 updates: - package-ecosystem: "maven" # See documentation for possible values directory: "/" # Location of package manifests schedule: interval: "daily" ================================================ FILE: .github/project.yml ================================================ release: current-version: "0.6.0" next-version: "0.7.0-SNAPSHOT" ================================================ FILE: .github/workflows/build.yml ================================================ name: Build on: push: branches: - "main" paths-ignore: - '.gitignore' - 'CODEOWNERS' - 'LICENSE' - '*.md' - '*.adoc' - '*.txt' - '.all-contributorsrc' pull_request: paths-ignore: - '.gitignore' - 'CODEOWNERS' - 'LICENSE' - '*.md' - '*.adoc' - '*.txt' - '.all-contributorsrc' concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true defaults: run: shell: bash jobs: build: name: Build on ${{ matrix.os }} strategy: fail-fast: false matrix: # os: [windows-latest, macos-latest, ubuntu-latest] os: [ubuntu-latest] runs-on: ${{ matrix.os }} steps: - name: Prepare git run: git config --global core.autocrlf false if: startsWith(matrix.os, 'windows') - uses: actions/checkout@v4 - name: Set up JDK 17 uses: actions/setup-java@v4 with: distribution: temurin java-version: 17 cache: 'maven' - name: Build with Maven run: mvn -B clean install -Dno-format - name: Build with Maven (Native) run: mvn -B install -Dnative -Dquarkus.native.container-build -Dnative.surefire.skip ================================================ FILE: .github/workflows/deploy-snapshots.yml.disabled ================================================ # This workflow will build and deploy a snapshot of your artifact to Sonatype Snapshots repository name: Deploy Snapshots concurrency: group: ${{ github.ref }}-${{ github.workflow }} cancel-in-progress: true on: workflow_dispatch: push: branches: [ main ] defaults: run: shell: bash jobs: deploy-snapshot: runs-on: ubuntu-latest name: Deploy Snapshot artifacts steps: - uses: actions/checkout@v4 - uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: 17 cache: 'maven' server-id: 'ossrh' server-username: MAVEN_USERNAME server-password: MAVEN_PASSWORD gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} gpg-passphrase: MAVEN_GPG_PASSPHRASE - name: Deploy Snapshot run: | mvn -B clean deploy -DperformRelease=true -Drelease env: MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} ================================================ FILE: .github/workflows/pre-release.yml ================================================ name: Quarkiverse Pre Release on: pull_request: paths: - '.github/project.yml' concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: pre-release: name: Pre-Release uses: quarkiverse/.github/.github/workflows/pre-release.yml@main secrets: inherit ================================================ FILE: .github/workflows/quarkus-snapshot.yaml ================================================ name: "Quarkus ecosystem CI" on: workflow_dispatch: watch: types: [started] permissions: contents: read concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: build: uses: quarkiverse/.github/.github/workflows/quarkus-ecosystem-ci.yml@main secrets: inherit with: ecosystem_ci_repo_path: quarkiverse-mongock java_version: 17 ================================================ FILE: .github/workflows/release-perform.yml ================================================ name: Quarkiverse Perform Release run-name: Perform ${{github.event.inputs.tag || github.ref_name}} Release on: push: tags: - '*' workflow_dispatch: inputs: tag: description: 'Tag to release' required: true permissions: attestations: write id-token: write contents: read concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: perform-release: name: Perform Release uses: quarkiverse/.github/.github/workflows/perform-release.yml@main secrets: inherit with: version: ${{github.event.inputs.tag || github.ref_name}} ================================================ FILE: .github/workflows/release-prepare.yml ================================================ name: Quarkiverse Prepare Release on: pull_request: types: [ closed ] paths: - '.github/project.yml' concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: prepare-release: name: Prepare Release if: ${{ github.event.pull_request.merged == true}} uses: quarkiverse/.github/.github/workflows/prepare-release.yml@main secrets: inherit ================================================ FILE: .gitignore ================================================ # Compiled class file *.class # Log file *.log # BlueJ files *.ctxt # Mobile Tools for Java (J2ME) .mtj.tmp/ # Package Files # *.jar *.war *.nar *.ear *.zip *.tar.gz *.rar # virtual machine crash logs, see https://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* # Eclipse .project .classpath .settings/ bin/ # IntelliJ .idea *.ipr *.iml *.iws # NetBeans nb-configuration.xml # Visual Studio Code .vscode .factorypath # OSX .DS_Store # Vim *.swp *.swo # patch *.orig *.rej # Gradle .gradle/ build/ # Maven target/ pom.xml.tag pom.xml.releaseBackup pom.xml.versionsBackup release.properties ================================================ FILE: LICENSE ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: README.md ================================================ # Quarkus Mongock [![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors-) [![Build](https://github.com/quarkiverse/quarkus-mongock/workflows/Build/badge.svg)](https://github.com/quarkiverse/quarkus-mongock/actions?query=workflow%3ABuild) [![Version](https://img.shields.io/maven-central/v/io.quarkiverse.mongock/quarkus-mongock?logo=apache-maven&style=flat-square)](https://central.sonatype.com/artifact/io.quarkiverse.mongock/quarkus-mongock-parent) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) This Quarkus extension allows you to use [Mongock](https://mongock.io/) with Quarkus. With Maven, add the following dependency to your `pom.xml` to get started: ```xml io.quarkiverse.mongock quarkus-mongock ${quarkusMongockVersion} ``` Or with Gradle, add the following dependency to your `build.gradle`: ```groovy implementation "io.quarkiverse.mongock:quarkus-mongock:${quarkusMongockVersion}" ``` For more information and quickstart, you can check the complete [documentation](https://quarkiverse.github.io/quarkiverse-docs/quarkus-mongock/dev/index.html). ## Contributors ✨ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Valentin Day
Valentin Day

💻 🚧
Maciej Swiderski
Maciej Swiderski

💻
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! ================================================ FILE: deployment/pom.xml ================================================ 4.0.0 io.quarkiverse.mongock quarkus-mongock-parent 0.7.0-SNAPSHOT quarkus-mongock-deployment Quarkus Mongock - Deployment io.quarkus quarkus-arc-deployment io.quarkus quarkus-mongodb-client-deployment io.quarkiverse.mongock quarkus-mongock ${project.version} io.quarkus quarkus-junit5-internal test maven-compiler-plugin io.quarkus quarkus-extension-processor ${quarkus.version} ================================================ FILE: deployment/src/main/java/io/quarkiverse/mongock/deployment/MongockEnabled.java ================================================ package io.quarkiverse.mongock.deployment; import java.util.function.BooleanSupplier; import io.quarkiverse.mongock.runtime.MongockBuildTimeConfig; /** * Supplier that can be used to only run build steps * if the Mongock extension is enabled. */ public class MongockEnabled implements BooleanSupplier { private final MongockBuildTimeConfig config; MongockEnabled(MongockBuildTimeConfig config) { this.config = config; } @Override public boolean getAsBoolean() { return config.enabled(); } } ================================================ FILE: deployment/src/main/java/io/quarkiverse/mongock/deployment/MongockProcessor.java ================================================ package io.quarkiverse.mongock.deployment; import static io.quarkus.deployment.annotations.ExecutionTime.STATIC_INIT; import java.util.ArrayList; import java.util.List; import java.util.Map; import jakarta.inject.Singleton; import org.jboss.jandex.ClassType; import org.jboss.jandex.DotName; import com.mongodb.client.MongoClient; import io.mongock.api.annotations.ChangeUnit; import io.quarkiverse.mongock.MongockFactory; import io.quarkiverse.mongock.runtime.MongockRecorder; import io.quarkus.arc.deployment.BeanContainerBuildItem; import io.quarkus.arc.deployment.SyntheticBeanBuildItem; import io.quarkus.deployment.annotations.*; import io.quarkus.deployment.annotations.Record; import io.quarkus.deployment.builditem.*; import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; import io.quarkus.deployment.recording.RecorderContext; @BuildSteps(onlyIf = MongockEnabled.class) class MongockProcessor { @BuildStep @Record(STATIC_INIT) void build( MongockRecorder recorder, CombinedIndexBuildItem combinedIndex, RecorderContext context, BuildProducer reflectiveClassProducer) { List> migrationClasses = new ArrayList<>(); addMigrationClasses(combinedIndex, context, reflectiveClassProducer, migrationClasses); recorder.setMigrationClasses(migrationClasses); } @BuildStep @Record(ExecutionTime.RUNTIME_INIT) void createBeans(MongockRecorder recorder, BuildProducer syntheticBeanBuildItemBuildProducer) { SyntheticBeanBuildItem.ExtendedBeanConfigurator configurator = SyntheticBeanBuildItem .configure(MongockFactory.class) .scope(Singleton.class) .setRuntimeInit() .unremovable() .addInjectionPoint(ClassType.create(DotName.createSimple(MongoClient.class))) .createWith(recorder.mongockFunction()); syntheticBeanBuildItemBuildProducer.produce(configurator.done()); } @BuildStep @Consume(BeanContainerBuildItem.class) @Record(ExecutionTime.RUNTIME_INIT) ServiceStartBuildItem startLiquibase(MongockRecorder recorder, BuildProducer initializationCompleteBuildItem) { recorder.doStartActions(); initializationCompleteBuildItem.produce(new InitTaskCompletedBuildItem("mongock")); return new ServiceStartBuildItem("mongock"); } @BuildStep public InitTaskBuildItem configureInitTask(ApplicationInfoBuildItem app) { return InitTaskBuildItem.create() .withName(app.getName() + "-mongock-init") .withTaskEnvVars( Map.of("QUARKUS_INIT_AND_EXIT", "true", "QUARKUS_MONGOCK_ENABLED", "true")) .withAppEnvVars(Map.of("QUARKUS_MONGOCK_ENABLED", "false")) .withSharedEnvironment(true) .withSharedFilesystem(true); } private void addMigrationClasses( CombinedIndexBuildItem combinedIndex, RecorderContext context, BuildProducer reflectiveClassProducer, List> migrationClasses) { combinedIndex.getIndex().getAnnotations(DotName.createSimple(ChangeUnit.class.getName())).stream() .map(annotationInstance -> annotationInstance.target().asClass()) .forEach(classInfo -> { migrationClasses.add(context.classProxy(classInfo.name().toString())); reflectiveClassProducer.produce( ReflectiveClassBuildItem .builder(classInfo.name().toString()) .methods() .build()); }); } } ================================================ FILE: deployment/src/test/java/io/quarkiverse/mongock/test/MongockDisabledTest.java ================================================ package io.quarkiverse.mongock.test; import static org.junit.jupiter.api.Assertions.assertTrue; import jakarta.enterprise.inject.Instance; import jakarta.inject.Inject; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import io.quarkiverse.mongock.MongockFactory; import io.quarkus.test.QuarkusUnitTest; public class MongockDisabledTest { @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() .overrideConfigKey("quarkus.mongock.enabled", "false") .withEmptyApplication(); @Inject Instance bean; @Test void testNoMongockFactoryInstance() { assertTrue(bean.isUnsatisfied(), "No mongock factory bean"); } } ================================================ FILE: deployment/src/test/resources/application-migrate-at-start.properties ================================================ quarkus.mongodb.database=test quarkus.mongodb.client1.connection-string = mongodb://mongo2:27017/userdb quarkus.mongodb.client1.database=test1 quarkus.mongock.migrate-at-start=true ================================================ FILE: docs/antora.yml ================================================ name: quarkus-mongock title: Mongock version: dev nav: - modules/ROOT/nav.adoc ================================================ FILE: docs/modules/ROOT/assets/images/.keepme ================================================ ================================================ FILE: docs/modules/ROOT/nav.adoc ================================================ * xref:index.adoc[Quarkus Mongock] ================================================ FILE: docs/modules/ROOT/pages/includes/attributes.adoc ================================================ :project-version: 0.6.0 :examples-dir: ./../examples/ ================================================ FILE: docs/modules/ROOT/pages/includes/quarkus-mongock.adoc ================================================ :summaryTableId: quarkus-mongock [.configuration-legend] icon:lock[title=Fixed at build time] Configuration property fixed at build time - All other configuration properties are overridable at runtime [.configuration-reference.searchable, cols="80,.^10,.^10"] |=== h|[[quarkus-mongock_configuration]]link:#quarkus-mongock_configuration[Configuration property] h|Type h|Default a|icon:lock[title=Fixed at build time] [[quarkus-mongock_quarkus-mongock-enabled]]`link:#quarkus-mongock_quarkus-mongock-enabled[quarkus.mongock.enabled]` [.description] -- Whether Mongock is enabled *during the build*. If Mongock is disabled, the Mongock beans won't be created and Mongock won't be usable. ifdef::add-copy-button-to-env-var[] Environment variable: env_var_with_copy_button:+++QUARKUS_MONGOCK_ENABLED+++[] endif::add-copy-button-to-env-var[] ifndef::add-copy-button-to-env-var[] Environment variable: `+++QUARKUS_MONGOCK_ENABLED+++` endif::add-copy-button-to-env-var[] --|boolean |`true` a| [[quarkus-mongock_quarkus-mongock-migrate-at-start]]`link:#quarkus-mongock_quarkus-mongock-migrate-at-start[quarkus.mongock.migrate-at-start]` [.description] -- `true` to execute Mongock automatically when the application starts, `false` otherwise. ifdef::add-copy-button-to-env-var[] Environment variable: env_var_with_copy_button:+++QUARKUS_MONGOCK_MIGRATE_AT_START+++[] endif::add-copy-button-to-env-var[] ifndef::add-copy-button-to-env-var[] Environment variable: `+++QUARKUS_MONGOCK_MIGRATE_AT_START+++` endif::add-copy-button-to-env-var[] --|boolean |`false` a| [[quarkus-mongock_quarkus-mongock-transaction-enabled]]`link:#quarkus-mongock_quarkus-mongock-transaction-enabled[quarkus.mongock.transaction-enabled]` [.description] -- `true` to enable transaction, `false` otherwise. If the driver does not support transaction, it will be automatically disabled. ifdef::add-copy-button-to-env-var[] Environment variable: env_var_with_copy_button:+++QUARKUS_MONGOCK_TRANSACTION_ENABLED+++[] endif::add-copy-button-to-env-var[] ifndef::add-copy-button-to-env-var[] Environment variable: `+++QUARKUS_MONGOCK_TRANSACTION_ENABLED+++` endif::add-copy-button-to-env-var[] --|boolean |`true` |=== ================================================ FILE: docs/modules/ROOT/pages/index.adoc ================================================ = Quarkus Mongock include::./includes/attributes.adoc[] https://mongock.io/[Mongock] is a Java based migration tool as part of your application code for Distributed environments focused in managing changes for your favourite NoSQL databases. == Usage To start using Mongock with your project, you just need to: - create https://docs.mongock.io/v5/migration/index.html[ChangeUnits] as you usually do with Mongock. - activate the `migrate-at-start` option to migrate automatically or inject the `MongockFactory` object and run your migration as you normally do. Add the following dependency to your POM file: [source,xml,subs=attributes+] ---- io.quarkiverse.mongock quarkus-mongock {project-version} ---- Mongock support relies on the https://quarkus.io/guides/mongodb[Quarkus MongoDB client]. First, you need to add the MongoDB client configuration to the `application.properties` file : [source,properties] ---- quarkus.mongodb.connection-string=mongodb://localhost:27017 quarkus.mongodb.database=test # Optional, if you want to migrate automatically at startup quarkus.mongock.migrate-at-start=true ---- Add https://docs.mongock.io/v5/migration/index.html[ChangeUnits] to the project, in the packages of your choice : [source,java] ---- @ChangeUnit(id="myMigrationChangeUnitId", order = "001", author = "mongock_test", systemVersion = "1") public class MyMigrationChangeUnit { private final MongoDatabase mongoDatabase; public MyMigrationChangeUnit(MongoDatabase mongoDatabase) { this.mongoDatabase = mongoDatabase; } @Execution public void migrationMethod() { mongoDatabase.getCollection("fruits").createIndex(Indexes.ascending("name")); } @RollbackExecution public void rollback() { mongoDatabase.getCollection("fruits").dropIndex(Indexes.ascending("name")); } } ---- And finally, you can manually run the migration by injecting the `MongockFactory` bean : [source,java] ---- import io.quarkiverse.mongock.MongockFactory; public class MigrationService { @Inject MongockFactory mongockFactory; public void migrate() { MongockRunner mongockRunner = mongockFactory.createMongockRunner(); mongockRunner.execute(); } } ---- == Limitations For now, this extension only support the https://docs.mongock.io/v5/driver/mongodb-sync/[MongoDB sync driver] with the default MongoDB client (no support for https://quarkus.io/guides/mongodb#multiple-mongodb-clients[multiple clients] yet). [[extension-configuration-reference]] == Extension Configuration Reference include::includes/quarkus-mongock.adoc[leveloffset=+1, opts=optional] ================================================ FILE: docs/pom.xml ================================================ 4.0.0 io.quarkiverse.mongock quarkus-mongock-parent 0.7.0-SNAPSHOT ../pom.xml quarkus-mongock-docs Quarkus Mongock - Documentation io.quarkiverse.mongock quarkus-mongock-integration-tests ${project.version} true modules/ROOT/examples io.quarkus quarkus-maven-plugin build it.ozimov yaml-properties-maven-plugin initialize read-project-properties ${project.basedir}/../.github/project.yml maven-resources-plugin copy-resources generate-resources copy-resources ${project.basedir}/modules/ROOT/pages/includes/ ${project.basedir}/../target/asciidoc/generated/config/ quarkus-mongock.adoc false ${project.basedir}/templates/includes attributes.adoc true copy-images prepare-package copy-resources ${project.build.directory}/generated-docs/_images/ ${project.basedir}/modules/ROOT/assets/images/ false org.asciidoctor asciidoctor-maven-plugin ================================================ FILE: docs/templates/includes/attributes.adoc ================================================ :project-version: ${release.current-version} :examples-dir: ./../examples/ ================================================ FILE: integration-tests/pom.xml ================================================ 4.0.0 io.quarkiverse.mongock quarkus-mongock-parent 0.7.0-SNAPSHOT quarkus-mongock-integration-tests Quarkus - Mongock - Integration Tests true io.quarkus quarkus-mongodb-panache io.quarkus quarkus-rest-jackson io.quarkiverse.mongock quarkus-mongock ${project.version} io.quarkus quarkus-junit5 test io.rest-assured rest-assured test io.quarkus quarkus-maven-plugin build maven-failsafe-plugin integration-test verify native-image native maven-surefire-plugin ${native.surefire.skip} false true ================================================ FILE: integration-tests/src/main/java/io/quarkiverse/mongock/it/Fruit.java ================================================ package io.quarkiverse.mongock.it; import io.quarkus.mongodb.panache.PanacheMongoEntity; import io.quarkus.mongodb.panache.common.MongoEntity; @MongoEntity(collection = "fruits") public class Fruit extends PanacheMongoEntity { public String name; public Fruit() { } public Fruit(String name) { this.name = name; } } ================================================ FILE: integration-tests/src/main/java/io/quarkiverse/mongock/it/FruitMigrationChangeUnit.java ================================================ package io.quarkiverse.mongock.it; import io.mongock.api.annotations.ChangeUnit; import io.mongock.api.annotations.Execution; import io.mongock.api.annotations.RollbackExecution; @ChangeUnit(id = "fruitMigrationChangeUnit", order = "001", author = "mongock_test", systemVersion = "1") public class FruitMigrationChangeUnit { @Execution public void migrationMethod() { Fruit.persist(new Fruit("apple")); } @RollbackExecution public void rollback() { Fruit.deleteAll(); } } ================================================ FILE: integration-tests/src/main/java/io/quarkiverse/mongock/it/FruitResource.java ================================================ package io.quarkiverse.mongock.it; import java.util.List; import jakarta.inject.Inject; import jakarta.ws.rs.GET; import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; import io.mongock.runner.core.executor.MongockRunner; import io.quarkiverse.mongock.MongockFactory; @Path("/") @Produces(MediaType.APPLICATION_JSON) public class FruitResource { @Inject MongockFactory mongockFactory; @GET @Path("fruits") public List list() { return Fruit.listAll(); } @POST @Path("migrate") public void migrate() { MongockRunner mongockRunner = mongockFactory.createMongockRunner(); mongockRunner.execute(); } } ================================================ FILE: integration-tests/src/main/resources/application.properties ================================================ quarkus.mongodb.database=test ================================================ FILE: integration-tests/src/test/java/io/quarkiverse/mongock/it/MongockIT.java ================================================ package io.quarkiverse.mongock.it; import io.quarkus.test.junit.QuarkusIntegrationTest; @QuarkusIntegrationTest public class MongockIT extends MongockTest { } ================================================ FILE: integration-tests/src/test/java/io/quarkiverse/mongock/it/MongockMigrateAtStartIT.java ================================================ package io.quarkiverse.mongock.it; import io.quarkus.test.junit.QuarkusIntegrationTest; @QuarkusIntegrationTest public class MongockMigrateAtStartIT extends MongockMigrateAtStartTest { } ================================================ FILE: integration-tests/src/test/java/io/quarkiverse/mongock/it/MongockMigrateAtStartTest.java ================================================ package io.quarkiverse.mongock.it; import java.util.Map; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.QuarkusTestProfile; import io.quarkus.test.junit.TestProfile; @TestProfile(value = MongockMigrateAtStartTest.MigrateAtStartTestProfile.class) @QuarkusTest public class MongockMigrateAtStartTest { @Test public void testMigrateAtStart() { Assertions.assertEquals(1, MongockTestUtils.listFruits().size()); } public static class MigrateAtStartTestProfile implements QuarkusTestProfile { @Override public Map getConfigOverrides() { return Map.of("quarkus.mongock.migrate-at-start", "true"); } } } ================================================ FILE: integration-tests/src/test/java/io/quarkiverse/mongock/it/MongockTest.java ================================================ package io.quarkiverse.mongock.it; import static io.restassured.RestAssured.post; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import io.quarkus.test.junit.QuarkusTest; @QuarkusTest public class MongockTest { @Test public void testMigration() { Assertions.assertEquals(0, MongockTestUtils.listFruits().size()); post("/migrate"); Assertions.assertEquals(1, MongockTestUtils.listFruits().size()); } } ================================================ FILE: integration-tests/src/test/java/io/quarkiverse/mongock/it/MongockTestUtils.java ================================================ package io.quarkiverse.mongock.it; import static io.restassured.RestAssured.get; import java.util.List; import io.restassured.common.mapper.TypeRef; public class MongockTestUtils { static List listFruits() { return get("/fruits").as(new TypeRef<>() { }); } } ================================================ FILE: pom.xml ================================================ 4.0.0 io.quarkiverse quarkiverse-parent 19 io.quarkiverse.mongock quarkus-mongock-parent Quarkus Mongock - Parent pom 0.7.0-SNAPSHOT deployment runtime scm:git:git@github.com:quarkiverse/quarkus-mongock.git scm:git:git@github.com:quarkiverse/quarkus-mongock.git https://github.com/quarkiverse/quarkus-mongock HEAD UTF-8 UTF-8 17 3.19.3 5.5.0 io.quarkus quarkus-bom ${quarkus.version} pom import io.mongock mongock-bom ${mongock.version} pom import io.quarkus quarkus-maven-plugin ${quarkus.version} docs performRelease !true docs it performRelease !true integration-tests ================================================ FILE: runtime/pom.xml ================================================ 4.0.0 io.quarkiverse.mongock quarkus-mongock-parent 0.7.0-SNAPSHOT quarkus-mongock Quarkus Mongock - Runtime io.quarkus quarkus-arc io.quarkus quarkus-mongodb-client io.mongock mongock-standalone io.mongock mongodb-sync-v4-driver org.graalvm.sdk graal-sdk provided io.quarkus quarkus-extension-maven-plugin ${quarkus.version} compile extension-descriptor ${project.groupId}:${project.artifactId}-deployment:${project.version} maven-compiler-plugin io.quarkus quarkus-extension-processor ${quarkus.version} ================================================ FILE: runtime/src/main/java/io/quarkiverse/mongock/MongockFactory.java ================================================ package io.quarkiverse.mongock; import java.util.List; import org.eclipse.microprofile.config.ConfigProvider; import com.mongodb.client.MongoClient; import io.mongock.driver.mongodb.sync.v4.driver.MongoSync4Driver; import io.mongock.runner.core.executor.MongockRunner; import io.mongock.runner.standalone.MongockStandalone; import io.quarkiverse.mongock.runtime.MongockRuntimeConfig; public class MongockFactory { private final MongoClient mongoClient; private final MongockRuntimeConfig mongockRuntimeConfig; private final List> migrationClasses; public MongockFactory( MongoClient mongoClient, MongockRuntimeConfig mongockRuntimeConfig, List> migrationClasses) { this.mongoClient = mongoClient; this.mongockRuntimeConfig = mongockRuntimeConfig; this.migrationClasses = migrationClasses; } public MongockRunner createMongockRunner() { String databaseName = ConfigProvider.getConfig().getOptionalValue("quarkus.mongodb.database", String.class) .orElseThrow(() -> new IllegalStateException("The database property was not configured for " + "the default Mongo Client (via 'quarkus.mongodb.database')")); return MongockStandalone.builder() .setDriver( MongoSync4Driver.withDefaultLock(mongoClient, databaseName)) .addMigrationClasses(migrationClasses) .setTransactional(mongockRuntimeConfig.transactionEnabled()) // See https://github.com/mongock/mongock/issues/661 .setLockGuardEnabled(false) .buildRunner(); } } ================================================ FILE: runtime/src/main/java/io/quarkiverse/mongock/runtime/MongockBuildTimeConfig.java ================================================ package io.quarkiverse.mongock.runtime; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; import io.smallrye.config.ConfigMapping; import io.smallrye.config.WithDefault; @ConfigMapping(prefix = "quarkus.mongock") @ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED) public interface MongockBuildTimeConfig { /** * Whether Mongock is enabled *during the build*. * * If Mongock is disabled, the Mongock beans won't be created and Mongock won't be usable. * * @asciidoclet */ @WithDefault("true") boolean enabled(); } ================================================ FILE: runtime/src/main/java/io/quarkiverse/mongock/runtime/MongockRecorder.java ================================================ package io.quarkiverse.mongock.runtime; import java.util.List; import java.util.function.Function; import org.jboss.logging.Logger; import com.mongodb.client.MongoClient; import io.mongock.runner.core.executor.MongockRunner; import io.quarkiverse.mongock.MongockFactory; import io.quarkus.arc.Arc; import io.quarkus.arc.InstanceHandle; import io.quarkus.arc.SyntheticCreationalContext; import io.quarkus.runtime.RuntimeValue; import io.quarkus.runtime.annotations.Recorder; @Recorder public class MongockRecorder { private static final Logger log = Logger.getLogger(MongockRecorder.class); private final RuntimeValue config; public static volatile List> migrationClasses; public MongockRecorder(RuntimeValue config) { this.config = config; } public void setMigrationClasses(List> migrationClasses) { log.debugv("Setting the following migration classes: {0}", migrationClasses); MongockRecorder.migrationClasses = migrationClasses; } public Function, MongockFactory> mongockFunction() { return (SyntheticCreationalContext context) -> { MongoClient mongoClient = context.getInjectedReference(MongoClient.class); return new MongockFactory(mongoClient, config.getValue(), migrationClasses); }; } public void doStartActions() { InstanceHandle mongockFactoryInstanceHandle = Arc.container().instance(MongockFactory.class); if (!mongockFactoryInstanceHandle.isAvailable()) { return; } MongockFactory mongockFactory = mongockFactoryInstanceHandle.get(); MongockRunner mongockRunner = mongockFactory.createMongockRunner(); if (config.getValue().migrateAtStart()) { mongockRunner.execute(); } } } ================================================ FILE: runtime/src/main/java/io/quarkiverse/mongock/runtime/MongockRuntimeConfig.java ================================================ package io.quarkiverse.mongock.runtime; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; import io.smallrye.config.ConfigMapping; import io.smallrye.config.WithDefault; @ConfigMapping(prefix = "quarkus.mongock") @ConfigRoot(phase = ConfigPhase.RUN_TIME) public interface MongockRuntimeConfig { /** * {@code true} to execute Mongock automatically when the application starts, {@code false} otherwise. */ @WithDefault("false") boolean migrateAtStart(); /** * {@code true} to enable transaction, {@code false} otherwise. If the driver does not support transaction, it will be * automatically disabled. */ @WithDefault("true") boolean transactionEnabled(); } ================================================ FILE: runtime/src/main/java/io/quarkiverse/mongock/runtime/graal/OrgReflectionsSubstitutions.java ================================================ package io.quarkiverse.mongock.runtime.graal; import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.function.BooleanSupplier; import org.reflections.Reflections; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; /** * Get rid of JBoss VFS if it is not present in the classpath. */ @TargetClass(value = Reflections.class, onlyWith = OrgReflectionsSubstitutions.IsJBossVFSAbsent.class) public final class OrgReflectionsSubstitutions { // Only necessary for package scanning, not used with Quarkus @Substitute private Map>> scan() { return new HashMap<>(); } static final class IsJBossVFSAbsent implements BooleanSupplier { @Override public boolean getAsBoolean() { try { Class.forName("org.jboss.vfs.VFS"); return false; } catch (ClassNotFoundException e) { return true; } } } } ================================================ FILE: runtime/src/main/resources/META-INF/quarkus-extension.yaml ================================================ name: "Quarkus Mongock" description: "This Quarkus extension allows you to use Mongock with Quarkus." metadata: short-name: "mongock" keywords: - "mongock" - "mongodb" categories: - "data" status: "preview" guide: "https://docs.quarkiverse.io/quarkus-mongock/dev/index.html" config: - "quarkus.mongock."