{"id":13675762,"url":"https://github.com/acro5piano/kysely-migration-cli","last_synced_at":"2025-07-29T16:43:37.067Z","repository":{"id":50545825,"uuid":"480202846","full_name":"acro5piano/kysely-migration-cli","owner":"acro5piano","description":"A thin library to create a migration script using Kysely ","archived":false,"fork":false,"pushed_at":"2024-12-17T06:19:34.000Z","size":70,"stargazers_count":73,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-07-29T06:25:50.512Z","etag":null,"topics":["database","kysely","migration","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/kysely-migration-cli","language":"TypeScript","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/acro5piano.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-04-11T02:41:02.000Z","updated_at":"2025-06-26T17:23:42.000Z","dependencies_parsed_at":"2023-11-07T17:35:51.952Z","dependency_job_id":"0c3806e6-046e-4520-a19f-c0febc9a2201","html_url":"https://github.com/acro5piano/kysely-migration-cli","commit_stats":{"total_commits":19,"total_committers":1,"mean_commits":19.0,"dds":0.0,"last_synced_commit":"03ce3cb46f2306cf700117bd7ecff931d648b075"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/acro5piano/kysely-migration-cli","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acro5piano%2Fkysely-migration-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acro5piano%2Fkysely-migration-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acro5piano%2Fkysely-migration-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acro5piano%2Fkysely-migration-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/acro5piano","download_url":"https://codeload.github.com/acro5piano/kysely-migration-cli/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acro5piano%2Fkysely-migration-cli/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267718934,"owners_count":24133466,"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","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"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":["database","kysely","migration","typescript"],"created_at":"2024-08-02T12:01:01.243Z","updated_at":"2025-07-29T16:43:37.023Z","avatar_url":"https://github.com/acro5piano.png","language":"TypeScript","funding_links":[],"categories":["CLIs"],"sub_categories":[],"readme":"# kysely-migration-cli\n\nA lightweight migration CLI **library** for [Kysely](https://github.com/koskimas/kysely)\n\n# Installation\n\nInstall using the dependency manager of your choice\n\n```typescript\n// NPM\nnpm install --save kysely-migration-cli\n\n// PNPM\npnpm add kysely-migration-cli\n\n// YARN\nyarn add kysely-migration-cli\n```\n\n# Usage\n\n`kysely-migration-cli` is a **library** designed to assist you in creating your own migration script. It does not aim to provide an executable command.\n\nCreate a migration script as shown below:\n\n```typescript\n// scripts/migrate.ts\n\nimport * as path from 'path'\nimport { promises as fs } from 'fs'\nimport pg from 'pg'\nimport { Kysely, Migrator, PostgresDialect, FileMigrationProvider } from 'kysely'\nimport { run } from 'kysely-migration-cli'\n\n// For ESM environment\nconst migrationFolder = new URL('../migrations', import.meta.url).pathname\n\n// For CJS environment\n// const migrationFolder = path.join(__dirname, '../migrations')\n\nconst db = new Kysely\u003cYourDbType\u003e({\n  dialect: new PostgresDialect({\n    pool: new pg.Pool({\n      connectionString: process.env.DATABASE_URL,\n    }),\n  }),\n})\n\nconst migrator = new Migrator({\n  db,\n  provider: new FileMigrationProvider({\n    fs,\n    path,\n    migrationFolder,\n  }),\n})\n\nrun(db, migrator, migrationFolder)\n```\n\nNote: The above script assumes your migration folder is located at the same directory of chdir and named `./migrations`\n\nThen run:\n\n```bash\n# Choose your preferred tool. Here are some examples:\n#\n#   $ node -r esbuild-register scripts/migrate.ts -h\n#   $ node -r ts-node/register scripts/migrate.ts -h\n#   $ node -r babel-node/register scripts/migrate.ts -h\n#   $ ts-node-transpile-only scripts/migrate.ts -h\n#   $ npm run tsc \u0026\u0026 node scripts/migrate.js -h\n#   $ bun run scripts/migrate.ts -h\n\n$ node -r esbuild-register scripts/migrate.ts -h\n```\n\nOutput:\n\n```\nUsage: kysely-migration-cli [options] [command]\n\nOptions:\n  -h, --help                display help for command\n\nCommands:\n  up                        Run a pending migration if any\n  down                      Revert the latest migration with a down file\n  redo                      Down and Up\n  latest                    Run all pending migrations\n  down-to \u003cmigration-name\u003e  Migrates down to the specified migration name. Specify\n                            \"NO_MIGRATIONS\" to migrate all the way down.\n  create \u003cinput-file\u003e       Create a new migration with the given description, and\n                            the current time as the version\n  help [command]            display help for command\n```\n\n# Migration creation\n\nThe `create` command generates a migration boilorplate with the current timestamp. For example, running `node -r ts-node/register scripts/migrate.ts create initial` creates a file named `migrations/20220222T044655-initial.ts` with the following code:\n\n\u003c!-- prettier-ignore --\u003e\n```ts\nimport { type Kysely } from 'kysely'\n\nexport async function up(db: Kysely\u003cany\u003e): Promise\u003cvoid\u003e {\n}\n\nexport async function down(db: Kysely\u003cany\u003e): Promise\u003cvoid\u003e {\n}\n```\n\nIf you want to modify the default template, you can pass an option `--template=yourtemplate.txt` pointing to a file containing the custom template\n\nIf you want to change the path where migration files are stored, please modify the CLI code as follows:\n\n```typescript\n// scripts/migrate.ts\n\n// ...\n\nrun(db, migrator, 'dir/to/migration/files')\n```\n\n# Experimental: CLI without a script file\n\nImportant Notes:\n\n- This is an experimental feature, and the behavior may change in the future.\n- Currently, it only works with Postgres.\n\nYou can run `kysely-migration-cli` without a script file.\n\n```\nenv DATABASE_URL=postgres://postgres:postgres@127.0.0.1:5432/postgres \\\n  npm run kysely-migration-cli\n```\n\nIf you place an `.env` file containing `DATABASE_URL=postgres://...`, the CLI will automatically load it before execution. To enable this, you need to install the dotenv module (`npm install dotenv`) .\n\nTo transpile TypeScript, `kysely-migration-cli` attempts to register a transpiler using Node's hook api. It currently supports the following transpilers:\n\n- `esbuild-register`\n- `ts-node/register/transpile-only`\n- `@swc-node/register`\n\n\u003e Of course, they are not required for platforms which supports TypeScript natively, such as `Deno` and `Bun`.\n\nIf you require additional registration supports, please submit a pull request.\n\n# Difference from kysely-ctl\n\nKysely has now the official CLI called `kysely-ctl`. It's actively maintianed and covers broader features, while `kysely-migration-cli` has less dependencies.\n\nhttps://github.com/kysely-org/kysely-ctl\n\nFor more details, please take a look at: https://github.com/acro5piano/kysely-migration-cli/issues/28\n\n# License\n\nCopyright © 2022 [Kay Gosho](https://github.com/acro5piano) (@acro5piano).\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facro5piano%2Fkysely-migration-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Facro5piano%2Fkysely-migration-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facro5piano%2Fkysely-migration-cli/lists"}