Skip to content

cinnabar-forge/migratta

Repository files navigation

Migratta

By Cinnabar Forge

DISCLAIMER: This project is not production ready. All versions below 1.0.0 should be considered unstable

A lightweight TypeScript library for defining and running database migrations in code.

It offers a fully type-safe builder API and TypeScript type generation from your schema state.

It supports SQLite only for now.

Features

  • Fluent builder API – define tables and columns with clear, chainable commands
  • Zero ORM – pure SQL migrations, no runtime entities or models
  • Schema actions – create, drop, rename, and alter tables or columns programmatically
  • Migration steps – mix SQL, scripts, and async operations in one timeline
  • Type generation – export schema as TypeScript types

Installation

npm

npm install migratta

Usage

import { Migratta } from "migratta";

// initialize object
const migratta = new Migratta({
  dialect: "sqlite",
  dialectVersion: "3.50", // allows using new dialect features
});

Create a table

// every migration starts with .migrate()
// first migration: creating new table
migratta.migrate()
  .table("users")
  .create({
    id: { type: "ID", primaryKey: true, autoIncrement: true },
    name: { type: "TEXT", notNull: true },
    age: { type: "INTEGER" },
  });

Alter a table

// second migration: updating existing table
migratta.migrate()
  .table("users")
  .addColumn("email", { type: "TEXT", unique: true });

Run raw SQL

// third migration: run custom query
migratta.migrate()
  .sql("UPDATE users SET name = ? WHERE name = ?", ["Mary", "Msry"]);

Run async callback

// fourth migration: run any logic as a migration step
migratta.migrate()
  .asyncScript(async () => {
    const raw = await yourDbDriver.get(`SELECT * FROM users`);
    const changed = await somethingToChange(raw);
    for (const row of changed) {
      await yourDbDriver.run(...)
    }
  });

Contributing

Visit CONTRIBUTING.md.

Current maintainer - Timur Moziev (@TimurRin)

License

Visit LICENSE.

Anca

This repository is a part of Anca standardization project. Parts of the files and code are generated by Anca.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages