segunolalive/helloBooks

View on GitHub
server/migrations/20170821170952-create migration for book table.js

Summary

Maintainability
A
1 hr
Test Coverage
module.exports = {
  up(queryInterface, Sequelize) {
    return queryInterface.createTable('Books', {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER,
      },
      title: {
        allowNull: false,
        type: Sequelize.STRING,
        unique: true
      },
      authors: {
        allowNull: false,
        type: Sequelize.STRING,
      },
      description: {
        type: Sequelize.TEXT,
      },
      total: {
        type: Sequelize.INTEGER,
        defaultValue: 0,
      },
      cover: {
        type: Sequelize.STRING,
      },
      bookFile: {
        type: Sequelize.STRING,
      },
      categoryId: {
        type: Sequelize.INTEGER,
        defaultValue: 1,
        references: {
          model: 'BookCategories',
          key: 'id',
        },
      },
      createdAt: {
        allowNull: false,
        type: Sequelize.DATE,
      },
      updatedAt: {
        allowNull: false,
        type: Sequelize.DATE,
      }
    });
  },
  down(queryInterface /* , Sequelize */) {
    return queryInterface.dropTable('Books');
  }
};