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.
- package/migrations/add-requested-from-dashboard-to-articles.js +17 -17
- package/models/AdAccountValues.js +25 -25
- package/models/AdHistory.js +30 -30
- package/models/AdPerformance.js +94 -94
- package/models/AdSet.js +289 -289
- package/models/AdSetHistory.js +30 -30
- package/models/AdsetPerformance.js +126 -126
- package/models/Article.js +190 -190
- package/models/AutomationRule.js +161 -127
- package/models/Buyers.js +25 -25
- package/models/Campaign.js +157 -157
- package/models/CampaignActionHistory.js +86 -86
- package/models/CampaignCreationLog.js +309 -309
- package/models/CampaignHistory.js +33 -33
- package/models/Channel.js +55 -55
- package/models/Domain.js +25 -25
- package/models/DynamicFeed.js +212 -212
- package/models/ExplorAdsChannel.js +61 -61
- package/models/Feed.js +33 -33
- package/models/FrontStoryChannel.js +59 -59
- package/models/MineChannel.js +42 -42
- package/models/Pages.js +81 -81
- package/models/PipelineExecution.js +59 -59
- package/models/Presets.js +34 -34
- package/models/RSOCFeedCampaign.js +357 -357
- package/models/RsocKeywordPerformance.js +110 -110
- package/models/RuleAction.js +90 -90
- package/models/RuleCondition.js +98 -98
- package/models/RuleExecution.js +107 -107
- package/models/RulesValues.js +56 -56
- package/models/SupportedLocale.js +23 -23
- package/models/SyncHistory.js +249 -249
- package/models/Tier2_AdAccounts.js +110 -110
- package/models/Tier2_Assets.js +70 -70
- package/models/Tier2_BusinessManagers.js +105 -105
- package/models/Tier2_CreditLines.js +99 -99
- package/models/Tier2_Pages.js +91 -91
- package/models/Tier2_Pixels.js +82 -82
- package/models/Tier2_Tokens.js +64 -64
- package/models/Tier2_UserAdAccounts.js +83 -83
- package/models/TokenRotationState.js +121 -121
- package/models/TonicRSOCKeywordPerformance.js +122 -122
- package/models/Vertical.js +25 -25
- package/models/newFiles.js +110 -110
- package/package.json +19 -21
- package/run.sh +214 -214
- package/services/sequelizeService.js +63 -63
|
@@ -1,309 +1,309 @@
|
|
|
1
|
-
// models/CampaignCreationLog.js
|
|
2
|
-
module.exports = (sequelize, DataTypes) => {
|
|
3
|
-
const CampaignCreationLog = sequelize.define(
|
|
4
|
-
"CampaignCreationLog",
|
|
5
|
-
{
|
|
6
|
-
id: {
|
|
7
|
-
type: DataTypes.INTEGER,
|
|
8
|
-
primaryKey: true,
|
|
9
|
-
autoIncrement: true,
|
|
10
|
-
},
|
|
11
|
-
process_id: {
|
|
12
|
-
type: DataTypes.UUID,
|
|
13
|
-
allowNull: false,
|
|
14
|
-
comment: "Unique ID for the creation batch process",
|
|
15
|
-
},
|
|
16
|
-
status: {
|
|
17
|
-
type: DataTypes.ENUM(
|
|
18
|
-
"STARTED",
|
|
19
|
-
"IN_PROGRESS",
|
|
20
|
-
"COMPLETED",
|
|
21
|
-
"FAILED",
|
|
22
|
-
"PARTIALLY_COMPLETED"
|
|
23
|
-
),
|
|
24
|
-
allowNull: false,
|
|
25
|
-
defaultValue: "STARTED",
|
|
26
|
-
},
|
|
27
|
-
country: {
|
|
28
|
-
type: DataTypes.TEXT,
|
|
29
|
-
allowNull: true,
|
|
30
|
-
comment: "Country being processed",
|
|
31
|
-
},
|
|
32
|
-
feed_campaign_id: {
|
|
33
|
-
type: DataTypes.STRING,
|
|
34
|
-
allowNull: true,
|
|
35
|
-
comment: "AGRS_CID of the created feed campaign",
|
|
36
|
-
},
|
|
37
|
-
facebook_campaign_id: {
|
|
38
|
-
type: DataTypes.STRING,
|
|
39
|
-
allowNull: true,
|
|
40
|
-
comment: "Facebook campaign ID if created",
|
|
41
|
-
},
|
|
42
|
-
details: {
|
|
43
|
-
type: DataTypes.JSONB,
|
|
44
|
-
allowNull: true,
|
|
45
|
-
comment: "Additional details about the process or results",
|
|
46
|
-
},
|
|
47
|
-
error_message: {
|
|
48
|
-
type: DataTypes.TEXT,
|
|
49
|
-
allowNull: true,
|
|
50
|
-
comment: "Error message if process failed",
|
|
51
|
-
},
|
|
52
|
-
vertical: {
|
|
53
|
-
type: DataTypes.STRING(100),
|
|
54
|
-
allowNull: true,
|
|
55
|
-
comment: "Campaign vertical (e.g., babydiapers, veteranbenefits)",
|
|
56
|
-
},
|
|
57
|
-
feed_provider: {
|
|
58
|
-
type: DataTypes.STRING(100),
|
|
59
|
-
allowNull: true,
|
|
60
|
-
comment: "Feed provider (e.g., predicto.ai, compado)",
|
|
61
|
-
},
|
|
62
|
-
media_buyer: {
|
|
63
|
-
type: DataTypes.STRING(100),
|
|
64
|
-
allowNull: true,
|
|
65
|
-
comment: "Media buyer/assignee (e.g., dug, ida)",
|
|
66
|
-
},
|
|
67
|
-
account_id: {
|
|
68
|
-
type: DataTypes.STRING(100),
|
|
69
|
-
allowNull: true,
|
|
70
|
-
comment: "Facebook account ID",
|
|
71
|
-
},
|
|
72
|
-
campaign_name: {
|
|
73
|
-
type: DataTypes.STRING(255),
|
|
74
|
-
allowNull: true,
|
|
75
|
-
comment: "Campaign name",
|
|
76
|
-
},
|
|
77
|
-
assignee: {
|
|
78
|
-
type: DataTypes.STRING(100),
|
|
79
|
-
allowNull: true,
|
|
80
|
-
comment: "Alternative assignee field",
|
|
81
|
-
},
|
|
82
|
-
facebook_campaign_name: {
|
|
83
|
-
type: DataTypes.STRING(255),
|
|
84
|
-
allowNull: true,
|
|
85
|
-
comment: "Facebook campaign name",
|
|
86
|
-
},
|
|
87
|
-
notes: {
|
|
88
|
-
type: DataTypes.TEXT,
|
|
89
|
-
allowNull: true,
|
|
90
|
-
comment: "Campaign notes/freeText",
|
|
91
|
-
},
|
|
92
|
-
free_text: {
|
|
93
|
-
type: DataTypes.TEXT,
|
|
94
|
-
allowNull: true,
|
|
95
|
-
comment: "Free text content",
|
|
96
|
-
},
|
|
97
|
-
ad_title: {
|
|
98
|
-
type: DataTypes.STRING(500),
|
|
99
|
-
allowNull: true,
|
|
100
|
-
comment: "Ad title",
|
|
101
|
-
},
|
|
102
|
-
keywords: {
|
|
103
|
-
type: DataTypes.ARRAY(DataTypes.TEXT),
|
|
104
|
-
allowNull: true,
|
|
105
|
-
comment: "Campaign keywords array",
|
|
106
|
-
},
|
|
107
|
-
countries: {
|
|
108
|
-
type: DataTypes.ARRAY(DataTypes.TEXT),
|
|
109
|
-
allowNull: true,
|
|
110
|
-
comment: "Target countries array",
|
|
111
|
-
},
|
|
112
|
-
platform: {
|
|
113
|
-
type: DataTypes.STRING(50),
|
|
114
|
-
allowNull: true,
|
|
115
|
-
comment: "Platform (e.g., Facebook)",
|
|
116
|
-
},
|
|
117
|
-
bid_strategy: {
|
|
118
|
-
type: DataTypes.STRING(100),
|
|
119
|
-
allowNull: true,
|
|
120
|
-
comment: "Bid strategy",
|
|
121
|
-
},
|
|
122
|
-
daily_budget: {
|
|
123
|
-
type: DataTypes.DECIMAL(10, 2),
|
|
124
|
-
allowNull: true,
|
|
125
|
-
comment: "Daily budget amount",
|
|
126
|
-
},
|
|
127
|
-
bid_amount: {
|
|
128
|
-
type: DataTypes.DECIMAL(10, 2),
|
|
129
|
-
allowNull: true,
|
|
130
|
-
comment: "Bid amount",
|
|
131
|
-
},
|
|
132
|
-
language: {
|
|
133
|
-
type: DataTypes.STRING(50),
|
|
134
|
-
allowNull: true,
|
|
135
|
-
comment: "Campaign language",
|
|
136
|
-
},
|
|
137
|
-
domain: {
|
|
138
|
-
type: DataTypes.STRING(255),
|
|
139
|
-
allowNull: true,
|
|
140
|
-
comment: "Campaign domain",
|
|
141
|
-
},
|
|
142
|
-
page_id: {
|
|
143
|
-
type: DataTypes.UUID,
|
|
144
|
-
allowNull: true,
|
|
145
|
-
comment: "Facebook Page ID (UUID from Pages table)",
|
|
146
|
-
},
|
|
147
|
-
page_code: {
|
|
148
|
-
type: DataTypes.STRING(100),
|
|
149
|
-
allowNull: true,
|
|
150
|
-
comment: "Page code (unique identifier from Pages table)",
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
tableName: "CampaignCreationLogs",
|
|
155
|
-
timestamps: true,
|
|
156
|
-
indexes: [
|
|
157
|
-
// CRITICAL: Main performance index for your DISTINCT ON query
|
|
158
|
-
{
|
|
159
|
-
name: "idx_campaign_logs_process_created_desc",
|
|
160
|
-
fields: ["process_id", { name: "createdAt", order: "DESC" }],
|
|
161
|
-
},
|
|
162
|
-
// JSON search optimization for account ID filtering
|
|
163
|
-
{
|
|
164
|
-
name: "idx_campaign_logs_details_gin",
|
|
165
|
-
fields: ["details"],
|
|
166
|
-
using: "gin",
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
name: "idx_campaign_logs_vertical",
|
|
170
|
-
fields: ["vertical"],
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
name: "idx_campaign_logs_feed_provider",
|
|
174
|
-
fields: ["feed_provider"],
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
name: "idx_campaign_logs_media_buyer",
|
|
178
|
-
fields: ["media_buyer"],
|
|
179
|
-
},
|
|
180
|
-
{
|
|
181
|
-
name: "idx_campaign_logs_account_id",
|
|
182
|
-
fields: ["account_id"],
|
|
183
|
-
},
|
|
184
|
-
{
|
|
185
|
-
name: "idx_campaign_logs_campaign_name",
|
|
186
|
-
fields: ["campaign_name"],
|
|
187
|
-
},
|
|
188
|
-
{
|
|
189
|
-
name: "idx_campaign_logs_assignee",
|
|
190
|
-
fields: ["assignee"],
|
|
191
|
-
},
|
|
192
|
-
{
|
|
193
|
-
name: "idx_campaign_logs_keywords",
|
|
194
|
-
fields: ["keywords"],
|
|
195
|
-
using: "gin",
|
|
196
|
-
},
|
|
197
|
-
{
|
|
198
|
-
name: "idx_campaign_logs_countries",
|
|
199
|
-
fields: ["countries"],
|
|
200
|
-
using: "gin",
|
|
201
|
-
},
|
|
202
|
-
// Composite index for status + country filters
|
|
203
|
-
{
|
|
204
|
-
name: "idx_campaign_logs_status_country",
|
|
205
|
-
fields: ["status", "country"],
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
name: "idx_campaign_logs_vertical_status",
|
|
209
|
-
fields: ["vertical", "status"],
|
|
210
|
-
},
|
|
211
|
-
{
|
|
212
|
-
name: "idx_campaign_logs_feed_provider_status",
|
|
213
|
-
fields: ["feed_provider", "status"],
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
name: "idx_campaign_logs_media_buyer_status",
|
|
217
|
-
fields: ["media_buyer", "status"],
|
|
218
|
-
},
|
|
219
|
-
{
|
|
220
|
-
name: "idx_campaign_logs_account_id_status",
|
|
221
|
-
fields: ["account_id", "status"],
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
name: "idx_campaign_logs_vertical_feed_provider",
|
|
225
|
-
fields: ["vertical", "feed_provider"],
|
|
226
|
-
},
|
|
227
|
-
{
|
|
228
|
-
name: "idx_campaign_logs_media_buyer_vertical",
|
|
229
|
-
fields: ["media_buyer", "vertical"],
|
|
230
|
-
},
|
|
231
|
-
{
|
|
232
|
-
name: "idx_campaign_logs_process_status_created",
|
|
233
|
-
fields: ["process_id", "status", "createdAt"],
|
|
234
|
-
},
|
|
235
|
-
{
|
|
236
|
-
name: "idx_campaign_logs_created_at_desc",
|
|
237
|
-
fields: [{ name: "createdAt", order: "DESC" }],
|
|
238
|
-
comment: "Critical for last day filtering and sorting by date",
|
|
239
|
-
},
|
|
240
|
-
{
|
|
241
|
-
name: "idx_campaign_logs_status_created_at",
|
|
242
|
-
fields: ["status", { name: "createdAt", order: "DESC" }],
|
|
243
|
-
comment: "Optimized for filtering by status within date ranges",
|
|
244
|
-
},
|
|
245
|
-
{
|
|
246
|
-
name: "idx_campaign_logs_process_created_at_desc",
|
|
247
|
-
fields: ["process_id", { name: "createdAt", order: "DESC" }],
|
|
248
|
-
comment: "Optimized for DISTINCT ON queries with date ordering",
|
|
249
|
-
},
|
|
250
|
-
{
|
|
251
|
-
name: "idx_campaign_logs_account_process",
|
|
252
|
-
fields: ["account_id", "process_id"],
|
|
253
|
-
comment: "For process-level account filtering v2",
|
|
254
|
-
},
|
|
255
|
-
{
|
|
256
|
-
name: "idx_campaign_logs_page_id",
|
|
257
|
-
fields: ["page_id"],
|
|
258
|
-
comment: "For page filtering",
|
|
259
|
-
},
|
|
260
|
-
{
|
|
261
|
-
name: "idx_campaign_logs_page_code",
|
|
262
|
-
fields: ["page_code"],
|
|
263
|
-
comment: "For page code filtering",
|
|
264
|
-
},
|
|
265
|
-
{
|
|
266
|
-
fields: ["process_id"],
|
|
267
|
-
},
|
|
268
|
-
{
|
|
269
|
-
fields: ["status"],
|
|
270
|
-
},
|
|
271
|
-
{
|
|
272
|
-
fields: ["country"],
|
|
273
|
-
},
|
|
274
|
-
{
|
|
275
|
-
fields: ["feed_campaign_id"],
|
|
276
|
-
},
|
|
277
|
-
{
|
|
278
|
-
fields: ["facebook_campaign_id"],
|
|
279
|
-
},
|
|
280
|
-
{
|
|
281
|
-
fields: ["createdAt"],
|
|
282
|
-
},
|
|
283
|
-
],
|
|
284
|
-
}
|
|
285
|
-
);
|
|
286
|
-
|
|
287
|
-
CampaignCreationLog.associate = (models) => {
|
|
288
|
-
// Add associations if needed
|
|
289
|
-
if (models.CodefuelCampaign) {
|
|
290
|
-
CampaignCreationLog.belongsTo(models.CodefuelCampaign, {
|
|
291
|
-
foreignKey: "feed_campaign_id",
|
|
292
|
-
targetKey: "AGRSCID",
|
|
293
|
-
as: "FeedCampaign",
|
|
294
|
-
constraints: false,
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
if (models.Pages) {
|
|
299
|
-
CampaignCreationLog.belongsTo(models.Pages, {
|
|
300
|
-
foreignKey: "page_code",
|
|
301
|
-
targetKey: "code",
|
|
302
|
-
as: "Page",
|
|
303
|
-
constraints: false,
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
return CampaignCreationLog;
|
|
309
|
-
};
|
|
1
|
+
// models/CampaignCreationLog.js
|
|
2
|
+
module.exports = (sequelize, DataTypes) => {
|
|
3
|
+
const CampaignCreationLog = sequelize.define(
|
|
4
|
+
"CampaignCreationLog",
|
|
5
|
+
{
|
|
6
|
+
id: {
|
|
7
|
+
type: DataTypes.INTEGER,
|
|
8
|
+
primaryKey: true,
|
|
9
|
+
autoIncrement: true,
|
|
10
|
+
},
|
|
11
|
+
process_id: {
|
|
12
|
+
type: DataTypes.UUID,
|
|
13
|
+
allowNull: false,
|
|
14
|
+
comment: "Unique ID for the creation batch process",
|
|
15
|
+
},
|
|
16
|
+
status: {
|
|
17
|
+
type: DataTypes.ENUM(
|
|
18
|
+
"STARTED",
|
|
19
|
+
"IN_PROGRESS",
|
|
20
|
+
"COMPLETED",
|
|
21
|
+
"FAILED",
|
|
22
|
+
"PARTIALLY_COMPLETED"
|
|
23
|
+
),
|
|
24
|
+
allowNull: false,
|
|
25
|
+
defaultValue: "STARTED",
|
|
26
|
+
},
|
|
27
|
+
country: {
|
|
28
|
+
type: DataTypes.TEXT,
|
|
29
|
+
allowNull: true,
|
|
30
|
+
comment: "Country being processed",
|
|
31
|
+
},
|
|
32
|
+
feed_campaign_id: {
|
|
33
|
+
type: DataTypes.STRING,
|
|
34
|
+
allowNull: true,
|
|
35
|
+
comment: "AGRS_CID of the created feed campaign",
|
|
36
|
+
},
|
|
37
|
+
facebook_campaign_id: {
|
|
38
|
+
type: DataTypes.STRING,
|
|
39
|
+
allowNull: true,
|
|
40
|
+
comment: "Facebook campaign ID if created",
|
|
41
|
+
},
|
|
42
|
+
details: {
|
|
43
|
+
type: DataTypes.JSONB,
|
|
44
|
+
allowNull: true,
|
|
45
|
+
comment: "Additional details about the process or results",
|
|
46
|
+
},
|
|
47
|
+
error_message: {
|
|
48
|
+
type: DataTypes.TEXT,
|
|
49
|
+
allowNull: true,
|
|
50
|
+
comment: "Error message if process failed",
|
|
51
|
+
},
|
|
52
|
+
vertical: {
|
|
53
|
+
type: DataTypes.STRING(100),
|
|
54
|
+
allowNull: true,
|
|
55
|
+
comment: "Campaign vertical (e.g., babydiapers, veteranbenefits)",
|
|
56
|
+
},
|
|
57
|
+
feed_provider: {
|
|
58
|
+
type: DataTypes.STRING(100),
|
|
59
|
+
allowNull: true,
|
|
60
|
+
comment: "Feed provider (e.g., predicto.ai, compado)",
|
|
61
|
+
},
|
|
62
|
+
media_buyer: {
|
|
63
|
+
type: DataTypes.STRING(100),
|
|
64
|
+
allowNull: true,
|
|
65
|
+
comment: "Media buyer/assignee (e.g., dug, ida)",
|
|
66
|
+
},
|
|
67
|
+
account_id: {
|
|
68
|
+
type: DataTypes.STRING(100),
|
|
69
|
+
allowNull: true,
|
|
70
|
+
comment: "Facebook account ID",
|
|
71
|
+
},
|
|
72
|
+
campaign_name: {
|
|
73
|
+
type: DataTypes.STRING(255),
|
|
74
|
+
allowNull: true,
|
|
75
|
+
comment: "Campaign name",
|
|
76
|
+
},
|
|
77
|
+
assignee: {
|
|
78
|
+
type: DataTypes.STRING(100),
|
|
79
|
+
allowNull: true,
|
|
80
|
+
comment: "Alternative assignee field",
|
|
81
|
+
},
|
|
82
|
+
facebook_campaign_name: {
|
|
83
|
+
type: DataTypes.STRING(255),
|
|
84
|
+
allowNull: true,
|
|
85
|
+
comment: "Facebook campaign name",
|
|
86
|
+
},
|
|
87
|
+
notes: {
|
|
88
|
+
type: DataTypes.TEXT,
|
|
89
|
+
allowNull: true,
|
|
90
|
+
comment: "Campaign notes/freeText",
|
|
91
|
+
},
|
|
92
|
+
free_text: {
|
|
93
|
+
type: DataTypes.TEXT,
|
|
94
|
+
allowNull: true,
|
|
95
|
+
comment: "Free text content",
|
|
96
|
+
},
|
|
97
|
+
ad_title: {
|
|
98
|
+
type: DataTypes.STRING(500),
|
|
99
|
+
allowNull: true,
|
|
100
|
+
comment: "Ad title",
|
|
101
|
+
},
|
|
102
|
+
keywords: {
|
|
103
|
+
type: DataTypes.ARRAY(DataTypes.TEXT),
|
|
104
|
+
allowNull: true,
|
|
105
|
+
comment: "Campaign keywords array",
|
|
106
|
+
},
|
|
107
|
+
countries: {
|
|
108
|
+
type: DataTypes.ARRAY(DataTypes.TEXT),
|
|
109
|
+
allowNull: true,
|
|
110
|
+
comment: "Target countries array",
|
|
111
|
+
},
|
|
112
|
+
platform: {
|
|
113
|
+
type: DataTypes.STRING(50),
|
|
114
|
+
allowNull: true,
|
|
115
|
+
comment: "Platform (e.g., Facebook)",
|
|
116
|
+
},
|
|
117
|
+
bid_strategy: {
|
|
118
|
+
type: DataTypes.STRING(100),
|
|
119
|
+
allowNull: true,
|
|
120
|
+
comment: "Bid strategy",
|
|
121
|
+
},
|
|
122
|
+
daily_budget: {
|
|
123
|
+
type: DataTypes.DECIMAL(10, 2),
|
|
124
|
+
allowNull: true,
|
|
125
|
+
comment: "Daily budget amount",
|
|
126
|
+
},
|
|
127
|
+
bid_amount: {
|
|
128
|
+
type: DataTypes.DECIMAL(10, 2),
|
|
129
|
+
allowNull: true,
|
|
130
|
+
comment: "Bid amount",
|
|
131
|
+
},
|
|
132
|
+
language: {
|
|
133
|
+
type: DataTypes.STRING(50),
|
|
134
|
+
allowNull: true,
|
|
135
|
+
comment: "Campaign language",
|
|
136
|
+
},
|
|
137
|
+
domain: {
|
|
138
|
+
type: DataTypes.STRING(255),
|
|
139
|
+
allowNull: true,
|
|
140
|
+
comment: "Campaign domain",
|
|
141
|
+
},
|
|
142
|
+
page_id: {
|
|
143
|
+
type: DataTypes.UUID,
|
|
144
|
+
allowNull: true,
|
|
145
|
+
comment: "Facebook Page ID (UUID from Pages table)",
|
|
146
|
+
},
|
|
147
|
+
page_code: {
|
|
148
|
+
type: DataTypes.STRING(100),
|
|
149
|
+
allowNull: true,
|
|
150
|
+
comment: "Page code (unique identifier from Pages table)",
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
tableName: "CampaignCreationLogs",
|
|
155
|
+
timestamps: true,
|
|
156
|
+
indexes: [
|
|
157
|
+
// CRITICAL: Main performance index for your DISTINCT ON query
|
|
158
|
+
{
|
|
159
|
+
name: "idx_campaign_logs_process_created_desc",
|
|
160
|
+
fields: ["process_id", { name: "createdAt", order: "DESC" }],
|
|
161
|
+
},
|
|
162
|
+
// JSON search optimization for account ID filtering
|
|
163
|
+
{
|
|
164
|
+
name: "idx_campaign_logs_details_gin",
|
|
165
|
+
fields: ["details"],
|
|
166
|
+
using: "gin",
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
name: "idx_campaign_logs_vertical",
|
|
170
|
+
fields: ["vertical"],
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
name: "idx_campaign_logs_feed_provider",
|
|
174
|
+
fields: ["feed_provider"],
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
name: "idx_campaign_logs_media_buyer",
|
|
178
|
+
fields: ["media_buyer"],
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
name: "idx_campaign_logs_account_id",
|
|
182
|
+
fields: ["account_id"],
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
name: "idx_campaign_logs_campaign_name",
|
|
186
|
+
fields: ["campaign_name"],
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: "idx_campaign_logs_assignee",
|
|
190
|
+
fields: ["assignee"],
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
name: "idx_campaign_logs_keywords",
|
|
194
|
+
fields: ["keywords"],
|
|
195
|
+
using: "gin",
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
name: "idx_campaign_logs_countries",
|
|
199
|
+
fields: ["countries"],
|
|
200
|
+
using: "gin",
|
|
201
|
+
},
|
|
202
|
+
// Composite index for status + country filters
|
|
203
|
+
{
|
|
204
|
+
name: "idx_campaign_logs_status_country",
|
|
205
|
+
fields: ["status", "country"],
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
name: "idx_campaign_logs_vertical_status",
|
|
209
|
+
fields: ["vertical", "status"],
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
name: "idx_campaign_logs_feed_provider_status",
|
|
213
|
+
fields: ["feed_provider", "status"],
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
name: "idx_campaign_logs_media_buyer_status",
|
|
217
|
+
fields: ["media_buyer", "status"],
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
name: "idx_campaign_logs_account_id_status",
|
|
221
|
+
fields: ["account_id", "status"],
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
name: "idx_campaign_logs_vertical_feed_provider",
|
|
225
|
+
fields: ["vertical", "feed_provider"],
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
name: "idx_campaign_logs_media_buyer_vertical",
|
|
229
|
+
fields: ["media_buyer", "vertical"],
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
name: "idx_campaign_logs_process_status_created",
|
|
233
|
+
fields: ["process_id", "status", "createdAt"],
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
name: "idx_campaign_logs_created_at_desc",
|
|
237
|
+
fields: [{ name: "createdAt", order: "DESC" }],
|
|
238
|
+
comment: "Critical for last day filtering and sorting by date",
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
name: "idx_campaign_logs_status_created_at",
|
|
242
|
+
fields: ["status", { name: "createdAt", order: "DESC" }],
|
|
243
|
+
comment: "Optimized for filtering by status within date ranges",
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
name: "idx_campaign_logs_process_created_at_desc",
|
|
247
|
+
fields: ["process_id", { name: "createdAt", order: "DESC" }],
|
|
248
|
+
comment: "Optimized for DISTINCT ON queries with date ordering",
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
name: "idx_campaign_logs_account_process",
|
|
252
|
+
fields: ["account_id", "process_id"],
|
|
253
|
+
comment: "For process-level account filtering v2",
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
name: "idx_campaign_logs_page_id",
|
|
257
|
+
fields: ["page_id"],
|
|
258
|
+
comment: "For page filtering",
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
name: "idx_campaign_logs_page_code",
|
|
262
|
+
fields: ["page_code"],
|
|
263
|
+
comment: "For page code filtering",
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
fields: ["process_id"],
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
fields: ["status"],
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
fields: ["country"],
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
fields: ["feed_campaign_id"],
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
fields: ["facebook_campaign_id"],
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
fields: ["createdAt"],
|
|
282
|
+
},
|
|
283
|
+
],
|
|
284
|
+
}
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
CampaignCreationLog.associate = (models) => {
|
|
288
|
+
// Add associations if needed
|
|
289
|
+
if (models.CodefuelCampaign) {
|
|
290
|
+
CampaignCreationLog.belongsTo(models.CodefuelCampaign, {
|
|
291
|
+
foreignKey: "feed_campaign_id",
|
|
292
|
+
targetKey: "AGRSCID",
|
|
293
|
+
as: "FeedCampaign",
|
|
294
|
+
constraints: false,
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (models.Pages) {
|
|
299
|
+
CampaignCreationLog.belongsTo(models.Pages, {
|
|
300
|
+
foreignKey: "page_code",
|
|
301
|
+
targetKey: "code",
|
|
302
|
+
as: "Page",
|
|
303
|
+
constraints: false,
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
return CampaignCreationLog;
|
|
309
|
+
};
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
module.exports = (sequelize, DataTypes) => {
|
|
2
|
-
const CampaignHistory = sequelize.define(
|
|
3
|
-
"CampaignHistory",
|
|
4
|
-
{
|
|
5
|
-
HistoryID: {
|
|
6
|
-
type: DataTypes.UUID,
|
|
7
|
-
defaultValue: DataTypes.UUIDV4,
|
|
8
|
-
primaryKey: true,
|
|
9
|
-
},
|
|
10
|
-
CampaignID: {
|
|
11
|
-
type: DataTypes.STRING,
|
|
12
|
-
allowNull: false,
|
|
13
|
-
},
|
|
14
|
-
TableName: {
|
|
15
|
-
type: DataTypes.STRING, // Useful for multi-table history tracking
|
|
16
|
-
defaultValue: "Campaign",
|
|
17
|
-
},
|
|
18
|
-
DataSnapshot: {
|
|
19
|
-
type: DataTypes.JSONB, // Store the entire row as JSON
|
|
20
|
-
allowNull: false,
|
|
21
|
-
},
|
|
22
|
-
timestamp: {
|
|
23
|
-
type: DataTypes.DATE,
|
|
24
|
-
defaultValue: DataTypes.NOW,
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
tableName: "CampaignHistory",
|
|
29
|
-
}
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
return CampaignHistory;
|
|
33
|
-
};
|
|
1
|
+
module.exports = (sequelize, DataTypes) => {
|
|
2
|
+
const CampaignHistory = sequelize.define(
|
|
3
|
+
"CampaignHistory",
|
|
4
|
+
{
|
|
5
|
+
HistoryID: {
|
|
6
|
+
type: DataTypes.UUID,
|
|
7
|
+
defaultValue: DataTypes.UUIDV4,
|
|
8
|
+
primaryKey: true,
|
|
9
|
+
},
|
|
10
|
+
CampaignID: {
|
|
11
|
+
type: DataTypes.STRING,
|
|
12
|
+
allowNull: false,
|
|
13
|
+
},
|
|
14
|
+
TableName: {
|
|
15
|
+
type: DataTypes.STRING, // Useful for multi-table history tracking
|
|
16
|
+
defaultValue: "Campaign",
|
|
17
|
+
},
|
|
18
|
+
DataSnapshot: {
|
|
19
|
+
type: DataTypes.JSONB, // Store the entire row as JSON
|
|
20
|
+
allowNull: false,
|
|
21
|
+
},
|
|
22
|
+
timestamp: {
|
|
23
|
+
type: DataTypes.DATE,
|
|
24
|
+
defaultValue: DataTypes.NOW,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
tableName: "CampaignHistory",
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
return CampaignHistory;
|
|
33
|
+
};
|