agrs-sequelize-sdk 1.2.99 → 1.3.1

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.
Files changed (47) hide show
  1. package/migrations/add-requested-from-dashboard-to-articles.js +17 -17
  2. package/models/AdAccountValues.js +25 -25
  3. package/models/AdHistory.js +30 -30
  4. package/models/AdPerformance.js +94 -94
  5. package/models/AdSet.js +289 -289
  6. package/models/AdSetHistory.js +30 -30
  7. package/models/AdsetPerformance.js +126 -126
  8. package/models/Article.js +190 -190
  9. package/models/AutomationRule.js +161 -127
  10. package/models/Buyers.js +25 -25
  11. package/models/Campaign.js +157 -157
  12. package/models/CampaignActionHistory.js +86 -86
  13. package/models/CampaignCreationLog.js +309 -309
  14. package/models/CampaignHistory.js +33 -33
  15. package/models/Channel.js +55 -55
  16. package/models/Domain.js +25 -25
  17. package/models/DynamicFeed.js +212 -212
  18. package/models/ExplorAdsChannel.js +61 -61
  19. package/models/Feed.js +33 -33
  20. package/models/FrontStoryChannel.js +59 -59
  21. package/models/MineChannel.js +42 -42
  22. package/models/Pages.js +81 -81
  23. package/models/PipelineExecution.js +59 -59
  24. package/models/Presets.js +34 -34
  25. package/models/RSOCFeedCampaign.js +357 -357
  26. package/models/RsocKeywordPerformance.js +110 -110
  27. package/models/RuleAction.js +90 -90
  28. package/models/RuleCondition.js +98 -98
  29. package/models/RuleExecution.js +107 -107
  30. package/models/RulesValues.js +56 -56
  31. package/models/SupportedLocale.js +23 -23
  32. package/models/SyncHistory.js +249 -249
  33. package/models/Tier2_AdAccounts.js +110 -110
  34. package/models/Tier2_Assets.js +70 -70
  35. package/models/Tier2_BusinessManagers.js +105 -105
  36. package/models/Tier2_CreditLines.js +99 -99
  37. package/models/Tier2_Pages.js +91 -91
  38. package/models/Tier2_Pixels.js +82 -82
  39. package/models/Tier2_Tokens.js +64 -64
  40. package/models/Tier2_UserAdAccounts.js +83 -83
  41. package/models/TokenRotationState.js +121 -121
  42. package/models/TonicRSOCKeywordPerformance.js +122 -122
  43. package/models/Vertical.js +25 -25
  44. package/models/newFiles.js +110 -110
  45. package/package.json +19 -21
  46. package/run.sh +214 -214
  47. package/services/sequelizeService.js +63 -63
