npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

migrateit

v0.1.8

Published

Automatic database migrations with LLM support

Downloads

19

Readme

Migrateit

A TypeScript library for automatically generating and executing database migrations. It uses LLMs (Large Language Models) to analyze your TypeScript classes and generate the appropriate migration scripts.

Features

  • Automatic migration generation from TypeScript classes
  • Support for PostgreSQL and SQLite databases
  • LLM-powered migration naming and generation
  • Migration management (up/down)
  • Support for decorators to define database schema
  • Schema tracking and validation

Installation

npm install migrateit

Usage

Initialize the Project

npx migrateit init

This will create 2 files:

  • migrateit.config.json in your project root directory:
{
    "dbType": "postgres",
    "modelsPath": ["./src/models/*.ts"],
    "migrationsPath": "./src/migrations/",
    "dbClientConfig": {
        "db": "postgres"
    },
    "llm": {
        "provider": "openai",
        "model": "gpt-4o",
        "apiKey": "optional-your-api-key",
        "baseURL": "optional-base-url"
    }
}
  • ./src/migrations/000-init.sql: This file is executed before the first migration to set up your database. You can use it for example to create initial DB schema, add extensions, etc. e.g:
CREATE SCHEMA IF NOT EXISTS app;

Define Your Models

Use decorators to define your database schema in TypeScript classes:

import { AutoIncrement, NotNull, PrimaryKey, Size, Table, Unique } from "migrateit";

@Table('app.users')
export class User {
    @PrimaryKey()
    @AutoIncrement()
    id: number;

    @Size(100)
    name: string;

    @Unique()
    @Size(300)
    email: string;

    password: string;

    @NotMapped()
    created_at: Date;
}

Available decorators:

  • @Table(name): Specify the table name. e.g., @Table('app.users'), @Table('users')
  • @Column(name): Specify column name
  • @PrimaryKey(): Mark as primary key
  • @AutoIncrement(): Enable auto-incrementing
  • @Unique(): Add unique constraint
  • @NotNull(): Make field non-nullable
  • @Size(size): Specify field size
  • @Default(value): Set default value
  • @UUID(): Use UUID type
  • @NotMapped(): Exclude field from database
  • @ForeignKey(column) or @ForeignKey(options): Define foreign key relationship
    • column: Referenced column name
    • on_delete: Action on delete (e.g., 'CASCADE', 'SET NULL')
    • name: Custom constraint name
    • Additional options can be specified in the options object
  • @Index(name) or @Index(options): Create an index
    • name: Name of the index
    • Additional options can be specified in the options object
  • @DataType(type): Specify custom column data type

Note that these decorators will not add any metadata to your classes. They are only used to help the LLM better understand your schema. Non-Nullable properties will get @NotNull() decorator automatically.

Managing Migrations

Create a New Migration

npx migrateit create [-n migration_name [-d]] [-e]

Options:

  • -n, --name: Specify migration name (optional, LLM will generate if omitted)
  • -d, --dry-run: Preview migration without creating files
  • -e, --empty: Create empty migration file

This will create 2 files in your migrations directory, one for up and one for down.

-- ./src/migrations/1739557922583-create-users-table.up.sql
create table app.users (
    id serial primary key,
    name varchar(100) not null,
    email varchar(300) not null unique,
    password varchar not null,
    created_at timestamp
);
-- ./src/migrations/1739557922583-create-users-table.down.sql
drop table app.users;

It'll also create ./src/migrations/000-schema.sql file. The schema file contains the full schema of your database. It is updated whenever a new migration is created and it is sent to the LLM to help identify the changes between the current schema and the new one.

NOTE: If you make any changes to your (up|down).sql files or remove them, do not forget to apply the same changes to your schema file.

Now if you update the User class and run npx migrateit create, it will generate a new migration based on the changes.

import { AutoIncrement, NotNull, PrimaryKey, Size, Table, Unique } from "migrateit";

@Table('app.users')
export class User {
    @PrimaryKey()
    @AutoIncrement()
    id: number;

    @Size(100)
    name: string;

    @Unique()
    @Size(300)
    email: string;

    @Default(0)
    age: number; // new field

    password: string;

    @NotMapped()
    created_at: Date;
}

Running npx migrateit create will generate the following migration:

-- ./src/migrations/1739557922584-add-age-column-to-users-table.up.sql
alter table app.users add column age integer default 0;
-- ./src/migrations/1739557922584-add-age-column-to-users-table.down.sql
alter table app.users drop column age;

List Migrations

npx migrateit list [-p]

Options:

  • -p, --pending: Show only pending migrations

Apply Migrations

npx migrateit up

Applies all pending migrations to the database.

Rollback Migration

npx migrateit down

Reverts the last applied migration.

Database Support

Currently supported databases:

  • PostgreSQL: Using pg libray
  • SQLite: Using Node's built-in SQLite support (Node v22+ required)

To add support for other databases or you want to use your own adapter for existing db types:

  • Create a class that inherits from DatabaseAdapter class.
  • Create a file migrateit.init.ts at the root of your project.
  • Register your adapter:
import { registerAdapter } from 'migrateit';
registerAdapter('adapter-name', new CustomDatabaseAdapter());
  • Update your migrateit.config.json file:
{
    "dbType": "dbType",
    "dbAdapter": "adapter-name"
}

Development

Running Tests

npm run test:dev

Building

npm run build

License

MIT