All files MigrationSet.js

9.52% Statements 2/21
0% Branches 0/4
0% Functions 0/3
9.52% Lines 2/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50            1x                                                                                   1x  
/**
 * @author David Menger
 */
'use strict';
 
 
const migrate = require('migrate');
 
function Migration (title, up, down, description, query) {
    this.title = title;
    this.up = up;
    this.down = down;
    this.description = description;
    this.query = query;
    this.timestamp = null;
}
 
class MigrationSet extends migrate.MigrationSet {
 
    constructor (store, query) {
        super(store);
 
        this.query = query;
    }
 
    addMigration (title, up, down) {
        let migration;
        if (typeof title === 'object') {
            migration = title;
            migration.query = this.query;
        } else {
            migration = new Migration(title, up, down, null, this.query);
        }
 
        // Only add the migration once, but update
        if (this.map[migration.title]) {
            this.map[migration.title].up = migration.up;
            this.map[migration.title].down = migration.down;
            this.map[migration.title].description = migration.description;
            return;
        }
 
        this.migrations.push(migration);
        this.map[migration.title] = migration;
    }
 
}
 
module.exports = MigrationSet;