{"id":41274874,"url":"https://github.com/szarapka/drift-mongo","last_synced_at":"2026-01-23T02:30:56.100Z","repository":{"id":60598195,"uuid":"542221862","full_name":"szarapka/drift-mongo","owner":"szarapka","description":"Multi-environment MongoDB migrations for Node.js","archived":false,"fork":false,"pushed_at":"2025-05-07T19:58:44.000Z","size":378,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-08T21:15:18.322Z","etag":null,"topics":["databse","migrations","mongo","mongodb"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/szarapka.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-09-27T18:00:55.000Z","updated_at":"2025-05-07T19:58:14.000Z","dependencies_parsed_at":"2025-04-27T01:38:43.271Z","dependency_job_id":"26ba25d0-ad69-4fba-8a6e-ea7ed6a1cb8a","html_url":"https://github.com/szarapka/drift-mongo","commit_stats":null,"previous_names":["improper-industries/drift-mongo","szarapka/drift-mongo","iustus-lab/drift-mongo"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/szarapka/drift-mongo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szarapka%2Fdrift-mongo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szarapka%2Fdrift-mongo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szarapka%2Fdrift-mongo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szarapka%2Fdrift-mongo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/szarapka","download_url":"https://codeload.github.com/szarapka/drift-mongo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szarapka%2Fdrift-mongo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28678499,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T01:00:35.747Z","status":"online","status_checked_at":"2026-01-23T02:00:08.296Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["databse","migrations","mongo","mongodb"],"created_at":"2026-01-23T02:30:54.752Z","updated_at":"2026-01-23T02:30:55.969Z","avatar_url":"https://github.com/szarapka.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Drift\n=====\n\nDrift is a simple multi-environment MongoDB migrations CLI tool for Node.js.\n\n## Installation\n\n#### Globally\n\n```\nnpm install -g drift-mongo\n```\n\nWhen installed globally, you can use the `drift` command as needed.\n\n#### Individual project\n\n```\nnpm install drift-mongo --save-dev\n```\n\nWhen installed in a project, you can use `npx drift` within the project folder structure.\n\n## Usage\n\nYou can run `drift` or `drift --help` to see the CLI commands.\n\n```\nUsage: drift [options] [command]\n\nA CLI for multi-environment MongoDB migrations with Node.js\n\nOptions:\n  -V, --version     output the version number\n  -h, --help        display help for command\n\nCommands:\n  init              initializes drift config\n  create \u003cdesc\u003e     creates a new migration\n  env \u003cenv\u003e         adds a new environment to use\n  status [options]  checks the status of migrations\n  up [options]      runs all pending migrations\n  down [options]    rolls back the last migration\n  help [command]    display help for command\n```\n\n## Initialization\n\nDrift requries [Node 22](https://nodejs.org/en) (or higher) installed.\n\nIn the root of the project you'd like to setup migrations for, initialize a new drift configuration.\n\n```\n$ drift init\n\nInitializing drift config...\n\nDrift configuration generated.\nUse your favorite editor to edit the config file at drift/drift.json\n```\n\nRunning this command did two things:\n\n1. created these folders: `drift/migrations`\n2. created a `drift.json` file in the `drift` folder\n\nThe configuration file, `drift.json`, was created with a default environment: `dev`. Edit this file with your development environment details.\n\n## Configuration\n\nThe `drift.json` file maintains your drift configuration for this project, with this initial object structure:\n\n```json\n{\n  \"migration_folder\": \"migrations\",\n  \"envs\": {\n    \"dev\": {\n      \"mongo_host\": \"mongodb+srv://user:pass@localhost:27017\",\n      \"mongo_db\": \"platform\",\n      \"mongo_collection\": \"migrations\"\n    }\n  }\n}\n```\n\n- `migration_folder`: Lets you change the name/path of the migrations folder.\n- `envs`: Holds a environment config object for each configured environment.\n\nIndividual environment configurations have three config properties:\n\n- `mongo_host`: The URI to the MongoDB cluster for the given environment.\n- `mongo_db`: The name of the database you want to run migrations on for the given environment.\n- `mongo_collection`: The name of a collection you want to create/use to track migrations for the given environment.\n\n**Important:** Add the `drift.json` file to your `.gitignore`.\n\n## Adding Environments\n\nYou can add an environment using the CLI, or by editing the `drift.json` file.\n\n```\nUsage: drift env [options] \u003cenv\u003e\n\nAdds a new environment to use\n\nOptions:\n  -h, --help  display help for command\n```\n\nTo add a production environment, you can use the following command:\n\n```\n$ drift env prod\n\nEnvironment added: prod\nEdit the environment at drift/drift.json\n```\n\nRunning this command added a new object to the `envs` object in the `drift.json` configuration file.\n\n```json\n\"envs\": {\n  \"prod\": {\n    \"mongo_host\": \"mongodb+srv://user:pass@localhost:27017\",\n    \"mongo_db\": \"platform\",\n    \"mogno_collection\": \"migrations\"\n  }\n}\n```\n\nEdit `drift.json` to add your connection and DB details.\n\n## Adding Migrations\n\nUse the CLI to add a new migration to drift.\n\n```\nUsage: drift create [options] \u003cdesc\u003e\n\nCreates a new migration\n\nOptions:\n  -h, --help  display help for command\n```\n\nTo add a (test) migration, you can use the following command:\n\n```\n$ drift create test\n\nCreating migration: test\n\nMigration created!\n\nEdit the migration at drift/migrations/1664591812475-test.js\n```\n\nRunning this command added a new migration to the configured migrations folder (`migrations` by default).\n\n## Migrations\n\nUse migration files to perform changes to your database. New migration files are created in the configured migrations folder (`migrations` by default):\n\n```javascript\nexport const up = async (db, client) =\u003e {\n  // Migration code goes here\n}\nexport const down = async (db, client) =\u003e {\n  // Rollback code goes here\n}\n```\n\nEdit this file with your migration code. The `db` object is the official MongoDB object, the `client` object is a MongoClient instance.\n\nMigrations use async-await and your migration code must use async-await and return a promise.\n\n#### Example\n\n```javascript\nexport const up = async (db, client) =\u003e {\n  await db.collection('test').insertOne({test: 'test'})\n}\nexport const down = async (db, client) =\u003e {\n  await db.collection('test').deleteOne({test: 'test'})\n}\n```\n\n## Migrating up\n\nRun all pending migrations on a given environment. If no environment is specified, `dev` is configured as default.\n\n```\nUsage: drift up [options]\n\nruns all pending migrations\n\nOptions:\n  -e --env \u003cenvironment\u003e  environment to run migrations for (default: dev) (default: \"dev\")\n  -h, --help              display help for command\n```\n\nTo run all pending migrations for the `dev` (default) environment use the following command:\n\n```\n$ drift up\n\nMigrated: 1664591812475-test.js\n\nMigrations complete!\n```\n\nTo run all pending migrations for the `prod` environment, use the following command:\n\n```\n$ drift up --env prod\n\nMigrated: 1664591812475-test.js\n\nMigrations complete!\n```\n\nAny error caught will stop the process.\n\n## Migrating down\n\nWhen you need to revert migrations for a given environment, migrating down will revert back through the completed migrations one at a time.\n\n```\nUsage: drift down [options]\n\nrolls back the last migration\n\nOptions:\n  -e --env \u003cenvironment\u003e  environment to run migrations for (default: dev) (default: \"dev\")\n  -h, --help              display help for command\n```\n\nTo revert the last completed migration for the `dev` (default) environment use the following command:\n\n```\n$ drift down\n\nDowngraded: 1664591812475-test.js\n\nRollback complete!\n```\n\nTo rever the last completed migration for the `prod` environment, use the following command:\n\n```\n$ drift down --env prod\n\nDowngraded: 1664591812475-test.js\n\nMigrations complete!\n```\n\n## Migration status\n\nEasily check the status of the migrations for a given environment.\n\n```\nUsage: drift status [options]\n\nchecks the status of migrations\n\nOptions:\n  -e --env \u003cenvironment\u003e  environment to check status for (default: dev) (default: \"dev\")\n  -h, --help              display help for command\n```\n\nTo check the status of migrations for the `dev` (default) environment, use the following command:\n\n```bash\n$ drift status\n\nMigration Status\nEnvironment: dev\n\n┌─────────────────────────┬──────────┬───────────────────────┐\n│ Filename                │ Status   │ Ran On                │\n├─────────────────────────┼──────────┼───────────────────────┤\n│ 1664591812475-test.js   │ migrated │ 9/30/2022, 2:07:06 PM │\n└─────────────────────────┴──────────┴───────────────────────┘\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fszarapka%2Fdrift-mongo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fszarapka%2Fdrift-mongo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fszarapka%2Fdrift-mongo/lists"}