{"_id":"@dservidie/dynamo-data-migrations","name":"@dservidie/dynamo-data-migrations","dist-tags":{"latest":"4.1.5"},"versions":{"4.1.5":{"name":"@dservidie/dynamo-data-migrations","version":"4.1.5","description":"A library to easily run migrations on DynamoDB with TypeScript. (forked from dynamo-data-migrations)","main":"build/src/lib/migrateDynamo.js","types":"build/src/lib/migrateDynamo.d.ts","bin":{"dynamo-data-migrations":"build/src/bin/migrateDynamo.js"},"scripts":{"check-types":"tsc --noEmit","clean:build":"node -e \"require('del').sync(['build/**'])\"","prebuild":"npm run clean:build","build":"tsc && cp -r  ./src/templates/ ./build/src/","test":"jest --coverage --color --runInBand --silent","lint":"eslint --ext .ts .","lint:fix":"eslint --ext .ts . --fix","prettier":"prettier 'src/**/*.ts'","prettier:fix":"prettier --write 'src/**/*.ts'","pre-commit":"npm run check-types && npm run lint:fix && git add .","pre-push":"npm run test","prepare":"npm run build && husky install","prepublishOnly":"npm test && npm run lint"},"author":"","license":"MIT","keywords":["dynamodb migrations database data"],"repository":{"type":"git","url":"git+https://github.com/dservidie/dynamo-data-migrations.git"},"engines":{"node":">=16.0.0","npm":">=6.12.0"},"preferGlobal":true,"dependencies":{"aws-sdk":"^2.1113.0","cli-table3":"^0.6.3","commander":"^9.1.0","del":"^6.0.0","fs-extra":"^10.1.0","lodash":"^4.17.21","p-each-series":"^2.2.0","ts-import":"^4.0.0-beta.8"},"devDependencies":{"@aws-sdk/types":"^3.55.0","@babel/core":"^7.21.0","@babel/preset-env":"^7.20.2","@types/fs-extra":"^9.0.13","@types/jest":"^27.4.1","@types/jest-when":"^3.5.2","@types/lodash":"^4.14.182","@types/node":"^17.0.23","@types/sinon":"^10.0.13","@typescript-eslint/eslint-plugin":"^5.21.0","@typescript-eslint/parser":"^5.23.0","aws-sdk-mock":"^5.8.0","babel-jest":"^29.4.3","dynalite":"^3.2.2","eslint":"^7.32.0","eslint-config-airbnb-typescript":"^12.3.1","eslint-config-prettier":"^6.10.1","eslint-formatter-pretty":"^4.1.0","eslint-plugin-import":"^2.20.1","eslint-plugin-jest":"^24.3.6","eslint-plugin-jsx-a11y":"^6.3.1","eslint-plugin-promise":"^5.1.0","eslint-plugin-react":"^7.20.5","eslint-plugin-react-hooks":"^4.0.8","eslint-plugin-unicorn":"^33.0.1","husky":"^8.0.0","jest":"^29.4.3","jest-when":"^3.5.2","prettier":"^2.6.2","sinon":"^15.0.0","ts-jest":"^29.0.5","ts-jest-resolver":"^2.0.0","ts-loader":"^9.2.8","ts-node":"^10.7.0","typescript":"^4.9.5","webpack":"^5.72.0"},"eslintConfig":{"extends":["airbnb-base","prettier"],"parserOptions":{"ecmaVersion":2018}},"jest":{"testMatch":["**/tests/**/*.spec.ts"],"resolver":"ts-jest-resolver","moduleFileExtensions":["ts","js","json"],"rootDir":".","transform":{"^.+\\.(t)s$":"ts-jest","^.+\\.mts":"ts-jest","^.+\\.mjs":"babel-jest"},"testEnvironment":"node","collectCoverage":false,"coverageThreshold":{"global":{"branches":90,"functions":90,"lines":90}},"silent":true,"restoreMocks":true},"babel":{"env":{"test":{"presets":[["@babel/preset-env",{"modules":false}]],"plugins":[["@babel/plugin-transform-modules-commonjs",{"spec":true}]]}}},"_id":"@dservidie/dynamo-data-migrations@4.1.5","gitHead":"a14e9032afc6e00ee80cbd4a0322471bcb9ff26b","bugs":{"url":"https://github.com/dservidie/dynamo-data-migrations/issues"},"homepage":"https://github.com/dservidie/dynamo-data-migrations#readme","_nodeVersion":"20.10.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-maXFmOXmBqSk907lkTsrxzJaVwgjTFooyjHI68lNnC7gQIC316NLmShYpanEEa+So577MKu9eM/E3G0Y2cP/Mw==","shasum":"69e8f84022948e873ea9e826b8845a4eac7d4e54","tarball":"https://registry.npmjs.org/@dservidie/dynamo-data-migrations/-/dynamo-data-migrations-4.1.5.tgz","fileCount":89,"unpackedSize":176962,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC6qCB1JVvTshfcCMpjTp0tqtkIOiVcs3Ot6PeGsSA8FwIgANg5Lv6DyO+bhl0vLGa9VYTWAWCusREPjjTYAymdvWc="}]},"_npmUser":{"name":"dservidie","email":"dservidie@gmail.com"},"directories":{},"maintainers":[{"name":"dservidie","email":"dservidie@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/dynamo-data-migrations_4.1.5_1722564553348_0.7219739556935283"},"_hasShrinkwrap":false}},"time":{"created":"2024-08-02T02:09:13.216Z","4.1.5":"2024-08-02T02:09:13.592Z","modified":"2024-08-02T02:09:13.896Z"},"maintainers":[{"name":"dservidie","email":"dservidie@gmail.com"}],"description":"A library to easily run migrations on DynamoDB with TypeScript. (forked from dynamo-data-migrations)","homepage":"https://github.com/dservidie/dynamo-data-migrations#readme","keywords":["dynamodb migrations database data"],"repository":{"type":"git","url":"git+https://github.com/dservidie/dynamo-data-migrations.git"},"bugs":{"url":"https://github.com/dservidie/dynamo-data-migrations/issues"},"license":"MIT","readme":"![Build Badge](https://github.com/dservidie/dynamo-data-migrations/actions/workflows/pr.yml/badge.svg)\r\n\r\n## Introduction\r\n\r\n`dynamo-data-migrations` is a database migration tool with DynamoDb support. It supports generation of migration file with extension `.ts`(TS projects), `.cjs`(CJS type JS projects) or `.mjs`(ESM type JS projects) as per source project language.\r\n\r\n\r\n## Installation\r\n```bash\r\n$ npm install -g dynamo-data-migrations\r\n```\r\n\r\n## Usage\r\n```\r\n$ dynamo-data-migrations\r\nUsage: dynamo-data-migrations [options] [command]\r\nOptions:\r\n  -V, --version                   output the version number\r\n  -h, --help                      display help for command\r\n\r\nCommands:\r\n  init                            initialize a new migration project\r\n  create [description]            create a new database migration with the provided description\r\n  up [options]                    run all pending database migrations against a provided profile.\r\n  down [options]                  undo the last applied database migration against a provided profile.\r\n  status [options]                print the changelog of the database against a provided profile\r\n  help [command]                  display help for command\r\n```\r\n\r\n\r\n## Initialize a new project\r\n\r\n1. Initialize a new dynamo-data-migrations project.\r\n\r\n    ```bash\r\n    $ dynamo-data-migrations init\r\n\r\n    Initialization successful. Please edit the generated config.json file\r\n    ```\r\n\r\n## Editing config.json\r\nThe `config.json` generated during the `init` phase contains configuration information as required to run the `up`, `down` and `status` commands. Below is a brief description of the details specified in the file.\r\n   1. `awsConfig`: This section is used to store AWS credentials and region of the AWS account against which you want to execute the up/down/status commands.\r\n       You can specify multiple profiles, if profile is not specified it is considered as `default` profile. **Region is mandatory for each profile**. \r\n        `accessKeyId` and `secretAccessKey` are optional, if not provided the credentials are loaded from AWS SharedCredentials file or from AWS environment variables. For more information, refer [Setting Credentials in Node.js](https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-credentials-node.html). \r\n       \r\n   2. `migrationsDir`: This value specifies the directory containing the migration files. By default during `init` phase `migrations` directory is created. If you want to use your own migration directory, specify the path (relative or absolute) in this section and **ensure the directory is created before executing any up/down/status command**.\r\n   3. `migrationType` : Ensure a value from `ts`,`cjs` and `mjs` is provided here, based on which the migration script will be generated.\r\n\r\n\r\n## Creating a new migration script\r\nTo create a new database migration script, just run the ````dynamo-data-migrations create [description]```` command. This will create a file  with the current timestamp prefixed in the filename. The file extension will be determined by the `migrationType` field value in `config.json`. The file will hold the signature of the `up` and `down` where migration details are to be specified.\r\nTemplates are at : https://github.com/technogise/dynamo-data-migrations/tree/main/src/templates\r\n\r\n````bash\r\n$ dynamo-data-migrations create sample_migration_1\r\nCreated: migrations/1674549369392-sample_migration_1.ts\r\n````\r\n\r\n### Checking the status of the migrations\r\nAt any time, you can check which migrations are applied (or not). Pass the profile option when you want to run the command in specific environments(dev,test etc).\r\n\r\n````bash\r\n$ dynamo-data-migrations status --profile dev\r\n\r\n┌─────────────────────────────────────┬────────────┐\r\n│ Filename                            │ Applied At │\r\n├─────────────────────────────────────┼────────────┤\r\n│ 1674549369392-sample_migration_1.ts │ PENDING.   |   \r\n└─────────────────────────────────────┴────────────┘\r\n\r\n````\r\n\r\n### Migrate up\r\nThis command will apply all **pending migrations** in the migrations dir picking up files in ascending order as per the name.\r\nIf no profile is passed it will use the `AWS_PROFILE` environment variable or the AWS configuration from the `default` profile.\r\nIf this is the first time that `up` command is executing against a particular AWS account then it also creates a `MIGRATIONS_LOG_DB` table to hold the migrated entries. \r\n**If an an error occurred while migrating a particular file, it will stop and won't continue with the rest of the pending migrations.**\r\n\r\nExample: For `default` profile\r\n````bash\r\n$  dynamo-data-migrations up\r\nMIGRATED UP: 1674549369392-sample_migration_1.ts\r\nMIGRATED UP: 1674549369492-sample_migration_2.ts\r\n````\r\nTo execute profile `dev`\r\n````bash\r\n$  dynamo-data-migrations up --profile dev\r\nMIGRATED UP: 1674549369392-sample_migration_1.ts\r\nMIGRATED UP: 1674549369492-sample_migration_2.ts\r\n````\r\n\r\nIf we check the status again, we can see the all the migrations was successfully applied:\r\n````bash\r\n$ dynamo-data-migrations status\r\n┌─────────────────────────────────────────┬──────────────────────────┐\r\n│ Filename                                │ Applied At               │\r\n├─────────────────────────────────────────┼──────────────────────────┤\r\n│ 1674549369392-sample_migration_1.ts     │ 2016-06-08T20:13:30.415Z │\r\n│ 1674549369492-sample_migration_2.ts     │ 2016-06-08T20:13:35.415Z │\r\n└─────────────────────────────────────────┴──────────────────────────┘\r\n````\r\n### Migrate down\r\nWith this command and without any parameters, dynamo-data-migrations will revert only the last applied migration.\r\nYou can also pass the number of downshifts to be done i.e. you can rollback last `n` installed migrations. If you want to rollback all applied migrations pass the `shift` argument wih value `0`\r\n\r\nBelow will revert last 2 applied migrations.\r\n````bash\r\n$ dynamo-data-migrations down --shift 2\r\nMIGRATED DOWN: 1674549369392-sample_migration_1.ts \r\nMIGRATED DOWN: 1674549369392-sample_migration_2.ts \r\n````\r\n","readmeFilename":"README.md"}