@@ -1,250 +1,250 @@
1
- // models/SyncHistory.js
2
- module.exports = (sequelize, DataTypes) => {
3
- const SyncHistory = sequelize.define(
4
- "SyncHistory",
5
- {
6
- id: {
7
- type: DataTypes.INTEGER,
8
- primaryKey: true,
9
- autoIncrement: true,
10
- },
11
- syncId: {
12
- type: DataTypes.STRING,
13
- allowNull: false,
14
- unique: true,
15
- comment: "Unique identifier for the sync operation"
16
- },
17
- syncType: {
18
- type: DataTypes.ENUM('manual', 'quick_sync', 'group_sync', 'preset_sync', 'scheduled'),
19
- allowNull: false,
20
- defaultValue: 'manual',
21
- comment: "Type of sync operation performed"
22
- },
23
- initiatedBy: {
24
- type: DataTypes.STRING,
25
- allowNull: true,
26
- comment: "User who initiated the sync (username or user ID)"
27
- },
28
- startTime: {
29
- type: DataTypes.DATE,
30
- allowNull: false,
31
- comment: "When the sync operation started"
32
- },
33
- endTime: {
34
- type: DataTypes.DATE,
35
- allowNull: true,
36
- comment: "When the sync operation completed"
37
- },
38
- duration: {
39
- type: DataTypes.INTEGER,
40
- allowNull: true,
41
- comment: "Duration in milliseconds"
42
- },
43
- status: {
44
- type: DataTypes.ENUM('running', 'completed', 'failed', 'cancelled'),
45
- allowNull: false,
46
- defaultValue: 'running',
47
- comment: "Current status of the sync operation"
48
- },
49
- success: {
50
- type: DataTypes.BOOLEAN,
51
- allowNull: true,
52
- comment: "Whether the sync completed successfully"
53
- },
54
- totalTables: {
55
- type: DataTypes.INTEGER,
56
- allowNull: false,
57
- defaultValue: 0,
58
- comment: "Total number of tables in the sync"
59
- },
60
- successfulTables: {
61
- type: DataTypes.INTEGER,
62
- allowNull: false,
63
- defaultValue: 0,
64
- comment: "Number of tables synced successfully"
65
- },
66
- failedTables: {
67
- type: DataTypes.INTEGER,
68
- allowNull: false,
69
- defaultValue: 0,
70
- comment: "Number of tables that failed to sync"
71
- },
72
- totalRecords: {
73
- type: DataTypes.INTEGER,
74
- allowNull: false,
75
- defaultValue: 0,
76
- comment: "Total number of records synced"
77
- },
78
- tablesIncluded: {
79
- type: DataTypes.ARRAY(DataTypes.STRING),
80
- allowNull: false,
81
- defaultValue: [],
82
- comment: "List of tables included in this sync"
83
- },
84
- syncOptions: {
85
- type: DataTypes.JSONB,
86
- allowNull: true,
87
- comment: "Sync options used (truncateFirst, batchSize, etc.)"
88
- },
89
- errorCount: {
90
- type: DataTypes.INTEGER,
91
- allowNull: false,
92
- defaultValue: 0,
93
- comment: "Number of errors encountered"
94
- },
95
- errorSummary: {
96
- type: DataTypes.TEXT,
97
- allowNull: true,
98
- comment: "Brief summary of errors encountered"
99
- },
100
- detailedResults: {
101
- type: DataTypes.JSONB,
102
- allowNull: true,
103
- comment: "Detailed results for each table (success/failure, record counts, errors)"
104
- },
105
- safetyChecks: {
106
- type: DataTypes.JSONB,
107
- allowNull: true,
108
- comment: "Safety check results (hosts, direction, etc.)"
109
- },
110
- sourceHost: {
111
- type: DataTypes.STRING,
112
- allowNull: true,
113
- comment: "Production database host"
114
- },
115
- targetHost: {
116
- type: DataTypes.STRING,
117
- allowNull: true,
118
- comment: "Staging database host"
119
- },
120
- environment: {
121
- type: DataTypes.STRING,
122
- allowNull: true,
123
- comment: "Environment where sync was executed (development, staging, production)"
124
- },
125
- groupsOrPreset: {
126
- type: DataTypes.STRING,
127
- allowNull: true,
128
- comment: "If this was a group/preset sync, which one was used"
129
- }
130
- },
131
- {
132
- tableName: "SyncHistory",
133
- timestamps: true, // Adds createdAt and updatedAt
134
- indexes: [
135
- {
136
- fields: ["syncId"],
137
- unique: true
138
- },
139
- {
140
- fields: ["startTime"],
141
- name: "idx_sync_history_start_time"
142
- },
143
- {
144
- fields: ["status"],
145
- name: "idx_sync_history_status"
146
- },
147
- {
148
- fields: ["success"],
149
- name: "idx_sync_history_success"
150
- },
151
- {
152
- fields: ["syncType"],
153
- name: "idx_sync_history_type"
154
- },
155
- {
156
- fields: ["initiatedBy"],
157
- name: "idx_sync_history_user"
158
- },
159
- {
160
- fields: ["createdAt"],
161
- name: "idx_sync_history_created"
162
- }
163
- ]
164
- }
165
- );
166
-
167
- // Add model methods
168
- SyncHistory.prototype.getDurationInSeconds = function() {
169
- return this.duration ? (this.duration / 1000).toFixed(1) : null;
170
- };
171
-
172
- SyncHistory.prototype.getSuccessRate = function() {
173
- if (this.totalTables === 0) return 0;
174
- return ((this.successfulTables / this.totalTables) * 100).toFixed(1);
175
- };
176
-
177
- SyncHistory.prototype.isRunning = function() {
178
- return this.status === 'running';
179
- };
180
-
181
- SyncHistory.prototype.hasErrors = function() {
182
- return this.errorCount > 0;
183
- };
184
-
185
- // Static methods for common queries
186
- SyncHistory.getRecentHistory = async function(limit = 10) {
187
- return await this.findAll({
188
- order: [['startTime', 'DESC']],
189
- limit: limit
190
- });
191
- };
192
-
193
- SyncHistory.getRunningsyncs = async function() {
194
- return await this.findAll({
195
- where: { status: 'running' },
196
- order: [['startTime', 'DESC']]
197
- });
198
- };
199
-
200
- SyncHistory.getSuccessfulSyncs = async function(limit = 10) {
201
- return await this.findAll({
202
- where: { success: true },
203
- order: [['startTime', 'DESC']],
204
- limit: limit
205
- });
206
- };
207
-
208
- SyncHistory.getFailedSyncs = async function(limit = 10) {
209
- return await this.findAll({
210
- where: { success: false },
211
- order: [['startTime', 'DESC']],
212
- limit: limit
213
- });
214
- };
215
-
216
- SyncHistory.getSyncStats = async function() {
217
- const total = await this.count();
218
- const successful = await this.count({ where: { success: true } });
219
- const failed = await this.count({ where: { success: false } });
220
- const running = await this.count({ where: { status: 'running' } });
221
-
222
- const avgDuration = await this.findOne({
223
- attributes: [
224
- [sequelize.fn('AVG', sequelize.col('duration')), 'avgDuration']
225
- ],
226
- where: { success: true },
227
- raw: true
228
- });
229
-
230
- const totalRecords = await this.findOne({
231
- attributes: [
232
- [sequelize.fn('SUM', sequelize.col('totalRecords')), 'totalRecords']
233
- ],
234
- where: { success: true },
235
- raw: true
236
- });
237
-
238
- return {
239
- totalSyncs: total,
240
- successfulSyncs: successful,
241
- failedSyncs: failed,
242
- runningSyncs: running,
243
- successRate: total > 0 ? ((successful / total) * 100).toFixed(1) : 0,
244
- averageDuration: avgDuration?.avgDuration ? Math.round(avgDuration.avgDuration) : null,
245
- totalRecordsSynced: totalRecords?.totalRecords || 0
246
- };
247
- };
248
-
249
- return SyncHistory;
1
+ // models/SyncHistory.js
2
+ module.exports = (sequelize, DataTypes) => {
3
+ const SyncHistory = sequelize.define(
4
+ "SyncHistory",
5
+ {
6
+ id: {
7
+ type: DataTypes.INTEGER,
8
+ primaryKey: true,
9
+ autoIncrement: true,
10
+ },
11
+ syncId: {
12
+ type: DataTypes.STRING,
13
+ allowNull: false,
14
+ unique: true,
15
+ comment: "Unique identifier for the sync operation"
16
+ },
17
+ syncType: {
18
+ type: DataTypes.ENUM('manual', 'quick_sync', 'group_sync', 'preset_sync', 'scheduled'),
19
+ allowNull: false,
20
+ defaultValue: 'manual',
21
+ comment: "Type of sync operation performed"
22
+ },
23
+ initiatedBy: {
24
+ type: DataTypes.STRING,
25
+ allowNull: true,
26
+ comment: "User who initiated the sync (username or user ID)"
27
+ },
28
+ startTime: {
29
+ type: DataTypes.DATE,
30
+ allowNull: false,
31
+ comment: "When the sync operation started"
32
+ },
33
+ endTime: {
34
+ type: DataTypes.DATE,
35
+ allowNull: true,
36
+ comment: "When the sync operation completed"
37
+ },
38
+ duration: {
39
+ type: DataTypes.INTEGER,
40
+ allowNull: true,
41
+ comment: "Duration in milliseconds"
42
+ },
43
+ status: {
44
+ type: DataTypes.ENUM('running', 'completed', 'failed', 'cancelled'),
45
+ allowNull: false,
46
+ defaultValue: 'running',
47
+ comment: "Current status of the sync operation"
48
+ },
49
+ success: {
50
+ type: DataTypes.BOOLEAN,
51
+ allowNull: true,
52
+ comment: "Whether the sync completed successfully"
53
+ },
54
+ totalTables: {
55
+ type: DataTypes.INTEGER,
56
+ allowNull: false,
57
+ defaultValue: 0,
58
+ comment: "Total number of tables in the sync"
59
+ },
60
+ successfulTables: {
61
+ type: DataTypes.INTEGER,
62
+ allowNull: false,
63
+ defaultValue: 0,
64
+ comment: "Number of tables synced successfully"
65
+ },
66
+ failedTables: {
67
+ type: DataTypes.INTEGER,
68
+ allowNull: false,
69
+ defaultValue: 0,
70
+ comment: "Number of tables that failed to sync"
71
+ },
72
+ totalRecords: {
73
+ type: DataTypes.INTEGER,
74
+ allowNull: false,
75
+ defaultValue: 0,
76
+ comment: "Total number of records synced"
77
+ },
78
+ tablesIncluded: {
79
+ type: DataTypes.ARRAY(DataTypes.STRING),
80
+ allowNull: false,
81
+ defaultValue: [],
82
+ comment: "List of tables included in this sync"
83
+ },
84
+ syncOptions: {
85
+ type: DataTypes.JSONB,
86
+ allowNull: true,
87
+ comment: "Sync options used (truncateFirst, batchSize, etc.)"
88
+ },
89
+ errorCount: {
90
+ type: DataTypes.INTEGER,
91
+ allowNull: false,
92
+ defaultValue: 0,
93
+ comment: "Number of errors encountered"
94
+ },
95
+ errorSummary: {
96
+ type: DataTypes.TEXT,
97
+ allowNull: true,
98
+ comment: "Brief summary of errors encountered"
99
+ },
100
+ detailedResults: {
101
+ type: DataTypes.JSONB,
102
+ allowNull: true,
103
+ comment: "Detailed results for each table (success/failure, record counts, errors)"
104
+ },
105
+ safetyChecks: {
106
+ type: DataTypes.JSONB,
107
+ allowNull: true,
108
+ comment: "Safety check results (hosts, direction, etc.)"
109
+ },
110
+ sourceHost: {
111
+ type: DataTypes.STRING,
112
+ allowNull: true,
113
+ comment: "Production database host"
114
+ },
115
+ targetHost: {
116
+ type: DataTypes.STRING,
117
+ allowNull: true,
118
+ comment: "Staging database host"
119
+ },
120
+ environment: {
121
+ type: DataTypes.STRING,
122
+ allowNull: true,
123
+ comment: "Environment where sync was executed (development, staging, production)"
124
+ },
125
+ groupsOrPreset: {
126
+ type: DataTypes.STRING,
127
+ allowNull: true,
128
+ comment: "If this was a group/preset sync, which one was used"
129
+ }
130
+ },
131
+ {
132
+ tableName: "SyncHistory",
133
+ timestamps: true, // Adds createdAt and updatedAt
134
+ indexes: [
135
+ {
136
+ fields: ["syncId"],
137
+ unique: true
138
+ },
139
+ {
140
+ fields: ["startTime"],
141
+ name: "idx_sync_history_start_time"
142
+ },
143
+ {
144
+ fields: ["status"],
145
+ name: "idx_sync_history_status"
146
+ },
147
+ {
148
+ fields: ["success"],
149
+ name: "idx_sync_history_success"
150
+ },
151
+ {
152
+ fields: ["syncType"],
153
+ name: "idx_sync_history_type"
154
+ },
155
+ {
156
+ fields: ["initiatedBy"],
157
+ name: "idx_sync_history_user"
158
+ },
159
+ {
160
+ fields: ["createdAt"],
161
+ name: "idx_sync_history_created"
162
+ }
163
+ ]
164
+ }
165
+ );
166
+
167
+ // Add model methods
168
+ SyncHistory.prototype.getDurationInSeconds = function() {
169
+ return this.duration ? (this.duration / 1000).toFixed(1) : null;
170
+ };
171
+
172
+ SyncHistory.prototype.getSuccessRate = function() {
173
+ if (this.totalTables === 0) return 0;
174
+ return ((this.successfulTables / this.totalTables) * 100).toFixed(1);
175
+ };
176
+
177
+ SyncHistory.prototype.isRunning = function() {
178
+ return this.status === 'running';
179
+ };
180
+
181
+ SyncHistory.prototype.hasErrors = function() {
182
+ return this.errorCount > 0;
183
+ };
184
+
185
+ // Static methods for common queries
186
+ SyncHistory.getRecentHistory = async function(limit = 10) {
187
+ return await this.findAll({
188
+ order: [['startTime', 'DESC']],
189
+ limit: limit
190
+ });
191
+ };
192
+
193
+ SyncHistory.getRunningsyncs = async function() {
194
+ return await this.findAll({
195
+ where: { status: 'running' },
196
+ order: [['startTime', 'DESC']]
197
+ });
198
+ };
199
+
200
+ SyncHistory.getSuccessfulSyncs = async function(limit = 10) {
201
+ return await this.findAll({
202
+ where: { success: true },
203
+ order: [['startTime', 'DESC']],
204
+ limit: limit
205
+ });
206
+ };
207
+
208
+ SyncHistory.getFailedSyncs = async function(limit = 10) {
209
+ return await this.findAll({
210
+ where: { success: false },
211
+ order: [['startTime', 'DESC']],
212
+ limit: limit
213
+ });
214
+ };
215
+
216
+ SyncHistory.getSyncStats = async function() {
217
+ const total = await this.count();
218
+ const successful = await this.count({ where: { success: true } });
219
+ const failed = await this.count({ where: { success: false } });
220
+ const running = await this.count({ where: { status: 'running' } });
221
+
222
+ const avgDuration = await this.findOne({
223
+ attributes: [
224
+ [sequelize.fn('AVG', sequelize.col('duration')), 'avgDuration']
225
+ ],
226
+ where: { success: true },
227
+ raw: true
228
+ });
229
+
230
+ const totalRecords = await this.findOne({
231
+ attributes: [
232
+ [sequelize.fn('SUM', sequelize.col('totalRecords')), 'totalRecords']
233
+ ],
234
+ where: { success: true },
235
+ raw: true
236
+ });
237
+
238
+ return {
239
+ totalSyncs: total,
240
+ successfulSyncs: successful,
241
+ failedSyncs: failed,
242
+ runningSyncs: running,
243
+ successRate: total > 0 ? ((successful / total) * 100).toFixed(1) : 0,
244
+ averageDuration: avgDuration?.avgDuration ? Math.round(avgDuration.avgDuration) : null,
245
+ totalRecordsSynced: totalRecords?.totalRecords || 0
246
+ };
247
+ };
248
+
249
+ return SyncHistory;
250
250
  };