{"size": 1605, "ext": "js", "max_stars_repo_path": "backend/database/migrations/20210823015539-create-vote.js", "max_stars_repo_name": "akamuraasai/blog", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "backend/database/migrations/20210823015539-create-vote.js", "max_issues_repo_name": "akamuraasai/blog", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "backend/database/migrations/20210823015539-create-vote.js", "max_forks_repo_name": "akamuraasai/blog", "max_forks_repo_forks_event_min_datetime": "2021-08-23T08:01:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-23T22:52:16.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 2, "avg_line_length": 21.9863013699, "max_line_length": 49, "alphanum_fraction": 0.5283489097}
'use strict';
module.exports = {
  up: async (queryInterface, Sequelize) => {
    await queryInterface.createTable('Votes', {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER
      },
      type_id: {
        allowNull: false,
        type: Sequelize.INTEGER
      },
      user_id: {
        allowNull: false,
        type: Sequelize.INTEGER
      },
      post_id: {
        allowNull: false,
        type: Sequelize.INTEGER
      },
      createdAt: {
        allowNull: false,
        type: Sequelize.DATE
      },
      updatedAt: {
        allowNull: false,
        type: Sequelize.DATE
      }
    });

    await queryInterface.addConstraint('Votes', {
      fields: ['type_id'],
      type: 'foreign key',
      name: 'fk_votes_type',
      references: {
        table: 'VoteTypes',
        field: 'id'
      },
      onDelete: 'RESTRICT',
      onUpdate: 'RESTRICT'
    });

    await queryInterface.addConstraint('Votes', {
      fields: ['user_id'],
      type: 'foreign key',
      name: 'fk_votes_users',
      references: {
        table: 'Users',
        field: 'id'
      },
      onDelete: 'RESTRICT',
      onUpdate: 'RESTRICT'
    });

    await queryInterface.addConstraint('Votes', {
      fields: ['post_id'],
      type: 'foreign key',
      name: 'fk_votes_posts',
      references: {
        table: 'Posts',
        field: 'id'
      },
      onDelete: 'RESTRICT',
      onUpdate: 'RESTRICT'
    });
  },

  down: async (queryInterface, Sequelize) => {
    await queryInterface.dropTable('Votes');
  }
};