0.1.2 • Published 4 years ago

gratin v0.1.2

Weekly downloads
4
License
GPL-3.0
Repository
github
Last release
4 years ago

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

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.0-alpha1

4 years ago