Merged PetitTeton webapp with the inventory tracking app; Moved the database configuration out of git and added an example configuration; Added migrations to the mix so that we can easily update the production database and roll back changes to the database (from the command line install migrations [may not be necessary?]:

npm install -g sequelize-cli

To update the database after updating the app from git (on the command line in the webapp base directory):
sequelize db:migrate

To undo the last migrations:
sequelize db:migrate:undo
This commit is contained in:
Wynne Crisman
2016-06-13 11:54:12 -07:00
parent 6592feb97a
commit 0a7cff6672
29 changed files with 537 additions and 27 deletions

33
models/sale.js Normal file
View File

@@ -0,0 +1,33 @@
"use strict";
module.exports = function(sequelize, DataTypes) {
//The id field is auto added and made primary key.
var Sale = sequelize.define('Sale', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
allowNull: false,
autoIncrement: true
},
date: {
type: DataTypes.DATE,
allowNull: false
},
measure: {
type: DataTypes.JSONB,
allowNull: false
}
}, {
freezeTableName: true, // Model tableName will be the same as the model name
classMethods: {
associate: function(models) {
//Sale.hasOne(models.Category, {as: 'category'});
//Sale.hasOne(models.Subcategory, {as: 'subcategory'});
Sale.belongsTo(models.Item, {as: 'item', foreignKey: {name: 'itemId', field: 'itemId'}});
Sale.belongsTo(models.Venue, {as: 'venue', foreignKey: {name: 'venueId', field: 'venueId'}});
}
}
});
return Sale;
};