20210609133935-user.js 1.69 KB
'use strict';
const bcrypt = require('bcrypt')
const path = require('path')
require('dotenv').config({path: path.join(__dirname, "../.env")})

module.exports = {
  up: async (queryInterface, Sequelize) => {
    return Promise.all([
      await queryInterface.createTable('Users', {
        id: {
          allowNull: false,
          autoIncrement: true,
          primaryKey: true,
          type: Sequelize.INTEGER
        },
        userId: {
          type: Sequelize.STRING(191),
          unique:true
        },
        password: {
          type: Sequelize.STRING(191)
        },
        name: {
          type: Sequelize.STRING(191)
        },
        phone: {
          type: Sequelize.STRING(31)
        },
        email: {
          type: Sequelize.STRING(191)
        },
        isAdmin: {
          type:Sequelize.BOOLEAN,
          defalutValue: false,
          allowNull: false
        },
        createdAt: {
          type: Sequelize.DATE,
          allowNull: false
        },
        updatedAt: {
          type: Sequelize.DATE,
          allowNull: false
        },
        deletedAt: {
          type: Sequelize.DATE
        }
      }, {
        charset: 'utf8mb4',
        collate: 'utf8mb4_unicode_ci'
      }),
      await queryInterface.bulkInsert('Users',
          [
            {
              id: 1,
              name: '관리자',
              userId: process.env.INITIAL_ADMIN_ID,
              password: await bcrypt.hash(process.env.INITIAL_ADMIN_PW, 10),
              isAdmin: true,
              createdAt: new Date(),
              updatedAt: new Date()
            }
          ])

    ])

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