{"id":13881009,"url":"https://github.com/nathanagez/serverless-typeorm-migrations","last_synced_at":"2025-07-16T17:31:38.442Z","repository":{"id":39640351,"uuid":"262161039","full_name":"nathanagez/serverless-typeorm-migrations","owner":"nathanagez","description":"Database migrations for AWS Lambda and RDS using TypeORM Migrations","archived":true,"fork":false,"pushed_at":"2022-12-11T05:01:08.000Z","size":231,"stargazers_count":45,"open_issues_count":1,"forks_count":12,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-05T19:10:21.024Z","etag":null,"topics":["database","migrations","serverless"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/serverless-typeorm-migrations","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nathanagez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-07T21:20:29.000Z","updated_at":"2024-12-18T16:42:22.000Z","dependencies_parsed_at":"2022-08-28T10:50:25.022Z","dependency_job_id":null,"html_url":"https://github.com/nathanagez/serverless-typeorm-migrations","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nathanagez/serverless-typeorm-migrations","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanagez%2Fserverless-typeorm-migrations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanagez%2Fserverless-typeorm-migrations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanagez%2Fserverless-typeorm-migrations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanagez%2Fserverless-typeorm-migrations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nathanagez","download_url":"https://codeload.github.com/nathanagez/serverless-typeorm-migrations/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanagez%2Fserverless-typeorm-migrations/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265002559,"owners_count":23696076,"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":["database","migrations","serverless"],"created_at":"2024-08-06T08:03:46.569Z","updated_at":"2025-07-16T17:31:36.833Z","avatar_url":"https://github.com/nathanagez.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"[![Serverless](https://miro.medium.com/max/5274/1*CuALG7dV2rLky1sapJbnUQ.png)](http://serverless.com)\n# Serverless TypeORM Migrations\n\nDatabase migrations for AWS Lambda and RDS using [TypeORM Migrations](https://typeorm.io/#/migrations).\n\n## About\n\nThis Serverless plugin can execute and rollback database migrations after deploys. See [Usage](#usage)\n\nThis plugin supports MySQL / MariaDB / Postgres / CockroachDB / SQLite / Microsoft SQL Server / sql.js\n\n\u003e Inspired by [serverless-pg-migrations](https://github.com/Nevon/serverless-pg-migrations). I use TypeORM so I wrote my own plugin\n\n**NOTES:**\n\n  * This plugin does not attempt to add handlers automatically (see [Adding handlers](#usage))\n  * This plugin does not create or drop databases\n  * This plugin does not have a handler for checking database connection\n\n## Migrations\n\nYou need to specify your `migration` folder\n\nFor details on using migrations please see the [TypeORM Migration](https://typeorm.io/#/migrations) docs.\n\n## Installation\n\n```bash\n$ yarn add serverless-typeorm-migrations\n```\nOR \n```bash\n$ npm install serverless-typeorm-migrations\n```\n\n## Usage\n\nDefine a migration handler somewhere in your project. Example:\n\n```js\n// /migrations.js\n\nconst { up, down } = require(\"serverless-typeorm-migrations/build/handlers\");\n\nmodule.exports.up = up;\n\nmodule.exports.down = down;\n```\n\n```ts\n// /migrations.ts\n\nexport { up, down } from 'serverless-typeorm-migrations/build/handlers';\n\n```\n\nAdd the plugin and handlers to your `serverless.yml`:\n\n```yml\nprovider:\n  name: aws\n\nplugins:\n  - serverless-typeorm-migrations\n\nfunctions:\n  up:\n    handler: migrations.up\n    timeout: 30\n    environment:\n      SLS_TYPEORM_MIGRATIONS_ENGINE: \"postgres\"\n      SLS_TYPEORM_MIGRATIONS_FOLDER: \"src/migration/**/*.js\"\n      # using url parameter\n      SLS_TYPEORM_MIGRATIONS_DATABASE_URL: \"postgres://root:password@domain.rds.amazonaws.com:5432/database\"\n  down:\n    handler: migrations.down\n    timeout: 30\n    environment:\n      SLS_TYPEORM_MIGRATIONS_ENGINE: \"postgres\"\n      SLS_TYPEORM_MIGRATIONS_FOLDER: \"src/migration/**/*.js\"\n      # using host, port, db name, username and password\n      SLS_TYPEORM_MIGRATIONS_DATABASE_HOST: \"domain.rds.amazonaws.com\"\n      SLS_TYPEORM_MIGRATIONS_DATABASE_PORT: \"5432\"\n      SLS_TYPEORM_MIGRATIONS_DATABASE_NAME: \"database\"\n      SLS_TYPEORM_MIGRATIONS_DATABASE_USERNAME: \"root\"\n      SLS_TYPEORM_MIGRATIONS_DATABASE_PASSWORD: \"cGFzc3dvcmQ=\" # base64 of 'password'\n```\n\nPass the function to the serverless deploy command to have it execute after the deploy is finished:\n\n```\nsls deploy --function up\n```\n\nYou can also manually invoke the functions locally:\n\n```\nsls invoke local --function up\n```\n\nOr use the plugin directly without going through your function:\n\n```\nsls migrate up\nsls migrate down\n```\n\n## Configuration\n\nThe functions need to have the following environment variables :\n- `SLS_TYPEORM_MIGRATIONS_FOLDER` pointing migrations folder\n- `SLS_TYPEORM_MIGRATIONS_ENGINE` defining database driver\n- `SLS_TYPEORM_MIGRATIONS_DATABASE_URL` set to a valid [connection uri](https://typeorm.io/#/connection/creating-a-new-connection).\n- `SLS_TYPEORM_MIGRATIONS_DATABASE_HOST` set to a valid [host address](https://typeorm.io/#/connection/creating-a-new-connection).\n- `SLS_TYPEORM_MIGRATIONS_DATABASE_PORT` set to a valid [port number](https://typeorm.io/#/connection/creating-a-new-connection).\n- `SLS_TYPEORM_MIGRATIONS_DATABASE_NAME` set to a valid [database name](https://typeorm.io/#/connection/creating-a-new-connection).\n- `SLS_TYPEORM_MIGRATIONS_DATABASE_USERNAME` set to a valid [username](https://typeorm.io/#/connection/creating-a-new-connection).\n- `SLS_TYPEORM_MIGRATIONS_DATABASE_PASSWORD` set to a valid Base64 encoded [password](https://typeorm.io/#/connection/creating-a-new-connection).\n\nYou need to define variable URL or host, port, db name, username and password.\nPay attention that `SLS_TYPEORM_MIGRATIONS_DATABASE_PASSWORD` is base64 encoded!\n\n## NestJS example\n\nIf you are using NestJS with serverless framework you have to create a `ormconfig.js` file in your root folder within the following content to generate migration:\n\n```js\nmodule.exports = {\n  type: 'your_driver',\n  host: process.env.DB_HOST,\n  port: parseInt(process.env.DB_PORT),\n  username: process.env.DB_USER,\n  password: process.env.DB_PASSWORD,\n  database: process.env.DB_NAME,\n  entities: ['your_entities_folder/**/*.ts'],\n  migrations: ['your_migrations_folder/**/*.ts'],\n  subscribers: ['your_subscribers_folder/**/*.ts'],\n  cli: {\n    entitiesDir: 'your_entities_folder',\n    migrationsDir: 'your_migrations_folder',\n    subscribersDir: 'your_subscribers_folder',\n  },\n};\n\n```\nNext you have to transpile .ts migration files to .js to make it work before deploying or invoking functions\n\nHere is my `package.json` scripts as example\n```json\n{\n\"migration:create\": \"typeorm migration:create -n\",\n\"migration:generate\": \"ts-node node_modules/.bin/typeorm migration:generate -n\",\n\"migration:up\": \"tsc src/migration/*.ts \u0026\u0026 serverless migrate up \u0026\u0026 rm -r src/migration/*.js\",\n\"migration:down\": \"tsc src/migration/*.ts \u0026\u0026 serverless migrate down \u0026\u0026 rm -r src/migration/*.js\"\n}\n```\nAnd finally, configure the plugin with these [environment variables](#configuration)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathanagez%2Fserverless-typeorm-migrations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnathanagez%2Fserverless-typeorm-migrations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathanagez%2Fserverless-typeorm-migrations/lists"}