agrs-sequelize-sdk 1.4.59 → 1.4.61
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/2026-05-17-PIXELS-FOLLOWUP.md +85 -85
- package/migrations/2026-05-17-add-platform-to-ad.js +19 -19
- package/migrations/2026-05-17-add-platform-to-adaccount.js +19 -19
- package/migrations/2026-05-17-add-platform-to-adperformance.js +19 -19
- package/migrations/2026-05-17-add-platform-to-adset.js +19 -19
- package/migrations/2026-05-17-add-platform-to-adsetperformance.js +19 -19
- package/migrations/2026-05-17-add-platform-to-aiarticleretryqueue.js +19 -19
- package/migrations/2026-05-17-add-platform-to-aicampaignqueue.js +19 -19
- package/migrations/2026-05-17-add-platform-to-article.js +19 -19
- package/migrations/2026-05-17-add-platform-to-campaign.js +19 -19
- package/migrations/2026-05-17-add-platform-to-codefuelcampaign.js +19 -19
- package/migrations/2026-05-17-add-platform-to-dynamicfeed.js +19 -19
- package/migrations/2026-05-17-add-platform-to-facebookretryqueue.js +19 -19
- package/migrations/2026-05-17-add-platform-to-pages.js +19 -19
- package/migrations/2026-05-17-add-platform-to-presets.js +19 -19
- package/migrations/2026-05-18-add-group-id-to-ai-campaign-queue.js +18 -18
- package/migrations/2026-05-18-add-platform-code-to-creation-logs.js +65 -65
- package/migrations/2026-05-18-add-platform-code-to-pixels.js +55 -55
- package/migrations/2026-05-18-add-platform-code-to-rsoc-feed-campaigns.js +55 -55
- package/migrations/2026-05-18-add-platform-date-index-to-adperformance.js +16 -16
- package/migrations/2026-05-18-add-platform-date-index-to-adsetperformance.js +16 -16
- package/migrations/2026-05-18-add-review-status-to-ad.js +36 -36
- package/migrations/2026-05-18-create-canonical-insights.js +84 -84
- package/migrations/2026-05-18-create-snapchat-public-profiles.js +68 -68
- package/migrations/2026-05-18-create-tiktok-identities.js +71 -71
- package/migrations/2026-05-18-create-tiktok-snapchat-campaigns.js +143 -143
- package/migrations/2026-05-18-create-tt-snp-adset-ad-tables.js +309 -309
- package/migrations/RUN_ME_MANUALLY_2026-05-17.sql +99 -99
- package/migrations/add-requested-from-dashboard-to-articles.js +17 -17
- package/migrations/change-adset-name-to-text.js +79 -79
- package/models/AICampaignQueue.js +151 -151
- package/models/AIGenerationLog.js +85 -85
- package/models/AIGenerationRequest.js +212 -212
- package/models/AdAccountValues.js +25 -25
- package/models/AdHistory.js +30 -30
- package/models/AdPerformance.js +104 -104
- package/models/AdSet.js +295 -295
- package/models/AdSetHistory.js +30 -30
- package/models/AdsetPerformance.js +137 -137
- package/models/AiArticleRetryQueue.js +157 -157
- package/models/AiCreationRetryQueue.js +134 -134
- package/models/ApiAuditLog.js +127 -127
- package/models/ApiToken.js +67 -67
- package/models/Article.js +222 -222
- package/models/AutomationRule.js +179 -179
- package/models/BannerTemplate.js +129 -129
- package/models/Buyers.js +25 -25
- package/models/Campaign.js +168 -168
- package/models/CampaignActionHistory.js +101 -101
- package/models/CampaignCreationLog.js +340 -340
- package/models/CampaignCreationLogV2.js +392 -392
- package/models/CampaignHistory.js +33 -33
- package/models/CampaignTag.js +46 -46
- package/models/CampaignTagAssignment.js +48 -48
- package/models/CanonicalInsights.js +68 -68
- package/models/Channel.js +55 -55
- package/models/Domain.js +49 -44
- package/models/DynamicFeed.js +218 -218
- package/models/ExplorAdsChannel.js +61 -61
- package/models/FacebookRetryQueue.js +163 -163
- package/models/Feed.js +33 -33
- package/models/FeedArticleConfiguration.js +80 -80
- package/models/FrontStoryChannel.js +59 -59
- package/models/FrontStoryChannelV2.js +60 -60
- package/models/GenericFlowRequest.js +114 -114
- package/models/MidoWebChannel.js +47 -47
- package/models/MineBrandBlocklist.js +56 -56
- package/models/MineBrandConfig.js +26 -26
- package/models/MineChannel.js +47 -47
- package/models/MineRedirectDomain.js +42 -42
- package/models/MineWebhookEvent.js +53 -53
- package/models/Pages.js +117 -117
- package/models/PipelineExecution.js +59 -59
- package/models/PolicyDogsCreativeCache.js +50 -50
- package/models/PolicyDogsImageCache.js +30 -30
- package/models/Presets.js +40 -40
- package/models/PublicApiBatch.js +155 -155
- package/models/PublicApiBatchItem.js +166 -166
- package/models/PublicApiIdempotencyCache.js +135 -135
- package/models/RSOCFeedCampaign.js +387 -387
- package/models/RSOCFeedConfig.js +46 -46
- package/models/RSOCRedirectWsCode.js +22 -22
- package/models/RsocKeywordPerformance.js +110 -110
- package/models/RuleAction.js +90 -90
- package/models/RuleCondition.js +137 -137
- package/models/RuleExecution.js +107 -107
- package/models/RulesValues.js +56 -56
- package/models/SingularChannel.js +31 -31
- package/models/SnapchatAd.js +69 -69
- package/models/SnapchatAdSquad.js +92 -92
- package/models/SnapchatCampaign.js +69 -69
- package/models/SnapchatChannel.js +31 -31
- package/models/SnapchatPublicProfiles.js +67 -67
- package/models/SupportedLocale.js +23 -23
- package/models/SyncHistory.js +249 -249
- package/models/TTQChannel.js +42 -42
- package/models/Team.js +33 -43
- package/models/TemplateMetadata.js +260 -260
- 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/TikTokAd.js +71 -71
- package/models/TikTokAdGroup.js +82 -82
- package/models/TikTokCampaign.js +71 -71
- package/models/TiktokChannel.js +31 -31
- package/models/TiktokIdentities.js +65 -65
- package/models/TokenRotationState.js +121 -121
- package/models/TonicRSOCKeywordPerformance.js +122 -122
- package/models/Users.js +204 -204
- package/models/Vertical.js +25 -25
- package/models/newFiles.js +137 -137
- package/package.json +21 -19
- package/run.sh +214 -214
- package/services/sequelizeService.js +110 -110
- package/tarzo-skalio-integration-docs.md +691 -691
|
@@ -1,340 +1,340 @@
|
|
|
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
|
-
platform_code: {
|
|
118
|
-
type: DataTypes.ENUM("fb", "tt", "snp"),
|
|
119
|
-
allowNull: false,
|
|
120
|
-
defaultValue: "fb",
|
|
121
|
-
comment:
|
|
122
|
-
"Canonical ad platform identifier: fb=Facebook, tt=TikTok, snp=Snapchat",
|
|
123
|
-
},
|
|
124
|
-
bid_strategy: {
|
|
125
|
-
type: DataTypes.STRING(100),
|
|
126
|
-
allowNull: true,
|
|
127
|
-
comment: "Bid strategy",
|
|
128
|
-
},
|
|
129
|
-
daily_budget: {
|
|
130
|
-
type: DataTypes.DECIMAL(10, 2),
|
|
131
|
-
allowNull: true,
|
|
132
|
-
comment: "Daily budget amount",
|
|
133
|
-
},
|
|
134
|
-
bid_amount: {
|
|
135
|
-
type: DataTypes.DECIMAL(10, 2),
|
|
136
|
-
allowNull: true,
|
|
137
|
-
comment: "Bid amount",
|
|
138
|
-
},
|
|
139
|
-
language: {
|
|
140
|
-
type: DataTypes.STRING(50),
|
|
141
|
-
allowNull: true,
|
|
142
|
-
comment: "Campaign language",
|
|
143
|
-
},
|
|
144
|
-
domain: {
|
|
145
|
-
type: DataTypes.STRING(255),
|
|
146
|
-
allowNull: true,
|
|
147
|
-
comment: "Campaign domain",
|
|
148
|
-
},
|
|
149
|
-
page_id: {
|
|
150
|
-
type: DataTypes.UUID,
|
|
151
|
-
allowNull: true,
|
|
152
|
-
comment: "Facebook Page ID (UUID from Pages table)",
|
|
153
|
-
},
|
|
154
|
-
page_code: {
|
|
155
|
-
type: DataTypes.STRING(100),
|
|
156
|
-
allowNull: true,
|
|
157
|
-
comment: "Page code (unique identifier from Pages table)",
|
|
158
|
-
},
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
tableName: "CampaignCreationLogs",
|
|
162
|
-
timestamps: true,
|
|
163
|
-
indexes: [
|
|
164
|
-
// CRITICAL: Main performance index for your DISTINCT ON query
|
|
165
|
-
{
|
|
166
|
-
name: "idx_campaign_logs_process_created_desc",
|
|
167
|
-
fields: ["process_id", { name: "createdAt", order: "DESC" }],
|
|
168
|
-
},
|
|
169
|
-
// JSON search optimization for account ID filtering
|
|
170
|
-
{
|
|
171
|
-
name: "idx_campaign_logs_details_gin",
|
|
172
|
-
fields: ["details"],
|
|
173
|
-
using: "gin",
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
name: "idx_campaign_logs_vertical",
|
|
177
|
-
fields: ["vertical"],
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
name: "idx_campaign_logs_feed_provider",
|
|
181
|
-
fields: ["feed_provider"],
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
name: "idx_campaign_logs_media_buyer",
|
|
185
|
-
fields: ["media_buyer"],
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
name: "idx_campaign_logs_account_id",
|
|
189
|
-
fields: ["account_id"],
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
name: "idx_campaign_logs_campaign_name",
|
|
193
|
-
fields: ["campaign_name"],
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
name: "idx_campaign_logs_assignee",
|
|
197
|
-
fields: ["assignee"],
|
|
198
|
-
},
|
|
199
|
-
{
|
|
200
|
-
name: "idx_campaign_logs_keywords",
|
|
201
|
-
fields: ["keywords"],
|
|
202
|
-
using: "gin",
|
|
203
|
-
},
|
|
204
|
-
{
|
|
205
|
-
name: "idx_campaign_logs_countries",
|
|
206
|
-
fields: ["countries"],
|
|
207
|
-
using: "gin",
|
|
208
|
-
},
|
|
209
|
-
// Composite index for status + country filters
|
|
210
|
-
{
|
|
211
|
-
name: "idx_campaign_logs_status_country",
|
|
212
|
-
fields: ["status", "country"],
|
|
213
|
-
},
|
|
214
|
-
{
|
|
215
|
-
name: "idx_campaign_logs_vertical_status",
|
|
216
|
-
fields: ["vertical", "status"],
|
|
217
|
-
},
|
|
218
|
-
{
|
|
219
|
-
name: "idx_campaign_logs_feed_provider_status",
|
|
220
|
-
fields: ["feed_provider", "status"],
|
|
221
|
-
},
|
|
222
|
-
{
|
|
223
|
-
name: "idx_campaign_logs_media_buyer_status",
|
|
224
|
-
fields: ["media_buyer", "status"],
|
|
225
|
-
},
|
|
226
|
-
{
|
|
227
|
-
name: "idx_campaign_logs_account_id_status",
|
|
228
|
-
fields: ["account_id", "status"],
|
|
229
|
-
},
|
|
230
|
-
{
|
|
231
|
-
name: "idx_campaign_logs_vertical_feed_provider",
|
|
232
|
-
fields: ["vertical", "feed_provider"],
|
|
233
|
-
},
|
|
234
|
-
{
|
|
235
|
-
name: "idx_campaign_logs_media_buyer_vertical",
|
|
236
|
-
fields: ["media_buyer", "vertical"],
|
|
237
|
-
},
|
|
238
|
-
{
|
|
239
|
-
name: "idx_campaign_logs_process_status_created",
|
|
240
|
-
fields: ["process_id", "status", "createdAt"],
|
|
241
|
-
},
|
|
242
|
-
{
|
|
243
|
-
name: "idx_campaign_logs_created_at_desc",
|
|
244
|
-
fields: [{ name: "createdAt", order: "DESC" }],
|
|
245
|
-
comment: "Critical for last day filtering and sorting by date",
|
|
246
|
-
},
|
|
247
|
-
{
|
|
248
|
-
name: "idx_campaign_logs_status_created_at",
|
|
249
|
-
fields: ["status", { name: "createdAt", order: "DESC" }],
|
|
250
|
-
comment: "Optimized for filtering by status within date ranges",
|
|
251
|
-
},
|
|
252
|
-
{
|
|
253
|
-
name: "idx_campaign_logs_process_created_at_desc",
|
|
254
|
-
fields: ["process_id", { name: "createdAt", order: "DESC" }],
|
|
255
|
-
comment: "Optimized for DISTINCT ON queries with date ordering",
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
name: "idx_campaign_logs_account_process",
|
|
259
|
-
fields: ["account_id", "process_id"],
|
|
260
|
-
comment: "For process-level account filtering v2",
|
|
261
|
-
},
|
|
262
|
-
{
|
|
263
|
-
name: "idx_campaign_logs_page_id",
|
|
264
|
-
fields: ["page_id"],
|
|
265
|
-
comment: "For page filtering",
|
|
266
|
-
},
|
|
267
|
-
{
|
|
268
|
-
name: "idx_campaign_logs_page_code",
|
|
269
|
-
fields: ["page_code"],
|
|
270
|
-
comment: "For page code filtering",
|
|
271
|
-
},
|
|
272
|
-
{
|
|
273
|
-
name: "idx_campaign_logs_platform_code",
|
|
274
|
-
fields: ["platform_code"],
|
|
275
|
-
comment: "For canonical platform filtering",
|
|
276
|
-
},
|
|
277
|
-
{
|
|
278
|
-
fields: ["process_id"],
|
|
279
|
-
},
|
|
280
|
-
{
|
|
281
|
-
fields: ["status"],
|
|
282
|
-
},
|
|
283
|
-
{
|
|
284
|
-
fields: ["country"],
|
|
285
|
-
},
|
|
286
|
-
{
|
|
287
|
-
fields: ["feed_campaign_id"],
|
|
288
|
-
},
|
|
289
|
-
{
|
|
290
|
-
fields: ["facebook_campaign_id"],
|
|
291
|
-
},
|
|
292
|
-
{
|
|
293
|
-
fields: ["createdAt"],
|
|
294
|
-
},
|
|
295
|
-
// Partial index mirroring the V2 side (idx_v2_awaiting_by_feed_campaign).
|
|
296
|
-
// The hourly Tarzo reconciler runs the SAME awaiting-materialization
|
|
297
|
-
// WHERE clause against both V1 and V2 (dual-write parity). Without this
|
|
298
|
-
// index the V1 UPDATE seq-scans 15.8M rows / 11GB and hits the 60s
|
|
299
|
-
// statement_timeout (verified in prod 2026-07-19: 207s EXPLAIN).
|
|
300
|
-
//
|
|
301
|
-
// Composite (feed_campaign_id, createdAt DESC) covers both:
|
|
302
|
-
// - step 2/5 join key (rfc.AGRS_CID = l.feed_campaign_id)
|
|
303
|
-
// - step 3/5 stale-age filter (l.createdAt < now() - 6h)
|
|
304
|
-
//
|
|
305
|
-
// Equality predicate — LIKE would be ignored by the planner (proven
|
|
306
|
-
// 2026-07-19). Self-pruning: rows drop out on COMPLETED/FAILED flip.
|
|
307
|
-
{
|
|
308
|
-
name: "idx_v1_awaiting_by_feed_campaign",
|
|
309
|
-
fields: ["feed_campaign_id", { name: "createdAt", order: "DESC" }],
|
|
310
|
-
where: sequelize.literal(
|
|
311
|
-
`status = 'IN_PROGRESS' AND (details->>'ai_stage') = 'tarzo_awaiting_materialization'`
|
|
312
|
-
),
|
|
313
|
-
},
|
|
314
|
-
],
|
|
315
|
-
}
|
|
316
|
-
);
|
|
317
|
-
|
|
318
|
-
CampaignCreationLog.associate = (models) => {
|
|
319
|
-
// Add associations if needed
|
|
320
|
-
if (models.CodefuelCampaign) {
|
|
321
|
-
CampaignCreationLog.belongsTo(models.CodefuelCampaign, {
|
|
322
|
-
foreignKey: "feed_campaign_id",
|
|
323
|
-
targetKey: "AGRSCID",
|
|
324
|
-
as: "FeedCampaign",
|
|
325
|
-
constraints: false,
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
if (models.Pages) {
|
|
330
|
-
CampaignCreationLog.belongsTo(models.Pages, {
|
|
331
|
-
foreignKey: "page_code",
|
|
332
|
-
targetKey: "code",
|
|
333
|
-
as: "Page",
|
|
334
|
-
constraints: false,
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
return CampaignCreationLog;
|
|
340
|
-
};
|
|
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
|
+
platform_code: {
|
|
118
|
+
type: DataTypes.ENUM("fb", "tt", "snp"),
|
|
119
|
+
allowNull: false,
|
|
120
|
+
defaultValue: "fb",
|
|
121
|
+
comment:
|
|
122
|
+
"Canonical ad platform identifier: fb=Facebook, tt=TikTok, snp=Snapchat",
|
|
123
|
+
},
|
|
124
|
+
bid_strategy: {
|
|
125
|
+
type: DataTypes.STRING(100),
|
|
126
|
+
allowNull: true,
|
|
127
|
+
comment: "Bid strategy",
|
|
128
|
+
},
|
|
129
|
+
daily_budget: {
|
|
130
|
+
type: DataTypes.DECIMAL(10, 2),
|
|
131
|
+
allowNull: true,
|
|
132
|
+
comment: "Daily budget amount",
|
|
133
|
+
},
|
|
134
|
+
bid_amount: {
|
|
135
|
+
type: DataTypes.DECIMAL(10, 2),
|
|
136
|
+
allowNull: true,
|
|
137
|
+
comment: "Bid amount",
|
|
138
|
+
},
|
|
139
|
+
language: {
|
|
140
|
+
type: DataTypes.STRING(50),
|
|
141
|
+
allowNull: true,
|
|
142
|
+
comment: "Campaign language",
|
|
143
|
+
},
|
|
144
|
+
domain: {
|
|
145
|
+
type: DataTypes.STRING(255),
|
|
146
|
+
allowNull: true,
|
|
147
|
+
comment: "Campaign domain",
|
|
148
|
+
},
|
|
149
|
+
page_id: {
|
|
150
|
+
type: DataTypes.UUID,
|
|
151
|
+
allowNull: true,
|
|
152
|
+
comment: "Facebook Page ID (UUID from Pages table)",
|
|
153
|
+
},
|
|
154
|
+
page_code: {
|
|
155
|
+
type: DataTypes.STRING(100),
|
|
156
|
+
allowNull: true,
|
|
157
|
+
comment: "Page code (unique identifier from Pages table)",
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
tableName: "CampaignCreationLogs",
|
|
162
|
+
timestamps: true,
|
|
163
|
+
indexes: [
|
|
164
|
+
// CRITICAL: Main performance index for your DISTINCT ON query
|
|
165
|
+
{
|
|
166
|
+
name: "idx_campaign_logs_process_created_desc",
|
|
167
|
+
fields: ["process_id", { name: "createdAt", order: "DESC" }],
|
|
168
|
+
},
|
|
169
|
+
// JSON search optimization for account ID filtering
|
|
170
|
+
{
|
|
171
|
+
name: "idx_campaign_logs_details_gin",
|
|
172
|
+
fields: ["details"],
|
|
173
|
+
using: "gin",
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
name: "idx_campaign_logs_vertical",
|
|
177
|
+
fields: ["vertical"],
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
name: "idx_campaign_logs_feed_provider",
|
|
181
|
+
fields: ["feed_provider"],
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
name: "idx_campaign_logs_media_buyer",
|
|
185
|
+
fields: ["media_buyer"],
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
name: "idx_campaign_logs_account_id",
|
|
189
|
+
fields: ["account_id"],
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
name: "idx_campaign_logs_campaign_name",
|
|
193
|
+
fields: ["campaign_name"],
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
name: "idx_campaign_logs_assignee",
|
|
197
|
+
fields: ["assignee"],
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
name: "idx_campaign_logs_keywords",
|
|
201
|
+
fields: ["keywords"],
|
|
202
|
+
using: "gin",
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
name: "idx_campaign_logs_countries",
|
|
206
|
+
fields: ["countries"],
|
|
207
|
+
using: "gin",
|
|
208
|
+
},
|
|
209
|
+
// Composite index for status + country filters
|
|
210
|
+
{
|
|
211
|
+
name: "idx_campaign_logs_status_country",
|
|
212
|
+
fields: ["status", "country"],
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
name: "idx_campaign_logs_vertical_status",
|
|
216
|
+
fields: ["vertical", "status"],
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
name: "idx_campaign_logs_feed_provider_status",
|
|
220
|
+
fields: ["feed_provider", "status"],
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
name: "idx_campaign_logs_media_buyer_status",
|
|
224
|
+
fields: ["media_buyer", "status"],
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
name: "idx_campaign_logs_account_id_status",
|
|
228
|
+
fields: ["account_id", "status"],
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
name: "idx_campaign_logs_vertical_feed_provider",
|
|
232
|
+
fields: ["vertical", "feed_provider"],
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
name: "idx_campaign_logs_media_buyer_vertical",
|
|
236
|
+
fields: ["media_buyer", "vertical"],
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
name: "idx_campaign_logs_process_status_created",
|
|
240
|
+
fields: ["process_id", "status", "createdAt"],
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
name: "idx_campaign_logs_created_at_desc",
|
|
244
|
+
fields: [{ name: "createdAt", order: "DESC" }],
|
|
245
|
+
comment: "Critical for last day filtering and sorting by date",
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
name: "idx_campaign_logs_status_created_at",
|
|
249
|
+
fields: ["status", { name: "createdAt", order: "DESC" }],
|
|
250
|
+
comment: "Optimized for filtering by status within date ranges",
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
name: "idx_campaign_logs_process_created_at_desc",
|
|
254
|
+
fields: ["process_id", { name: "createdAt", order: "DESC" }],
|
|
255
|
+
comment: "Optimized for DISTINCT ON queries with date ordering",
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
name: "idx_campaign_logs_account_process",
|
|
259
|
+
fields: ["account_id", "process_id"],
|
|
260
|
+
comment: "For process-level account filtering v2",
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
name: "idx_campaign_logs_page_id",
|
|
264
|
+
fields: ["page_id"],
|
|
265
|
+
comment: "For page filtering",
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
name: "idx_campaign_logs_page_code",
|
|
269
|
+
fields: ["page_code"],
|
|
270
|
+
comment: "For page code filtering",
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
name: "idx_campaign_logs_platform_code",
|
|
274
|
+
fields: ["platform_code"],
|
|
275
|
+
comment: "For canonical platform filtering",
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
fields: ["process_id"],
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
fields: ["status"],
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
fields: ["country"],
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
fields: ["feed_campaign_id"],
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
fields: ["facebook_campaign_id"],
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
fields: ["createdAt"],
|
|
294
|
+
},
|
|
295
|
+
// Partial index mirroring the V2 side (idx_v2_awaiting_by_feed_campaign).
|
|
296
|
+
// The hourly Tarzo reconciler runs the SAME awaiting-materialization
|
|
297
|
+
// WHERE clause against both V1 and V2 (dual-write parity). Without this
|
|
298
|
+
// index the V1 UPDATE seq-scans 15.8M rows / 11GB and hits the 60s
|
|
299
|
+
// statement_timeout (verified in prod 2026-07-19: 207s EXPLAIN).
|
|
300
|
+
//
|
|
301
|
+
// Composite (feed_campaign_id, createdAt DESC) covers both:
|
|
302
|
+
// - step 2/5 join key (rfc.AGRS_CID = l.feed_campaign_id)
|
|
303
|
+
// - step 3/5 stale-age filter (l.createdAt < now() - 6h)
|
|
304
|
+
//
|
|
305
|
+
// Equality predicate — LIKE would be ignored by the planner (proven
|
|
306
|
+
// 2026-07-19). Self-pruning: rows drop out on COMPLETED/FAILED flip.
|
|
307
|
+
{
|
|
308
|
+
name: "idx_v1_awaiting_by_feed_campaign",
|
|
309
|
+
fields: ["feed_campaign_id", { name: "createdAt", order: "DESC" }],
|
|
310
|
+
where: sequelize.literal(
|
|
311
|
+
`status = 'IN_PROGRESS' AND (details->>'ai_stage') = 'tarzo_awaiting_materialization'`
|
|
312
|
+
),
|
|
313
|
+
},
|
|
314
|
+
],
|
|
315
|
+
}
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
CampaignCreationLog.associate = (models) => {
|
|
319
|
+
// Add associations if needed
|
|
320
|
+
if (models.CodefuelCampaign) {
|
|
321
|
+
CampaignCreationLog.belongsTo(models.CodefuelCampaign, {
|
|
322
|
+
foreignKey: "feed_campaign_id",
|
|
323
|
+
targetKey: "AGRSCID",
|
|
324
|
+
as: "FeedCampaign",
|
|
325
|
+
constraints: false,
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (models.Pages) {
|
|
330
|
+
CampaignCreationLog.belongsTo(models.Pages, {
|
|
331
|
+
foreignKey: "page_code",
|
|
332
|
+
targetKey: "code",
|
|
333
|
+
as: "Page",
|
|
334
|
+
constraints: false,
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
return CampaignCreationLog;
|
|
340
|
+
};
|