{"_id":"@animiru/ani-migrate","_rev":"3-b9105d61f3b4134137151c26bfcfc7b0","name":"@animiru/ani-migrate","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@animiru/ani-migrate","version":"1.0.0","description":"PostgreSQL script migrator.","main":"bin","bin":{"ani-migrate":"bin/index.js"},"scripts":{"build":"tsc"},"repository":{"type":"git","url":"git+https://github.com/Animiru/ani-migrate.git"},"keywords":["animiru","pg","postgres","postgresql","migrate","migration","animigrate"],"author":"","license":"ISC","bugs":{"url":"https://github.com/Animiru/ani-migrate/issues"},"homepage":"https://github.com/Animiru/ani-migrate#readme","devDependencies":{"@types/colors":"^1.2.1","@types/node":"^16.10.2","@types/pg":"^8.6.1","@types/underscore":"^1.11.3","@typescript-eslint/eslint-plugin":"^4.32.0","@typescript-eslint/parser":"^4.32.0","eslint":"^7.32.0","typescript":"^4.4.3"},"dependencies":{"colors":"1.4.0","pg":"8.5.1","underscore":"^1.13.1"},"gitHead":"74f74cf4898b06319ed8e38e91bd3914d27e8015","_id":"@animiru/ani-migrate@1.0.0","_nodeVersion":"16.6.2","_npmVersion":"7.20.3","dist":{"integrity":"sha512-zXqGnYCN9oV2iyRTNKvxTg/nvo3QmsKTMasgvCUyYcIw9a9jFUDyK9EpYNUAU150tvys2WDFviRwO++eHgO3Ig==","shasum":"15b5fb5752c5f31f685a3c1a5f76f70895c831ee","tarball":"https://registry.npmjs.org/@animiru/ani-migrate/-/ani-migrate-1.0.0.tgz","fileCount":10,"unpackedSize":24763,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh11lECRA9TVsSAnZWagAAIMAQAIW24iP2+3KAe1KXPlCE\nfqoFxvEdP4c7vEaE2xD7uqyl4walNc+uICNpQOE+ssiRRjcfUrkEjT3IH2Kl\n16KPbwsiKKFz+g58hZ74KbL12Xsu+xq+hyeHOa0cuwPLCQK8/nOQ4dzmkMpV\nDUj4kh31DdovhY17eXnmaobpdO75weEM49AUES7nWOIbSNwFw3nkfYWTDxQb\nuIbOX93sooduqZEjOZipOd3Ats41UIcQbPd59nk3d3HRFweM0VoJ2kSF1Duv\nf4nIIIqIH4hf6ooFJl5BVpwPxUPVDsPpFoSq6q960mt/4s3fg23DumXqPaCK\nY/SWHF5+WJxeT9LneATN+G8yehnv0IM5OqVrtxFIJtqxhNi9hBH94EMEvWqI\ncYTzjgq0l+pzAn8nPSlrMEgeX0heJO22HBmfdUy1NOp7cE5z0wODKxqMzwql\nds3qPmOQZghd/Ze6w7FPNQYYtgwbjm/1e0p+vzMiyENpooBOS1KlJpxhNidN\nVyEuzulQf05tKo6OgjQvIVQD1lCZinGtMM/TuX+LqpBDljdhzdt+7mh4cQtD\n1gZ7az7dIXiowCXs27mBg1mN0EWHD+qbdSLtvxWUyh41C80tSWHcz06b+5h6\njivysT6w50BMmRvh3qZ7E4HdI+sXKbFdWaHMNz0jI0vboRJhHLgPpt3s3ZLx\nPrSP\r\n=c1Dy\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDUDYlNQ9mA/Hpiwry/RiUa4QTCU+OrYvFy75tO9i8EoAiAB92gWl+qEyaQST1liWiTItZIQ/c2WuPoGe4p+QZ8thA=="}]},"_npmUser":{"name":"nobuwu","email":"nowobuwu@gmail.com"},"directories":{},"maintainers":[{"name":"nobuwu","email":"nowobuwu@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ani-migrate_1.0.0_1633228433914_0.5736394047726172"},"_hasShrinkwrap":false}},"time":{"created":"2021-10-03T02:33:53.840Z","1.0.0":"2021-10-03T02:33:54.066Z","modified":"2022-04-04T14:11:43.460Z"},"maintainers":[{"email":"npm@nobu.sh","name":"nobush"}],"description":"PostgreSQL script migrator.","homepage":"https://github.com/Animiru/ani-migrate#readme","keywords":["animiru","pg","postgres","postgresql","migrate","migration","animigrate"],"repository":{"type":"git","url":"git+https://github.com/Animiru/ani-migrate.git"},"bugs":{"url":"https://github.com/Animiru/ani-migrate/issues"},"license":"ISC","readme":"ani-migrate\r\n===========\r\nani-migrate is a PostgreSQL migration package that allows for versioning to keep all database migrations clean and mess free!\r\n\r\nThis package is highly based off of [pg-migrator](https://github.com/Aphel-Cloud-Solutions/pg-migrator/) with some enhancements.\r\n\r\n## Features\r\n  * Forward and backwards migrations\r\n  * Migration to a specifc version\r\n  * Sub folder deep search\r\n  * Transactional migration\r\n  * No remote session required\r\n  * Optional schema based versioning\r\n\r\n## Installation\r\n\r\n```\r\nnpm install -g @animiru/ani-migrate\r\n```\r\n\r\n## Quick Start\r\nTo keep things a little more organized *ani-migrate* requires there to be a dedicated directory for migrations. This directory can be named anything the only rule is it contains a file named `.ani-migrate`.\r\n\r\nWe will talk more about `.ani-migrate` later.\r\n\r\n\r\n`Example Hierarchy`\r\n\r\n```\r\nproject\r\n  ├─ migrations\r\n  │   ├─ .ani-migrate\r\n  │   ├─ 1-2.sql\r\n  │   ├─ 2-1.sql\r\n  │   └─ ...\r\n  ├─ src\r\n  │   ├─ index.js\r\n  │   └─ ...\r\n  └─ package.json\r\n```\r\nNow with a migrations directory we can use the following command to migrate to the highest migration in our directory.\r\n\r\n```\r\nani-migrate postgres://username:pass@host/somedb\r\n```\r\n\r\n## More In Depth\r\nAs seen in the basic usage it is pretty simple to get started but we also offer some more in depth features.\r\n### Hierarchy\r\nAbove you saw an example hierarchy we provided. Well `ani-migrate` actually provides a deep sub folder search. Therefore you can organize your migrations directory however you please.\r\n\r\n`Advanced Hierarchy`\r\n\r\n```\r\nproject\r\n  ├─ migrations\r\n  │   ├─ .ani-migrate\r\n  │   ├─ v1.0.0\r\n  │   │   ├─ 1-2.sql\r\n  │   │   ├─ 2-1.sql\r\n  │   │   ├─ 2-3.sql\r\n  │   │   └─ 3-2.sql\r\n  │   ├─ v2.0.0\r\n  │   │   ├─ 3-4.sql\r\n  │   │   └─ 4-3.sql\r\n  │   └─ ...\r\n  ├─ src\r\n  │   ├─ index.js\r\n  │   └─ ...\r\n  └─ package.json\r\n```\r\nSomething as advanced as this would be 100% valid not to mention you can have sub folders inside of your sub folders to the power of infinity.\r\n\r\n### Steps\r\nAnother concern or issue you may have from above is  \"what if I want to migrate backwards?\" or \"what if a want to migrate 5 steps forward?\". Well we have you 100% covered.\r\n\r\n<br>\r\n\r\n```\r\nani-migrate postgres://username:pass@host/somedb +1\r\n```\r\n> Migrate up 1 step\r\n```\r\nani-migrate postgres://username:pass@host/somedb -1\r\n```\r\n> Migrate down 1 step\r\n```\r\nani-migrate postgres://username:pass@host/somedb -5\r\n```\r\n> Migrate to back 5 versions\r\n```\r\nani-migrate postgres://username:pass@host/somedb 5\r\n```\r\n> Migrate to migration 4-5.sql\r\n\r\n### `.ani-migrate`\r\nThis file is not as cool as it seems. It is used to config schema based migrations.\r\n\r\n`Example .ani-migrate`\r\n```\r\n# ani-migrate config\r\n```\r\nAs stated above, its not that interesting. It  mainly stands as a landmark for what directory contains migrations and config for schema based migrations.\r\n\r\n## Migration Scripts\r\nani-migrate will utilize all migrations scripts located anywhere withing the migration folder that follow the format `x-y.sql` (case insensitive).\r\n\r\nAs stated above the migration scripts can be organized and categorized however you wish. ani-migrate will search all sub folders and sub folders of sub folders to the power of infinity.\r\n\r\n`Sample Migration Names`\r\n```\r\n17-18.sql : Migration script from version 17 to version 18 for forward migration\r\n18-17.sql : Migration script from version 18 to version 17 for backwards migration\r\n```\r\n### NOTE\r\nYour first migration needs to be `1-2.sql` we do not start at 0!\r\n\r\n## Per Schema Migrations\r\nPer schema migrations is one of the more interesting parts of this package.\r\n\r\nA use case of this would be say you have two sub projects under one main project that need to access each others tables. Rather than creating two seperate databases and having two seperate connection. We can use schema based migrations to utilize the same database for multiple projects using migrations.\r\n\r\nThis may sound quite confusing so lets put it into example.\r\n\r\n### Project A\r\nIn project a we will have a service that constantly monitors youtube for new uploads and stores their links.\r\n\r\n`Hierarchy`\r\n\r\n```\r\nyt-watcher\r\n  ├─ migrations\r\n  │   ├─ .ani-migrate\r\n  │   ├─ 1-2.sql\r\n  │   ├─ 2-1.sql\r\n  │   └─ ...\r\n  ├─ src\r\n  │   ├─ index.js\r\n  │   └─ ...\r\n  └─ package.json\r\n```\r\n\r\n`.ani-migrate`\r\n```\r\n# ani-migrate config\r\n\r\nschema=youtube\r\n```\r\n\r\n`1-2.sql`\r\n```sql\r\nCREATE SCHEMA IF NOT EXISTS youtube;\r\n\r\nSET search_path TO youtube, public;\r\n\r\nCREATE TABLE IF NOT EXISTS youtube.new_upload (\r\n  \"url\": text NOT NULL,\r\n  \"uploaded\" timestamp NOT NULL\r\n);\r\n```\r\n\r\n`2-1.sql`\r\n```sql\r\nDROP SCHEMA IF EXISTS youtube CASCADE;\r\n```\r\n\r\n```\r\nani-migrate postgres://username:pass@host/testdb\r\n```\r\n\r\n`Project A` now has a config setup to tell `ani-migrate` to store the versioning table under the youtube schema and only version migrations for the youtube schema nothing else.\r\n\r\n### Project B\r\nIn this project we are reading the uploaded videos from teh database but we also need to store user info for people who login on our site.\r\n\r\n`Hierarchy`\r\n\r\n```\r\nwebsite\r\n  ├─ migrations\r\n  │   ├─ .ani-migrate\r\n  │   ├─ 1-2.sql\r\n  │   ├─ 2-1.sql\r\n  │   └─ ...\r\n  ├─ src\r\n  │   ├─ index.js\r\n  │   └─ ...\r\n  └─ package.json\r\n```\r\n\r\n`.ani-migrate`\r\n```\r\n# ani-migrate config\r\n\r\nschema=website\r\n```\r\n\r\n`1-2.sql`\r\n```sql\r\nCREATE SCHEMA IF NOT EXISTS website;\r\n\r\nSET search_path TO website, public;\r\n\r\nCREATE TABLE IF NOT EXISTS website.users (\r\n  \"username\": varchar(32) NOT NULL,\r\n  \"password\" varchar(64) NOT NULL\r\n);\r\n```\r\n\r\n`2-1.sql`\r\n```sql\r\nDROP SCHEMA IF EXISTS website CASCADE;\r\n```\r\n```\r\nani-migrate postgres://username:pass@host/testdb\r\n```\r\n\r\nNow `Project B` also has its own table under the schema `website` on the same database `testdb` so we can have 1 connection to read youtube episodes and user info. \r\n\r\n### In Conclusion\r\n\r\nSince we told `ani-migrate` in the config for each project to only utilize a specific schema, neither of the migrations will conflict.\r\n\r\n## [Examples](./examples)","readmeFilename":"README.md"}