Thanks to visit codestin.com
Credit goes to github.com

Skip to content

rthoward/migreat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Migreat

Getting started

  1. Create a .migreat.js file that exports a database connection and migration file dir:
const dbConnection = require('./lib/db');
const path = require('path');

module.exports = {
  db,
  migrationDir: path.join(__dirname, './migrations')
};
  1. Create a migration:

$ migreat gen my_first_migration

  1. Edit it:

$ vim migrations/1513098322271__my_first_migration.js

module.exports = {
  up: (db) => {
    return db.query(`
      CREATE TABLE new_table (
        id SERIAL PRIMARY KEY,
        data TEXT,
      );
    `)},

    down: (db) => {
      return db.query(`
        DROP TABLE new_table;
      `);
    }
};
  1. Migrate:

$ migreat up

Details

Database connection

The database connection that you export in .migreat.js can be any object with the following property: query(string) -> Promise. Migreat will pass this connection into the up() and down() methods in your migration files.

Migreat relies on SQL transactions to make each migration atomic, so your database backend must support them.

About

A simple, low-assumption migration tool for node.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published