Skip to content

Commit

Permalink
feat(code): add code model
Browse files Browse the repository at this point in the history
  • Loading branch information
serge1peshcoff committed Apr 28, 2019
1 parent c830f75 commit a7dd4e2
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
34 changes: 34 additions & 0 deletions migrations/20190428134103-create-code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module.exports = {
up: (queryInterface, Sequelize) => queryInterface.createTable('codes', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
integration_id: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: 'integrations',
key: 'id'
}
},
value: {
allowNull: false,
type: Sequelize.STRING
},
claimed_by: {
type: Sequelize.INTEGER
},
created_at: {
allowNull: false,
type: Sequelize.DATE
},
updated_at: {
allowNull: false,
type: Sequelize.DATE
}
}),
down: queryInterface => queryInterface.dropTable('codes')
};
25 changes: 25 additions & 0 deletions models/Code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { Sequelize, sequelize } = require('../lib/sequelize');

const Code = sequelize.define('code', {
value: {
type:Sequelize.STRING,
allowNull: false,
defaultValue: '',
validate: {
notEmpty: { msg: 'Code should be set.' },
},
},
integration_id: {
type:Sequelize.INTEGER,
allowNull: false,
defaultValue: '',
validate: {
notEmpty: { msg: 'Integration ID should be set.' },
},
},
claimed_by: {
type: Sequelize.INTEGER
}
}, { underscored: true, tableName: 'codes' });

module.exports = Code;
7 changes: 6 additions & 1 deletion models/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
const Integration = require('./Integration');
const Code = require('./Code');

Integration.hasMany(Code);
Code.belongsTo(Integration);

module.exports = {
Integration
Integration,
Code
};

0 comments on commit a7dd4e2

Please sign in to comment.