gratin
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

Gratin

Use Gratin. Start migratin'.


What

Gratin is a very simple database migration tool that will:

  • Read all the files from a given folder, assuming each of them is a valid script for your target database.
  • Connect to a given database
  • Apply each file in a transaction
  • Keep track of each applied migration in the database itself, creating the table gratin_changelog.

Installation

npm i --save gratin

Usage

Create a new file, like migrator.ts, which will be the entry point for the migrations tool:

import { join } from 'path';
 
import { Gratin, Postgres } from 'gratin';
 
const gratin = new Gratin({
    migrationsFolder: join(__dirname, 'migrations'),
    database: new Postgres({
        host: '127.0.0.1',
        port: 5432,
        database: 'postgres',
        username: 'postgres',
        password: '12345',
    }),
});
 
gratin.run();

This will find every file inside ./migrations folder (relative to the script itself) and apply each of them to the database in separate transactions, creating a changelog in the database to keep track of all the applied migrations.

And, because it's just code, you can do whatever you want to get the proper database credentials, do some tasks before or after migrating, etc.

Now all you have to do is run it with something like ts-node or compile it with Typescript tsc.

Database support

Currently, only PostgreSQL. But you could create a new implementation of IDatabase on your own and use it. The PostgreSQL implementation is included in the package as a commodity.

Credits

Readme

Keywords

none

Package Sidebar

Install

npm i gratin

Weekly Downloads

0

Version

0.1.2

License

GPL-3.0

Unpacked Size

48.8 kB

Total Files

13

Last publish

Collaborators

  • sirikon