Socket
Socket
Sign inDemoInstall

node-mini-migrations

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-mini-migrations - npm Package Compare versions

Comparing version 0.0.2 to 1.0.0

10

CHANGELOG.md

@@ -7,2 +7,12 @@ # Changelog

## [1.0.0] - 2019-03-09
### Fixed
- My inability to spell in the readme file
### Added
- Installation instructions
### Changed
- get, set, del now renamed to describe what it's used for
## [0.0.2] - 2019-03-07

@@ -9,0 +19,0 @@ ### Changed

12

example/driver.js

@@ -28,22 +28,22 @@ const fs = require('fs')

get: (key) => {
getMigrationState: (id) => {
const state = JSON.parse(
fs.readFileSync('test_state.json', 'utf8')
)
return state[key]
return state[id]
},
set: (key, value) => {
setMigrationUp: (id) => {
const state = JSON.parse(
fs.readFileSync('test_state.json', 'utf8')
)
state[key] = value
state[id] = true
fs.writeFileSync('test_state.json', JSON.stringify(state))
},
del: (key) => {
setMigrationDown: (id) => {
const state = JSON.parse(
fs.readFileSync('test_state.json', 'utf8')
)
delete state[key]
delete state[id]
fs.writeFileSync('test_state.json', JSON.stringify(state))

@@ -50,0 +50,0 @@ },

{
"name": "node-mini-migrations",
"version": "0.0.2",
"version": "1.0.0",
"description": "A very small, lightweight and flexible migrations library unconcerned with what database you use",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,3 +0,3 @@

# Mini Migrator
A really simple node migrations library that is completly independant of any database or file system
# Mini Migrations for NodeJS
A really simple node migrations library that is completely independant of any database or file system.

@@ -7,2 +7,7 @@ ## Example Usage

### Installation
```bash
npm install node-mini-migrations
```
### Setup

@@ -13,4 +18,4 @@ ```javascript

// db could be an instance of a database, like mysql, postgres, mongodb, or
// anything you want. It's just an object that gets passed to migrations.
// `db` could be an instance of a database, like mysql, postgres, mongodb,
// or anything you want. It's just an object that gets passed to migrations.
const db = {

@@ -41,22 +46,22 @@ tableCreate: (table) => {

get: (key) => {
getMigrationState: (id) => {
const state = JSON.parse(
fs.readFileSync('test_state.json', 'utf8')
)
return state[key]
return state[id]
},
set: (key, value) => {
setMigrationUp: (id) => {
const state = JSON.parse(
fs.readFileSync('test_state.json', 'utf8')
)
state[key] = value
state[id] = true
fs.writeFileSync('test_state.json', JSON.stringify(state))
},
del: (key) => {
setMigrationDown: (id) => {
const state = JSON.parse(
fs.readFileSync('test_state.json', 'utf8')
)
delete state[key]
delete state[id]
fs.writeFileSync('test_state.json', JSON.stringify(state))

@@ -63,0 +68,0 @@ },

module.exports = async ({driver, migrations}) => {
if (driver.init) {
driver.init('down')
await driver.init('down')
}
for (let migration of migrations) {
const active = driver.get(migration.id)
const active = await driver.getMigrationState(migration.id)
if (active) {

@@ -12,5 +12,5 @@ console.log(`Tearing down ${migration.id}`)

await migration.down(driver.db)
driver.del(migration.id)
await driver.setMigrationDown(migration.id)
} catch (err) {
console.log(`Error bringing up ${migration.id}`)
console.log(`Error tearing down ${migration.id}`, err)
}

@@ -23,4 +23,4 @@ } else {

if (driver.finish) {
driver.finish('down')
await driver.finish('down')
}
}
module.exports = async ({driver, migrations}) => {
if (driver.init) {
driver.init('up')
await driver.init('up')
}
for (let migration of migrations) {
const active = driver.get(migration.id)
const active = await driver.getMigrationState(migration.id)
if (active) {

@@ -14,5 +14,5 @@ console.log(`Migration ${migration.id} already active`)

await migration.up(driver.db)
driver.set(migration.id, true)
await driver.setMigrationUp(migration.id)
} catch (err) {
console.log(`Error bringing up ${migration.id}`)
console.log(`Error bringing up ${migration.id}`, err)
}

@@ -23,4 +23,4 @@ }

if (driver.finish) {
driver.finish('up')
await driver.finish('up')
}
}
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