Skip to content

Commit

Permalink
Expense table creation
Browse files Browse the repository at this point in the history
  • Loading branch information
sedubois committed Jun 8, 2016
1 parent 795e8bf commit cca565a
Showing 1 changed file with 120 additions and 0 deletions.
120 changes: 120 additions & 0 deletions migrations/20160608001600-add-expenses-table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
'use strict';

const status = require('../server/constants/expense_status');

module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.createTable(
'Expenses', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},

UserId: {
type: Sequelize.INTEGER,
references: {
model: 'Users',
key: 'id'
},
onDelete: 'SET NULL',
onUpdate: 'CASCADE',
allowNull: false
},

GroupId: {
type: Sequelize.INTEGER,
references: {
model: 'Groups',
key: 'id'
},
onDelete: 'SET NULL',
onUpdate: 'CASCADE',
allowNull: false
},

currency: {
type: Sequelize.STRING,
allowNull: false
},

amount: {
type: Sequelize.INTEGER,
validate: { min: 0 },
allowNull: false
},

title: {
type: Sequelize.STRING,
allowNull: false
},
notes: Sequelize.TEXT,
attachment: Sequelize.STRING,
category: Sequelize.STRING,
vat: Sequelize.INTEGER,

lastEditedById: {
type: Sequelize.INTEGER,
references: {
model: 'Users',
key: 'id'
},
onDelete: 'SET NULL',
onUpdate: 'CASCADE'
},

status: {
type: Sequelize.STRING,
defaultValue: status.PENDING,
allowNull: false,
validate: {
isIn: {
args: [[status.PENDING, status.APPROVED, status.REJECTED, status.PAID]],
msg: 'Must be PENDING, APPROVED, REJECTED or PAID'
}
}
},

incurredAt: {
type: Sequelize.DATE,
allowNull: false
},

createdAt: {
type: Sequelize.DATE,
defaultValue: Sequelize.NOW,
allowNull: false
},

updatedAt: {
type: Sequelize.DATE,
defaultValue: Sequelize.NOW,
allowNull: false
},

deletedAt: {
type: Sequelize.DATE
}
}, {
paranoid: true
})
.tap(() => queryInterface.addColumn(
'Transactions',
'ExpenseId',
{
type: Sequelize.INTEGER,
references: {
model: 'Expenses',
key: 'id'
},
onDelete: 'SET NULL',
onUpdate: 'CASCADE'
}));
},

down: function (queryInterface) {
return queryInterface.removeColumn('Transactions', 'ExpenseId')
.then(() => queryInterface.dropTable('Expenses'));
}
};

0 comments on commit cca565a

Please sign in to comment.