@itleanchatbot/shared-models-js-postgres 2.1.3 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/migrations/20211006150930-create-index.js +62 -0
- package/src/migrations/20211022105430-alter-attendance-scale-off.js +27 -0
- package/src/migrations/20211029134230-remove-constraints.js +187 -0
- package/src/seeders/20210914165047-update-channel-types.js +15 -0
- package/src/models/index.js +0 -45
package/package.json
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
up: async (queryInterface, Sequelize) => {
|
|
5
|
+
await queryInterface.addIndex('Intentions', {
|
|
6
|
+
fields: ['SkillId', 'name'],
|
|
7
|
+
name: 'leanbot_Intentions_01',
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
await queryInterface.addIndex('IntentionValues', {
|
|
11
|
+
fields: ['name'],
|
|
12
|
+
name: 'leanbot_IntentionValues_01',
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
await queryInterface.addIndex('IntentionValues', {
|
|
16
|
+
fields: ['IntentionId'],
|
|
17
|
+
name: 'leanbot_IntentionValues_02',
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
await queryInterface.addIndex('EntityValues', {
|
|
21
|
+
fields: ['EntityId'],
|
|
22
|
+
name: 'leanbot_EntityValues_01',
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
await queryInterface.addIndex('EntityValues', {
|
|
26
|
+
fields: ['synonyms'],
|
|
27
|
+
name: 'leanbot_EntityValues_02',
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
await queryInterface.addIndex('Entities', {
|
|
31
|
+
fields: ['SkillId', 'name'],
|
|
32
|
+
name: 'leanbot_Entities_01',
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
await queryInterface.addIndex('ChannelTypes', {
|
|
36
|
+
fields: ['channelName'],
|
|
37
|
+
name: 'leanbot_ChannelTypes_01',
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
await queryInterface.addIndex('Synonyms', {
|
|
41
|
+
fields: ['type'],
|
|
42
|
+
name: 'leanbot_Synonyms_01',
|
|
43
|
+
})
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
down: async (queryInterface, Sequelize) => {
|
|
47
|
+
await queryInterface.removeIndex('Intentions', 'leanbot_Intentions_01')
|
|
48
|
+
await queryInterface.removeIndex(
|
|
49
|
+
'IntentionValues',
|
|
50
|
+
'leanbot_IntentionValues_01'
|
|
51
|
+
)
|
|
52
|
+
await queryInterface.removeIndex(
|
|
53
|
+
'IntentionValues',
|
|
54
|
+
'leanbot_IntentionValues_02'
|
|
55
|
+
)
|
|
56
|
+
await queryInterface.removeIndex('EntityValues', 'leanbot_EntityValues_01')
|
|
57
|
+
await queryInterface.removeIndex('EntityValues', 'leanbot_EntityValues_02')
|
|
58
|
+
await queryInterface.removeIndex('Entities', 'leanbot_Entities_01')
|
|
59
|
+
await queryInterface.removeIndex('ChannelTypes', 'leanbot_ChannelTypes_01')
|
|
60
|
+
await queryInterface.removeIndex('Synonyms', 'leanbot_Synonyms_01')
|
|
61
|
+
},
|
|
62
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
up: async (queryInterface, Sequelize) => {
|
|
5
|
+
await queryInterface.changeColumn('AttendanceScaleOffs', 'hourInit', {
|
|
6
|
+
allowNull: true,
|
|
7
|
+
type: Sequelize.TIME,
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
await queryInterface.changeColumn('AttendanceScaleOffs', 'hourFinish', {
|
|
11
|
+
allowNull: true,
|
|
12
|
+
type: Sequelize.TIME,
|
|
13
|
+
})
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
down: async (queryInterface, Sequelize) => {
|
|
17
|
+
await queryInterface.changeColumn('AttendanceScaleOffs', 'hourInit', {
|
|
18
|
+
allowNull: false,
|
|
19
|
+
type: Sequelize.TIME,
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
await queryInterface.changeColumn('AttendanceScaleOffs', 'hourFinish', {
|
|
23
|
+
allowNull: false,
|
|
24
|
+
type: Sequelize.TIME,
|
|
25
|
+
})
|
|
26
|
+
},
|
|
27
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
const remove = async (queryInterface, tableName, constraintName) => {
|
|
3
|
+
try {
|
|
4
|
+
const result = await queryInterface.removeConstraint(
|
|
5
|
+
tableName,
|
|
6
|
+
constraintName
|
|
7
|
+
)
|
|
8
|
+
return result
|
|
9
|
+
} catch (error) {
|
|
10
|
+
console.error(error)
|
|
11
|
+
return null
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const add = async (
|
|
15
|
+
queryInterface,
|
|
16
|
+
tableName,
|
|
17
|
+
field,
|
|
18
|
+
onDelete,
|
|
19
|
+
onUpdate,
|
|
20
|
+
constraintName
|
|
21
|
+
) => {
|
|
22
|
+
try {
|
|
23
|
+
const result = await queryInterface.addConstraint(tableName, {
|
|
24
|
+
name: constraintName,
|
|
25
|
+
type: 'FOREIGN KEY',
|
|
26
|
+
fields: [field],
|
|
27
|
+
references: {
|
|
28
|
+
table: 'DialogNodes',
|
|
29
|
+
field: 'id',
|
|
30
|
+
},
|
|
31
|
+
onDelete,
|
|
32
|
+
onUpdate,
|
|
33
|
+
})
|
|
34
|
+
return result
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error(error)
|
|
37
|
+
return null
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const setNull = async (queryInterface) => {
|
|
41
|
+
try {
|
|
42
|
+
const result = await queryInterface.sequelize.query(
|
|
43
|
+
`
|
|
44
|
+
update "BotIterables" set "DialogNodeId" = null where "id" in (
|
|
45
|
+
select distinct "b"."id"
|
|
46
|
+
from "BotIterables" as "b"
|
|
47
|
+
left join "DialogNodes" as "d"
|
|
48
|
+
on "b"."DialogNodeId" = "d"."id"
|
|
49
|
+
where "d"."id" is null
|
|
50
|
+
and "b"."DialogNodeId" is not null
|
|
51
|
+
)
|
|
52
|
+
`
|
|
53
|
+
)
|
|
54
|
+
return result
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.error(error)
|
|
57
|
+
return null
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
module.exports = {
|
|
61
|
+
up: async (queryInterface, Sequelize) => {
|
|
62
|
+
// BotIterables
|
|
63
|
+
await remove(
|
|
64
|
+
queryInterface,
|
|
65
|
+
'BotIterables',
|
|
66
|
+
'BotIterables_DialogNodeId_fkey'
|
|
67
|
+
)
|
|
68
|
+
await remove(
|
|
69
|
+
queryInterface,
|
|
70
|
+
'BotIterables',
|
|
71
|
+
'BotIterables_DialogNodeId_fkey1'
|
|
72
|
+
)
|
|
73
|
+
// DialogNodes_ApiResources
|
|
74
|
+
await remove(
|
|
75
|
+
queryInterface,
|
|
76
|
+
'DialogNodes_ApiResources',
|
|
77
|
+
'DialogNodes_ApiResources_DialogNodeId_fkey'
|
|
78
|
+
)
|
|
79
|
+
// DialogNodes_MultipleResponses
|
|
80
|
+
await remove(
|
|
81
|
+
queryInterface,
|
|
82
|
+
'DialogNodes_MultipleResponses',
|
|
83
|
+
'DialogNodes_MultipleResponses_DialogNodeId_fkey'
|
|
84
|
+
)
|
|
85
|
+
//DialogNodes
|
|
86
|
+
await remove(
|
|
87
|
+
queryInterface,
|
|
88
|
+
'DialogNodes',
|
|
89
|
+
'DialogNodes_DialogNodeFolderId_fkey'
|
|
90
|
+
)
|
|
91
|
+
// EndSessionTriggers
|
|
92
|
+
await remove(
|
|
93
|
+
queryInterface,
|
|
94
|
+
'EndSessionTriggers',
|
|
95
|
+
'EndSessionTriggers_DialogNodeId_fkey'
|
|
96
|
+
)
|
|
97
|
+
//FaqTriggers_DialogNodeId_fkey
|
|
98
|
+
await remove(queryInterface, 'FaqTriggers', 'FaqTriggers_DialogNodeId_fkey')
|
|
99
|
+
// Response_DialogNodes
|
|
100
|
+
await remove(
|
|
101
|
+
queryInterface,
|
|
102
|
+
'Response_DialogNodes',
|
|
103
|
+
'Response_DialogNodes_DialogNodeId_fkey'
|
|
104
|
+
)
|
|
105
|
+
// TranshipTriggers
|
|
106
|
+
await remove(
|
|
107
|
+
queryInterface,
|
|
108
|
+
'TranshipTriggers',
|
|
109
|
+
'TranshipTriggers_DialogNodeId_fkey'
|
|
110
|
+
)
|
|
111
|
+
},
|
|
112
|
+
down: async (queryInterface, Sequelize) => {
|
|
113
|
+
await setNull(queryInterface)
|
|
114
|
+
await add(
|
|
115
|
+
queryInterface,
|
|
116
|
+
'BotIterables',
|
|
117
|
+
'DialogNodeId',
|
|
118
|
+
'RESTRICT',
|
|
119
|
+
'CASCADE',
|
|
120
|
+
'BotIterables_DialogNodeId_fkey'
|
|
121
|
+
)
|
|
122
|
+
await add(
|
|
123
|
+
queryInterface,
|
|
124
|
+
'BotIterables',
|
|
125
|
+
'DialogNodeId',
|
|
126
|
+
'SET NULL',
|
|
127
|
+
'CASCADE',
|
|
128
|
+
'BotIterables_DialogNodeId_fkey1'
|
|
129
|
+
)
|
|
130
|
+
await add(
|
|
131
|
+
queryInterface,
|
|
132
|
+
'DialogNodes_ApiResources',
|
|
133
|
+
'DialogNodeId',
|
|
134
|
+
'RESTRICT',
|
|
135
|
+
'CASCADE',
|
|
136
|
+
'DialogNodes_ApiResources_DialogNodeId_fkey'
|
|
137
|
+
)
|
|
138
|
+
await add(
|
|
139
|
+
queryInterface,
|
|
140
|
+
'DialogNodes_MultipleResponses',
|
|
141
|
+
'DialogNodeId',
|
|
142
|
+
'RESTRICT',
|
|
143
|
+
'CASCADE',
|
|
144
|
+
'DialogNodes_MultipleResponses_DialogNodeId_fkey'
|
|
145
|
+
)
|
|
146
|
+
await add(
|
|
147
|
+
queryInterface,
|
|
148
|
+
'DialogNodes',
|
|
149
|
+
'DialogNodeFolderId',
|
|
150
|
+
'RESTRICT',
|
|
151
|
+
'CASCADE',
|
|
152
|
+
'DialogNodes_DialogNodeFolderId_fkey'
|
|
153
|
+
)
|
|
154
|
+
await add(
|
|
155
|
+
queryInterface,
|
|
156
|
+
'EndSessionTriggers',
|
|
157
|
+
'DialogNodeId',
|
|
158
|
+
'RESTRICT',
|
|
159
|
+
'CASCADE',
|
|
160
|
+
'EndSessionTriggers_DialogNodeId_fkey'
|
|
161
|
+
)
|
|
162
|
+
await add(
|
|
163
|
+
queryInterface,
|
|
164
|
+
'FaqTriggers',
|
|
165
|
+
'DialogNodeId',
|
|
166
|
+
'RESTRICT',
|
|
167
|
+
'CASCADE',
|
|
168
|
+
'FaqTriggers_DialogNodeId_fkey'
|
|
169
|
+
)
|
|
170
|
+
await add(
|
|
171
|
+
queryInterface,
|
|
172
|
+
'Response_DialogNodes',
|
|
173
|
+
'DialogNodeId',
|
|
174
|
+
'RESTRICT',
|
|
175
|
+
'CASCADE',
|
|
176
|
+
'Response_DialogNodes_DialogNodeId_fkey'
|
|
177
|
+
)
|
|
178
|
+
await add(
|
|
179
|
+
queryInterface,
|
|
180
|
+
'TranshipTriggers',
|
|
181
|
+
'DialogNodeId',
|
|
182
|
+
'RESTRICT',
|
|
183
|
+
'CASCADE',
|
|
184
|
+
'TranshipTriggers_DialogNodeId_fkey'
|
|
185
|
+
)
|
|
186
|
+
},
|
|
187
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
up: async (queryInterface, Sequelize) => {
|
|
5
|
+
return queryInterface.sequelize.query(
|
|
6
|
+
`update "ChannelTypes" as ct
|
|
7
|
+
set "responsesTypes" = '[{"action":"text","display":"Texto"},{"action":"image","display":"Imagem"},{"action":"pdf","display":"PDF"},{"action":"video","display":"Vídeo"},{"action":"file","display":"Arquivo"},{"action":"simple_button","display":"Botão simples"}]'
|
|
8
|
+
where ct."channelName" = 'webchat'`
|
|
9
|
+
)
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
down: async (queryInterface, Sequelize) => {
|
|
13
|
+
return queryInterface.bulkDelete('ChannelTypes', null, {})
|
|
14
|
+
},
|
|
15
|
+
}
|
package/src/models/index.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
const fs = require('fs')
|
|
2
|
-
const path = require('path')
|
|
3
|
-
const Sequelize = require('sequelize')
|
|
4
|
-
const basename = path.basename(__filename)
|
|
5
|
-
|
|
6
|
-
module.exports = (config) => {
|
|
7
|
-
const db = {}
|
|
8
|
-
let sequelize
|
|
9
|
-
|
|
10
|
-
if (config.use_env_variable) {
|
|
11
|
-
sequelize = new Sequelize(process.env[config.use_env_variable], config)
|
|
12
|
-
} else {
|
|
13
|
-
sequelize = new Sequelize(
|
|
14
|
-
config.database,
|
|
15
|
-
config.username,
|
|
16
|
-
config.password,
|
|
17
|
-
config
|
|
18
|
-
)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
fs.readdirSync(__dirname)
|
|
22
|
-
.filter((file) => {
|
|
23
|
-
return (
|
|
24
|
-
file.indexOf('.') !== 0 && file !== basename && file.slice(-3) === '.js'
|
|
25
|
-
)
|
|
26
|
-
})
|
|
27
|
-
.forEach((file) => {
|
|
28
|
-
const model = require(path.join(__dirname, file)).model(
|
|
29
|
-
sequelize,
|
|
30
|
-
Sequelize.DataTypes
|
|
31
|
-
)
|
|
32
|
-
db[model.name] = model
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
Object.keys(db).forEach((modelName) => {
|
|
36
|
-
if (db[modelName].associate) {
|
|
37
|
-
db[modelName].associate(db)
|
|
38
|
-
}
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
db.sequelize = sequelize
|
|
42
|
-
db.Sequelize = Sequelize
|
|
43
|
-
|
|
44
|
-
return db
|
|
45
|
-
}
|