20210609133935-user.js
1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'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');
}
};