kysely-migrator-cli

1.8.0 • Public • Published

kysely-migrator-cli

A light weight hassle free migration cli for Kysely

Table of Contents

Installation

# Install Kysely-migrator globally:
npm install -g kysely-migrator

or 

yarn add global kysely-migrator

Usage

kysely-migrator-cli is a library designed to assist you in creating your own migration script. It does provides executables command.

To use create a json file call migrator.json

{
    "databaseUrl": "${DATABASE_URL}", // leave has is, there should be an env variable with the same name(your database connection)
    "migrationFolder": "src/database/migrations" // path to your migrations folder
}

And it's that simple go straight ahead and create your migrations

migrator migrate:create test

Output:

//file name timestamp-test.ts
// Example: creating a table
import { Kysely } from 'kysely';

export async function up(database: Kysely<unknown>): Promise<void> {
  await database.schema
    .createTable('your_table_name')
    .addColumn('id', 'serial', (column) => column.primaryKey())
    .addColumn('name', 'text', (column) => column.notNull())
    // add more column has needed
    .execute();
}

export async function down(database: Kysely<unknown>): Promise<void> {
  await database.schema.dropTable('your_table_name');
}

Help:

## Options

- `-V, --version`   Output the version number.
- `-h, --help`      Display help for the command.

## Commands

- `migrate:create`  Generate a migration file.
- `migrate`         Migrate to the latest version.
- `migrate:down`    Roll back the last migration.
- `migrate:latest`  Runs all migrations that have not yet been run.
- `help [command]`  Display help for a specific command.

NPM Package

migrator

Package Sidebar

Install

npm i kysely-migrator-cli

Weekly Downloads

11

Version

1.8.0

License

MIT

Unpacked Size

266 kB

Total Files

24

Last publish

Collaborators

  • extodan