Created
June 3, 2017 17:16
-
-
Save carldanley/29bbe9987fb35df6f428431d4fa82d77 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// external dependencies | |
const bPromise = require('bluebird'); | |
// logic | |
exports.up = function(db, types) { | |
return db.sequelize.transaction(bPromise.coroutine(function* (t) { | |
yield db.createTable('listings', { | |
id: { | |
type: types.INTEGER, | |
allowNull: false, | |
autoIncrement: true | |
} | |
}, {transaction: t}); | |
yield db.createTable('shipments', { | |
id: { | |
type: types.INTEGER, | |
allowNull: false, | |
autoIncrement: true | |
} | |
}, {transaction: t}); | |
})); | |
}; | |
exports.down = function(db, types) { | |
return db.sequelize.transaction(bPromise.coroutine(function* (t) { | |
yield db.dropTable('listings', {transaction: t}); | |
yield db.dropTable('shipments', {transaction: t}); | |
})); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// exports | |
module.exports = function(db, types) { | |
const properties = { | |
id: { | |
type: types.INTEGER, | |
allowNull: false, | |
autoIncrement: true | |
}, | |
title: types.STRING, | |
description: types.TEXT, | |
namedPriceAmount: types.FLOAT, | |
namedPriceCurrency: types.STRING, | |
createdAt: types.DATE, | |
createdBy: types.INTEGER.UNSIGNED, | |
public: types.BOOLEAN, | |
expirationDate: types.DATE, | |
active: types.BOOLEAN, | |
brokered: types.BOOLEAN, | |
code: types.INTEGER.UNSIGNED, | |
referenceId: types.STRING, | |
meta: types.JSONB | |
}; | |
const methods = { | |
associate: function(models) { | |
models.Listing.hasMany(models.Shipment, { | |
as: 'shipments', | |
foreignKey: 'parentId' | |
}); | |
} | |
}; | |
return db.define('listings', properties, methods); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment