{"id":24044948,"url":"https://github.com/oun/monjam","last_synced_at":"2025-04-22T10:42:55.364Z","repository":{"id":57744351,"uuid":"192090603","full_name":"oun/monjam","owner":"oun","description":"Database migration for MongoDB","archived":false,"fork":false,"pushed_at":"2019-08-05T23:30:40.000Z","size":206,"stargazers_count":11,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T14:21:35.724Z","etag":null,"topics":["continuous-delivery","database-migrations","gradle-plugin","java","mongodb"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-15T14:53:52.000Z","updated_at":"2023-01-31T19:46:31.000Z","dependencies_parsed_at":"2022-08-30T10:51:37.761Z","dependency_job_id":null,"html_url":"https://github.com/oun/monjam","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oun%2Fmonjam","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oun%2Fmonjam/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oun%2Fmonjam/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oun%2Fmonjam/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oun","download_url":"https://codeload.github.com/oun/monjam/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250222287,"owners_count":21394850,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["continuous-delivery","database-migrations","gradle-plugin","java","mongodb"],"created_at":"2025-01-08T23:51:36.448Z","updated_at":"2025-04-22T10:42:55.320Z","avatar_url":"https://github.com/oun.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MonJam [![Build Status](https://travis-ci.com/oun/monjam.svg?branch=master)](https://travis-ci.com/oun/monjam) [![codecov](https://codecov.io/gh/oun/monjam/branch/master/graph/badge.svg)](https://codecov.io/gh/oun/monjam)\n\nMongoDB migration\n\n## Features\n- Gradle plugin\n- Java and script migration\n- Multi-document transaction (MongoDB 4.0+)\n\n## Road Map\n- Integration with Spring MongoTemplate\n- Maven plugin\n- Validate, info, clean command\n\n## Installation\n\nAdd gradle plugin, dependency and configuration in your build.gradle.\n```\nplugins {\n    id 'io.github.oun.monjam' version '0.5.0'\n}\n\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    compile 'io.github.oun:monjam-core:0.5.0'\n}\n\nmonjam {\n    url = 'mongodb://localhost:27017/?replicaSet=rs0'\n    database = 'monjam'\n    collection = 'schema_migrations'\n    location = 'db/migration'\n}\n```\n\nSee the [code example](https://github.com/oun/monjam-example) for Spring-based application.\n\n## Usage\n\n### Create Migration\n\nAnnotated class with **@MongoMigration** annotation and each methods with **@Migrate** annotation. Method with annotation parameter type *MIGRATE* and *ROLLBACK* will be executed on running migrate and rollback command respectively.\n\n#### Annotation based Java Migration\n```java\npackage db.migration;\n\nimport com.monjam.core.annotation.Migrate;\nimport com.monjam.core.annotation.MongoMigration;\nimport com.monjam.core.api.Context;\nimport com.monjam.core.api.MigrationType;\n\n@MongoMigration\npublic class UserMigration {\n    @Migrate(type = MigrationType.MIGRATE, version = \"1.0.0\", description = \"Change user prefix type\")\n    public void changeUserPrefixType(Context context) {\n        // Execute on migrate version 1.0.0\n    }\n\n    @Migrate(type = MigrationType.ROLLBACK, version = \"1.0.0\", description = \"Revert user prefix type\")\n    public void revertChangeUserPrefixType(Context context) {\n        // Execute on rollback version 1.0.0\n    }\n}\n```\n\n#### Java Migration\n\nCreate java based migration class implementing Migration interface. The up and down method will be executed upon running migrate and rollback command respectively.\n\n```java\npackage db.migration;\n\nimport com.monjam.core.api.Context;\nimport com.monjam.core.api.Migration;\n\npublic class V1_0_0__Change_user_prefix_type implements Migration {\n    @Override\n    public void up(Context context) {\n        // Execute on migrate\n    }\n\n    @Override\n    public void down(Context context) {\n        // Execute on rollback\n    }\n}\n```\n\n#### Script Migration\n\nCreate migrate script `V1_0_0__Change_user_prefix_type.js`\n\n```javascript\ndb.users.update({prefix: 'Mr.'}, {$set: {prefix: 1}}, {multi: true});\ndb.users.update({prefix: 'Mrs.'}, {$set: {prefix: 2}}, {multi: true});\n```\n\n#### File Name Pattern\n\nJava class and script file must follow naming pattern `{Prefix}{Version}__{Description}`\n\n- Prefix: V for migrate, U for rollback (applicable to script migration)\n- Version: Sem-ver format separated each part with underscored\n- Separator: Two underscores\n- Description: Underscores separated words\n\n### Execute Migrate\n`./gradlew monjamMigrate`\n\nAs each migration get applied, the schema migration history collection (default to schema_migrations) is updated with each document corresponding to applied migration\n\n| _id | version | description | executedAt |\n|-----|---------|-------------|------------|\n| 5d3bbedb93b76e755467566d | 1.0.0 | Change user prefix type | 2019-07-27T03:02:51.555Z |\n\n## Command\n\n| Command | Gradle Task | Description |\n|---------|-------------|-------------|\n| Migrate | monjamMigrate | Migrates database to the latest version or target version |\n| Rollback | monjamRollback | Rollback the most recently applied migration or target version |\n\n## Configuration\n\nConfiguration can be defined in build.gradle.\n```\nmonjam {\n    url = 'mongodb://localhost:27017/?replicaSet=rs0'\n    database = 'monjam'\n    collection = 'schema_migrations'\n    location = 'db/migration'\n}\n```\nor using gradle properties passed directly via command-line.\n`./gradlew monjamMigrate -Pmonjam.username=admin -Pmonjam.password=secret`\n\n| Name        | Description                      | Default |\n|-------------|----------------------------------|---------|\n| url         | Connection url                   | -       |\n| database    | Database name                    | -       |\n| username    | Username                         | -       |\n| password    | Password                         | -       |\n| authDatabase | Authentication database name    | admin   |\n| collection  | Collection that store applied schema migrations | schema_migrations |\n| location    | Schema migration files locations | db/migration |\n| target      | Target version to migrate or rollback. For migrate, migration with version higher will be ignored. For rollback, migration with version equals or lower will be ignored | latest version (migrate), previous version (rollback) |\n| scriptMigrationExtension | Script migration file extension | js |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foun%2Fmonjam","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foun%2Fmonjam","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foun%2Fmonjam/lists"}