Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

larvitdbmigration

Package Overview
Dependencies
Maintainers
1
Versions
177
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

larvitdbmigration

node.js database migration tool

  • 0.3.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
384
decreased by-38.16%
Maintainers
1
Weekly downloads
 
Created
Source

Database migration tool

This is used to keep track of the database structure, and update it when need be via deploys.

At the moment only MariaDB(/MySQL) is supported.

A table by default called db_version will be created, containing a single integer.

Scripts will be placed by default in /dbmigration/.js

Each migration script will be ran, and the db_version increased, until no more migration scripts exists.

Usage

Application startup script

In your application startup script, do something like this:

'use strict';

var dbMigration = require('larvitdbmigration');

dbMigration({
	'host': '127.0.0.1',
	'user': 'bar',
	'database': 'bar'
})(function(err) {
	if (err) {
		throw err;
	}

	// Now database is migrated and ready for use!
});

To use custom table name and/or script path, just change

dbMigration({
	'host': '127.0.0.1',
	'user': 'bar',
	'password': 'bar',
	'database': 'bar'
})(function(err) {

to

dbMigration({
	'host': '127.0.0.1',
	'user': 'bar',
	'password': 'bar',
	'database': 'bar',
	'tableName': 'some_table',
	'migrationScriptsPath': './scripts_yo'
})(function(err) {

Example migration scripts

Lets say the current database have a table like this:

CREATE TABLE bloj (nisse int(11));

And in the next deploy we'd like to change the column name "nisse" to "hasse". For this you can do one of two methods:

Javascript

Create the file //1.js with this content:

'use strict';

var db = require('db');

exports = module.exports = function(cb) {
	db.query('ALTER TABLE bloj CHANGE nisse hasse int(11);', cb);
}
SQL

IMPORTANT! SQL files will be ignored if a .js file exists.

ALSO IMPORTANT! SQL files require the mysql client to be installed on the host system.

Create the file //1.sql with this content:

ALTER TABLE bloj CHANGE nisse hasse int(11);
Summary

Tadaaa! Now this gets done once and the version will be bumped to 1. If you then create a script named "2.js" or "2.sql" you might guess what happends. :)

Keywords

FAQs

Package last updated on 27 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc