{"id":13675760,"url":"https://github.com/awkweb/kysely-migrate","last_synced_at":"2025-05-12T22:17:06.248Z","repository":{"id":204784876,"uuid":"709439491","full_name":"awkweb/kysely-migrate","owner":"awkweb","description":"Kysely migrations and codegen CLI","archived":false,"fork":false,"pushed_at":"2024-03-03T15:53:16.000Z","size":193,"stargazers_count":18,"open_issues_count":4,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-30T02:02:17.953Z","etag":null,"topics":["cli","codegen","kysely","migrations"],"latest_commit_sha":null,"homepage":"","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/awkweb.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["tmm"]}},"created_at":"2023-10-24T18:11:37.000Z","updated_at":"2025-03-22T15:52:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"d16e370a-4eb1-42a0-99b7-ed671b5713b9","html_url":"https://github.com/awkweb/kysely-migrate","commit_stats":null,"previous_names":["tmm/kysely-migrate"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awkweb%2Fkysely-migrate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awkweb%2Fkysely-migrate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awkweb%2Fkysely-migrate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awkweb%2Fkysely-migrate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/awkweb","download_url":"https://codeload.github.com/awkweb/kysely-migrate/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253814969,"owners_count":21968560,"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":["cli","codegen","kysely","migrations"],"created_at":"2024-08-02T12:01:01.213Z","updated_at":"2025-05-12T22:17:06.225Z","avatar_url":"https://github.com/awkweb.png","language":"TypeScript","readme":"# kysely-migrate\n\n[Kysely](https://github.com/kysely-org/kysely) migrations and codegen CLI\n\n## Installation\n\n```fish\nbun add -D kysely-migrate\n```\n\n## Usage\n\nCreate a `kysely-migrate.config.ts` file and fill it out.\n\n```ts\nimport { Kysely, MysqlDialect } from 'kysely'\nimport { defineConfig } from 'kysely-migrate'\nimport { createPool } from 'mysql2'\n\nexport default defineConfig({\n  db: new Kysely({\n    dialect: new MysqlDialect({ pool: createPool('mysql://') }),\n  }),\n  migrationFolder: 'src/db/migrations',\n  codegen: { dialect: 'mysql', out: 'src/db/types.ts' },\n})\n```\n\nAdd a `\"migrate\"` script to your `package.json` file.\n\n```json\n{\n  \"scripts\": {\n    \"migrate\": \"bun -b kysely-migrate\"\n  }\n}\n```\n\nRun [commands](#commands) to manage migrations and generate types.\n\n```fish\nbun migrate \u003ccommand\u003e [options]\n```\n\n## Commands\n\nRun `kysely-migrate --help` or `kysely-migrate \u003ccommand\u003e --help` to see the list of available commands, options, and examples.\n\n```\ncodegen  generate types from database metadata\ncreate   create new migration\ndown     migrate one step down\ninit     create configuration file\nlist     list migrations\nto       migrate to selected migration\nup       migrate one step up\n```\n\n## API\n\n### defineConfig\n\nCreates [`Config`](#config) object.\n\n```ts\nimport { defineConfig } from 'kysely-migrate'\n```\n\n| Name    | Type                                       | Description                                                           |\n| ------- | ------------------------------------------ | --------------------------------------------------------------------- |\n| `config` | `Config \\| (() =\u003e Config \\| Promise\u003cConfig\u003e)` | Configuration object or a function that returns a configuration object. |\n| returns | [`Config`](#config)                          | Configuration object.                                                  |\n\n### loadEnv\n\nLoads environment variables from `.env` or `.env.*` files.\n\n```ts\nimport { loadEnv } from 'kysely-migrate'\n```\n\n| Name           | Type                      | Description                                 |\n| -------------- | ------------------------- | ------------------------------------------- |\n| `config.mode`   | `string \\| undefined`      | `.env` file type (e.g. `` `.env.${mode}` ``) |\n| `config.envDir` | `string \\| undefined`      | Directory to load `.env` file from           |\n| returns        | `Record\u003cstring, string\u003e`  | Parsed environment variables.               |\n\n### Config\n\n`Config` object.\n\n```ts\nimport { type Config } from 'kysely-migrate'\n```\n\n```ts\n{\n  /** Kysely instance used to manipulate migrations and introspect database */\n  db: Kysely\u003cany\u003e\n  /** Path to migrations directory */\n  migrationFolder: string\n\n  /** `kysely-migrate codegen` options */\n  codegen?:\n    | {\n        /** Custom definition mappings for database types to TypeScript types */\n        definitions?: Definitions | undefined\n        /** Dialect definitions to inherit */\n        dialect?: 'mysql' | 'postgres' | 'sqlite' | undefined\n        /** Output file path */\n        out: string\n      }\n    | undefined\n  \n  /** Used for internal `FileMigrationProvider` instance. Defaults to `node:fs/promises`. */\n  fs?: FileMigrationProviderFS | undefined\n  /** Used for internal `FileMigrationProvider` instance. Defaults to `node:path`. */\n  path?: FileMigrationProviderPath | undefined\n  /** Defaults to internal `migrator` created with `db` and `migrationFolder`. */\n  migrator?: Migrator | undefined\n}\n```\n\n### Dialect Definitions\n\nDialect definition files map database types to TypeScript types. They are used by the codegen command to generate types from database metadata. The following dialect definitions are available:\n\n```ts\nimport {\n  mysqlDefinitions,\n  postgresDefinitions,\n  sqliteDefinitions,\n} from 'kysely-migrate'\n```\n\n## Frequently Asked Questions\n\n### Unknown file extension \".ts\"\n\nIf you aren't using Bun, you either need to use the `.js` extension for your migration files or process the TypeScript files yourself. For example, you can use [`tsx`](https://github.com/esbuild-kit/tsx).\n\n```json\n{\n  \"scripts\": {\n    \"migrate\": \"tsx node_modules/kysely-migrate/dist/esm/cli.js\"\n  }\n}\n```\n\n## Contributing\n\nContributions to kysely-migrate are greatly appreciated! If you're interested in contributing, please create a [new GitHub Discussion](https://github.com/tmm/kysely-migrate/discussions/new?category=ideas) with some info on what you would like to work on **before submitting a pull request**.\n","funding_links":["https://github.com/sponsors/tmm"],"categories":["CLIs"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawkweb%2Fkysely-migrate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fawkweb%2Fkysely-migrate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawkweb%2Fkysely-migrate/lists"}