agrs-sequelize-sdk 1.4.52 → 1.4.53

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 (116) hide show
  1. package/migrations/2026-05-17-PIXELS-FOLLOWUP.md +85 -85
  2. package/migrations/2026-05-17-add-platform-to-ad.js +19 -19
  3. package/migrations/2026-05-17-add-platform-to-adaccount.js +19 -19
  4. package/migrations/2026-05-17-add-platform-to-adperformance.js +19 -19
  5. package/migrations/2026-05-17-add-platform-to-adset.js +19 -19
  6. package/migrations/2026-05-17-add-platform-to-adsetperformance.js +19 -19
  7. package/migrations/2026-05-17-add-platform-to-aiarticleretryqueue.js +19 -19
  8. package/migrations/2026-05-17-add-platform-to-aicampaignqueue.js +19 -19
  9. package/migrations/2026-05-17-add-platform-to-article.js +19 -19
  10. package/migrations/2026-05-17-add-platform-to-campaign.js +19 -19
  11. package/migrations/2026-05-17-add-platform-to-codefuelcampaign.js +19 -19
  12. package/migrations/2026-05-17-add-platform-to-dynamicfeed.js +19 -19
  13. package/migrations/2026-05-17-add-platform-to-facebookretryqueue.js +19 -19
  14. package/migrations/2026-05-17-add-platform-to-pages.js +19 -19
  15. package/migrations/2026-05-17-add-platform-to-presets.js +19 -19
  16. package/migrations/2026-05-18-add-group-id-to-ai-campaign-queue.js +18 -18
  17. package/migrations/2026-05-18-add-platform-code-to-creation-logs.js +65 -65
  18. package/migrations/2026-05-18-add-platform-code-to-pixels.js +55 -55
  19. package/migrations/2026-05-18-add-platform-code-to-rsoc-feed-campaigns.js +55 -55
  20. package/migrations/2026-05-18-add-platform-date-index-to-adperformance.js +16 -16
  21. package/migrations/2026-05-18-add-platform-date-index-to-adsetperformance.js +16 -16
  22. package/migrations/2026-05-18-add-review-status-to-ad.js +36 -36
  23. package/migrations/2026-05-18-create-canonical-insights.js +84 -84
  24. package/migrations/2026-05-18-create-snapchat-public-profiles.js +68 -68
  25. package/migrations/2026-05-18-create-tiktok-identities.js +71 -71
  26. package/migrations/2026-05-18-create-tiktok-snapchat-campaigns.js +143 -143
  27. package/migrations/2026-05-18-create-tt-snp-adset-ad-tables.js +309 -309
  28. package/migrations/RUN_ME_MANUALLY_2026-05-17.sql +99 -99
  29. package/migrations/add-requested-from-dashboard-to-articles.js +17 -17
  30. package/migrations/change-adset-name-to-text.js +79 -79
  31. package/models/AICampaignQueue.js +152 -152
  32. package/models/AIGenerationLog.js +85 -85
  33. package/models/AIGenerationRequest.js +212 -212
  34. package/models/AdAccountValues.js +25 -25
  35. package/models/AdHistory.js +30 -30
  36. package/models/AdPerformance.js +104 -104
  37. package/models/AdSet.js +295 -295
  38. package/models/AdSetHistory.js +30 -30
  39. package/models/AdsetPerformance.js +137 -137
  40. package/models/AiArticleRetryQueue.js +157 -157
  41. package/models/AiCreationRetryQueue.js +134 -134
  42. package/models/ApiAuditLog.js +127 -127
  43. package/models/ApiToken.js +67 -67
  44. package/models/Article.js +222 -222
  45. package/models/AutomationRule.js +179 -179
  46. package/models/BannerTemplate.js +129 -129
  47. package/models/Buyers.js +25 -25
  48. package/models/Campaign.js +168 -163
  49. package/models/CampaignActionHistory.js +101 -101
  50. package/models/CampaignCreationLog.js +340 -340
  51. package/models/CampaignCreationLogV2.js +392 -392
  52. package/models/CampaignHistory.js +33 -33
  53. package/models/CampaignTag.js +46 -0
  54. package/models/CampaignTagAssignment.js +48 -0
  55. package/models/CanonicalInsights.js +68 -68
  56. package/models/Channel.js +55 -55
  57. package/models/Domain.js +44 -44
  58. package/models/DynamicFeed.js +218 -218
  59. package/models/ExplorAdsChannel.js +61 -61
  60. package/models/FacebookRetryQueue.js +163 -163
  61. package/models/Feed.js +33 -33
  62. package/models/FeedArticleConfiguration.js +80 -80
  63. package/models/FrontStoryChannel.js +59 -59
  64. package/models/FrontStoryChannelV2.js +60 -60
  65. package/models/GenericFlowRequest.js +114 -114
  66. package/models/MidoWebChannel.js +47 -47
  67. package/models/MineBrandBlocklist.js +40 -40
  68. package/models/MineChannel.js +42 -42
  69. package/models/MineRedirectDomain.js +36 -36
  70. package/models/MineWebhookEvent.js +53 -53
  71. package/models/Pages.js +117 -117
  72. package/models/PipelineExecution.js +59 -59
  73. package/models/PolicyDogsCreativeCache.js +50 -50
  74. package/models/PolicyDogsImageCache.js +30 -30
  75. package/models/Presets.js +40 -40
  76. package/models/PublicApiBatch.js +155 -155
  77. package/models/PublicApiBatchItem.js +166 -166
  78. package/models/PublicApiIdempotencyCache.js +135 -135
  79. package/models/RSOCFeedCampaign.js +387 -387
  80. package/models/RsocKeywordPerformance.js +110 -110
  81. package/models/RuleAction.js +90 -90
  82. package/models/RuleCondition.js +137 -137
  83. package/models/RuleExecution.js +107 -107
  84. package/models/RulesValues.js +56 -56
  85. package/models/SingularChannel.js +31 -31
  86. package/models/SnapchatAd.js +69 -69
  87. package/models/SnapchatAdSquad.js +92 -92
  88. package/models/SnapchatCampaign.js +69 -69
  89. package/models/SnapchatChannel.js +31 -31
  90. package/models/SnapchatPublicProfiles.js +67 -67
  91. package/models/SupportedLocale.js +23 -23
  92. package/models/SyncHistory.js +249 -249
  93. package/models/TTQChannel.js +42 -42
  94. package/models/TemplateMetadata.js +260 -260
  95. package/models/Tier2_AdAccounts.js +110 -110
  96. package/models/Tier2_Assets.js +70 -70
  97. package/models/Tier2_BusinessManagers.js +105 -105
  98. package/models/Tier2_CreditLines.js +99 -99
  99. package/models/Tier2_Pages.js +91 -91
  100. package/models/Tier2_Pixels.js +82 -82
  101. package/models/Tier2_Tokens.js +64 -64
  102. package/models/Tier2_UserAdAccounts.js +83 -83
  103. package/models/TikTokAd.js +71 -71
  104. package/models/TikTokAdGroup.js +82 -82
  105. package/models/TikTokCampaign.js +71 -71
  106. package/models/TiktokChannel.js +31 -31
  107. package/models/TiktokIdentities.js +65 -65
  108. package/models/TokenRotationState.js +121 -121
  109. package/models/TonicRSOCKeywordPerformance.js +122 -122
  110. package/models/Users.js +190 -185
  111. package/models/Vertical.js +25 -25
  112. package/models/newFiles.js +137 -137
  113. package/package.json +21 -19
  114. package/run.sh +214 -214
  115. package/services/sequelizeService.js +110 -110
  116. package/tarzo-skalio-integration-docs.md +691 -691
@@ -1,111 +1,111 @@
1
- module.exports = (sequelize, DataTypes) => {
2
- const RsocKeywordPerformance = sequelize.define('RsocKeywordPerformance', {
3
- id: {
4
- type: DataTypes.INTEGER,
5
- primaryKey: true,
6
- autoIncrement: true,
7
- allowNull: false
8
- },
9
- ts: {
10
- type: DataTypes.DATE,
11
- allowNull: false,
12
- comment: 'Timestamp of the record'
13
- },
14
- channel_id: {
15
- type: DataTypes.STRING,
16
- allowNull: false,
17
- comment: 'Channel identifier'
18
- },
19
- style_id: {
20
- type: DataTypes.STRING,
21
- allowNull: true,
22
- comment: 'Style identifier'
23
- },
24
- country_code: {
25
- type: DataTypes.STRING(2),
26
- allowNull: true,
27
- comment: 'Country code (ISO 2-letter)'
28
- },
29
- custom_query: {
30
- type: DataTypes.TEXT,
31
- allowNull: true,
32
- comment: 'Custom search query'
33
- },
34
- query: {
35
- type: DataTypes.TEXT,
36
- allowNull: true,
37
- comment: 'Standard search query'
38
- },
39
- funnel_page_views: {
40
- type: DataTypes.INTEGER,
41
- allowNull: true,
42
- defaultValue: 0,
43
- comment: 'Number of funnel page views'
44
- },
45
- funnel_impressions: {
46
- type: DataTypes.INTEGER,
47
- allowNull: true,
48
- defaultValue: 0,
49
- comment: 'Number of funnel impressions'
50
- },
51
- funnel_clicks: {
52
- type: DataTypes.INTEGER,
53
- allowNull: true,
54
- defaultValue: 0,
55
- comment: 'Number of funnel clicks'
56
- },
57
- page_views: {
58
- type: DataTypes.INTEGER,
59
- allowNull: true,
60
- defaultValue: 0,
61
- comment: 'Number of page views'
62
- },
63
- impressions: {
64
- type: DataTypes.INTEGER,
65
- allowNull: true,
66
- defaultValue: 0,
67
- comment: 'Number of impressions'
68
- },
69
- clicks: {
70
- type: DataTypes.INTEGER,
71
- allowNull: true,
72
- defaultValue: 0,
73
- comment: 'Number of clicks'
74
- },
75
- agrs_cid: {
76
- type: DataTypes.STRING,
77
- allowNull: true,
78
- comment: 'AGRS campaign identifier linking to campaign data'
79
- }
80
- }, {
81
- tableName: 'rsoc_keyword_performance',
82
- timestamps: true, // Adds createdAt and updatedAt columns
83
- indexes: [
84
- {
85
- fields: ['channel_id', 'ts'],
86
- name: 'idx_rsoc_keyword_channel_time'
87
- },
88
- {
89
- fields: ['style_id'],
90
- name: 'idx_rsoc_keyword_style'
91
- },
92
- {
93
- fields: ['country_code'],
94
- name: 'idx_rsoc_keyword_country'
95
- },
96
- {
97
- fields: ['agrs_cid'],
98
- name: 'idx_rsoc_keyword_agrs_cid'
99
- }
100
- ]
101
- });
102
-
103
- // Define associations if needed
104
- RsocKeywordPerformance.associate = (models) => {
105
- // Add associations here if your table needs to reference other tables
106
- // For example:
107
- // RsocKeywordPerformance.belongsTo(models.Channel, { foreignKey: 'channel_id' });
108
- };
109
-
110
- return RsocKeywordPerformance;
1
+ module.exports = (sequelize, DataTypes) => {
2
+ const RsocKeywordPerformance = sequelize.define('RsocKeywordPerformance', {
3
+ id: {
4
+ type: DataTypes.INTEGER,
5
+ primaryKey: true,
6
+ autoIncrement: true,
7
+ allowNull: false
8
+ },
9
+ ts: {
10
+ type: DataTypes.DATE,
11
+ allowNull: false,
12
+ comment: 'Timestamp of the record'
13
+ },
14
+ channel_id: {
15
+ type: DataTypes.STRING,
16
+ allowNull: false,
17
+ comment: 'Channel identifier'
18
+ },
19
+ style_id: {
20
+ type: DataTypes.STRING,
21
+ allowNull: true,
22
+ comment: 'Style identifier'
23
+ },
24
+ country_code: {
25
+ type: DataTypes.STRING(2),
26
+ allowNull: true,
27
+ comment: 'Country code (ISO 2-letter)'
28
+ },
29
+ custom_query: {
30
+ type: DataTypes.TEXT,
31
+ allowNull: true,
32
+ comment: 'Custom search query'
33
+ },
34
+ query: {
35
+ type: DataTypes.TEXT,
36
+ allowNull: true,
37
+ comment: 'Standard search query'
38
+ },
39
+ funnel_page_views: {
40
+ type: DataTypes.INTEGER,
41
+ allowNull: true,
42
+ defaultValue: 0,
43
+ comment: 'Number of funnel page views'
44
+ },
45
+ funnel_impressions: {
46
+ type: DataTypes.INTEGER,
47
+ allowNull: true,
48
+ defaultValue: 0,
49
+ comment: 'Number of funnel impressions'
50
+ },
51
+ funnel_clicks: {
52
+ type: DataTypes.INTEGER,
53
+ allowNull: true,
54
+ defaultValue: 0,
55
+ comment: 'Number of funnel clicks'
56
+ },
57
+ page_views: {
58
+ type: DataTypes.INTEGER,
59
+ allowNull: true,
60
+ defaultValue: 0,
61
+ comment: 'Number of page views'
62
+ },
63
+ impressions: {
64
+ type: DataTypes.INTEGER,
65
+ allowNull: true,
66
+ defaultValue: 0,
67
+ comment: 'Number of impressions'
68
+ },
69
+ clicks: {
70
+ type: DataTypes.INTEGER,
71
+ allowNull: true,
72
+ defaultValue: 0,
73
+ comment: 'Number of clicks'
74
+ },
75
+ agrs_cid: {
76
+ type: DataTypes.STRING,
77
+ allowNull: true,
78
+ comment: 'AGRS campaign identifier linking to campaign data'
79
+ }
80
+ }, {
81
+ tableName: 'rsoc_keyword_performance',
82
+ timestamps: true, // Adds createdAt and updatedAt columns
83
+ indexes: [
84
+ {
85
+ fields: ['channel_id', 'ts'],
86
+ name: 'idx_rsoc_keyword_channel_time'
87
+ },
88
+ {
89
+ fields: ['style_id'],
90
+ name: 'idx_rsoc_keyword_style'
91
+ },
92
+ {
93
+ fields: ['country_code'],
94
+ name: 'idx_rsoc_keyword_country'
95
+ },
96
+ {
97
+ fields: ['agrs_cid'],
98
+ name: 'idx_rsoc_keyword_agrs_cid'
99
+ }
100
+ ]
101
+ });
102
+
103
+ // Define associations if needed
104
+ RsocKeywordPerformance.associate = (models) => {
105
+ // Add associations here if your table needs to reference other tables
106
+ // For example:
107
+ // RsocKeywordPerformance.belongsTo(models.Channel, { foreignKey: 'channel_id' });
108
+ };
109
+
110
+ return RsocKeywordPerformance;
111
111
  };
@@ -1,90 +1,90 @@
1
- const { DataTypes } = require("sequelize");
2
-
3
- module.exports = (sequelize) => {
4
- const RuleAction = sequelize.define(
5
- "RuleAction",
6
- {
7
- id: {
8
- type: DataTypes.UUID,
9
- defaultValue: DataTypes.UUIDV4,
10
- primaryKey: true,
11
- },
12
- ruleId: {
13
- type: DataTypes.UUID,
14
- allowNull: false,
15
- references: {
16
- model: "AutomationRule",
17
- key: "id",
18
- },
19
- comment: "Reference to the parent rule",
20
- },
21
- actionType: {
22
- type: DataTypes.ENUM(
23
- "PAUSE",
24
- "ACTIVATE",
25
- "CHANGE_BUDGET",
26
- "CHANGE_BID",
27
- "CHANGE_BID_STRATEGY",
28
- "CUSTOM_ACTION"
29
- ),
30
- allowNull: false,
31
- comment: "Type of action to perform",
32
- },
33
- targetLevel: {
34
- type: DataTypes.ENUM("CAMPAIGN", "ADSET", "AD"),
35
- allowNull: false,
36
- comment: "Level at which the action operates",
37
- },
38
- value: {
39
- type: DataTypes.STRING(255),
40
- allowNull: true,
41
- comment: "Value for the action (budget amount, bid amount, etc.)",
42
- },
43
- valueType: {
44
- type: DataTypes.ENUM("STRING", "NUMBER", "ARRAY"),
45
- allowNull: true,
46
- defaultValue: "STRING",
47
- comment: "Type of the value field",
48
- },
49
- actionConfig: {
50
- type: DataTypes.JSONB,
51
- allowNull: true,
52
- comment:
53
- "Configuration for the action (budget amount, bid strategy, etc.)",
54
- },
55
- order: {
56
- type: DataTypes.INTEGER,
57
- allowNull: false,
58
- defaultValue: 0,
59
- comment: "Order of this action within the rule",
60
- },
61
- isActive: {
62
- type: DataTypes.BOOLEAN,
63
- defaultValue: true,
64
- allowNull: false,
65
- comment: "Whether this action is active",
66
- },
67
- delayMinutes: {
68
- type: DataTypes.INTEGER,
69
- allowNull: true,
70
- defaultValue: 0,
71
- comment: "Delay in minutes before executing this action",
72
- },
73
- },
74
- {
75
- tableName: "RuleActions",
76
- timestamps: true,
77
- // Remove indexes from model definition - they will be created by migration
78
- }
79
- );
80
-
81
- RuleAction.associate = (models) => {
82
- // An action belongs to a rule
83
- RuleAction.belongsTo(models.AutomationRule, {
84
- foreignKey: "ruleId",
85
- as: "rule",
86
- });
87
- };
88
-
89
- return RuleAction;
90
- };
1
+ const { DataTypes } = require("sequelize");
2
+
3
+ module.exports = (sequelize) => {
4
+ const RuleAction = sequelize.define(
5
+ "RuleAction",
6
+ {
7
+ id: {
8
+ type: DataTypes.UUID,
9
+ defaultValue: DataTypes.UUIDV4,
10
+ primaryKey: true,
11
+ },
12
+ ruleId: {
13
+ type: DataTypes.UUID,
14
+ allowNull: false,
15
+ references: {
16
+ model: "AutomationRule",
17
+ key: "id",
18
+ },
19
+ comment: "Reference to the parent rule",
20
+ },
21
+ actionType: {
22
+ type: DataTypes.ENUM(
23
+ "PAUSE",
24
+ "ACTIVATE",
25
+ "CHANGE_BUDGET",
26
+ "CHANGE_BID",
27
+ "CHANGE_BID_STRATEGY",
28
+ "CUSTOM_ACTION"
29
+ ),
30
+ allowNull: false,
31
+ comment: "Type of action to perform",
32
+ },
33
+ targetLevel: {
34
+ type: DataTypes.ENUM("CAMPAIGN", "ADSET", "AD"),
35
+ allowNull: false,
36
+ comment: "Level at which the action operates",
37
+ },
38
+ value: {
39
+ type: DataTypes.STRING(255),
40
+ allowNull: true,
41
+ comment: "Value for the action (budget amount, bid amount, etc.)",
42
+ },
43
+ valueType: {
44
+ type: DataTypes.ENUM("STRING", "NUMBER", "ARRAY"),
45
+ allowNull: true,
46
+ defaultValue: "STRING",
47
+ comment: "Type of the value field",
48
+ },
49
+ actionConfig: {
50
+ type: DataTypes.JSONB,
51
+ allowNull: true,
52
+ comment:
53
+ "Configuration for the action (budget amount, bid strategy, etc.)",
54
+ },
55
+ order: {
56
+ type: DataTypes.INTEGER,
57
+ allowNull: false,
58
+ defaultValue: 0,
59
+ comment: "Order of this action within the rule",
60
+ },
61
+ isActive: {
62
+ type: DataTypes.BOOLEAN,
63
+ defaultValue: true,
64
+ allowNull: false,
65
+ comment: "Whether this action is active",
66
+ },
67
+ delayMinutes: {
68
+ type: DataTypes.INTEGER,
69
+ allowNull: true,
70
+ defaultValue: 0,
71
+ comment: "Delay in minutes before executing this action",
72
+ },
73
+ },
74
+ {
75
+ tableName: "RuleActions",
76
+ timestamps: true,
77
+ // Remove indexes from model definition - they will be created by migration
78
+ }
79
+ );
80
+
81
+ RuleAction.associate = (models) => {
82
+ // An action belongs to a rule
83
+ RuleAction.belongsTo(models.AutomationRule, {
84
+ foreignKey: "ruleId",
85
+ as: "rule",
86
+ });
87
+ };
88
+
89
+ return RuleAction;
90
+ };
@@ -1,137 +1,137 @@
1
- const { DataTypes } = require("sequelize");
2
-
3
- module.exports = (sequelize) => {
4
- const RuleCondition = sequelize.define(
5
- "RuleCondition",
6
- {
7
- id: {
8
- type: DataTypes.UUID,
9
- defaultValue: DataTypes.UUIDV4,
10
- primaryKey: true,
11
- },
12
- ruleId: {
13
- type: DataTypes.UUID,
14
- allowNull: false,
15
- references: {
16
- model: "AutomationRule",
17
- key: "id",
18
- },
19
- comment: "Reference to the parent rule",
20
- },
21
- field: {
22
- type: DataTypes.STRING(100),
23
- allowNull: false,
24
- comment: "Field to evaluate (e.g., roi, ctr, campaign_name)",
25
- },
26
- type: {
27
- type: DataTypes.ENUM("DIMENSION", "METRIC"),
28
- allowNull: false,
29
- defaultValue: "DIMENSION",
30
- comment:
31
- "Type of field - DIMENSION for filtering, METRIC for calculations",
32
- },
33
- operator: {
34
- type: DataTypes.ENUM(
35
- "EQUALS",
36
- "NOT_EQUALS",
37
- "GREATER_THAN",
38
- "LESS_THAN",
39
- "GREATER_THAN_OR_EQUAL",
40
- "LESS_THAN_OR_EQUAL",
41
- "BETWEEN",
42
- "IN",
43
- "NOT_IN",
44
- "CONTAINS",
45
- "NOT_CONTAINS",
46
- "IS_NULL",
47
- "IS_NOT_NULL"
48
- ),
49
- allowNull: false,
50
- comment: "Comparison operator",
51
- },
52
- value: {
53
- type: DataTypes.JSONB,
54
- allowNull: true,
55
- comment:
56
- "Value(s) to compare against (can be array for BETWEEN, IN, etc.)",
57
- },
58
- valueType: {
59
- type: DataTypes.ENUM("STRING", "NUMBER", "ARRAY"),
60
- allowNull: true,
61
- defaultValue: "STRING",
62
- comment: "Type of the value field",
63
- },
64
- logicalOperator: {
65
- type: DataTypes.ENUM("AND", "OR"),
66
- allowNull: false,
67
- defaultValue: "AND",
68
- comment: "How this condition connects to the next one",
69
- },
70
- order: {
71
- type: DataTypes.INTEGER,
72
- allowNull: false,
73
- defaultValue: 0,
74
- comment: "Order of this condition within the rule",
75
- },
76
- isActive: {
77
- type: DataTypes.BOOLEAN,
78
- defaultValue: true,
79
- allowNull: false,
80
- comment: "Whether this condition is active",
81
- },
82
- groupId: {
83
- type: DataTypes.STRING(50),
84
- allowNull: true,
85
- comment: "ID to group conditions together (e.g., group1, group2)",
86
- },
87
- groupOperator: {
88
- type: DataTypes.ENUM("AND", "OR"),
89
- allowNull: false,
90
- defaultValue: "AND",
91
- comment: "Operator within the group (AND/OR)",
92
- },
93
- betweenGroupsOperator: {
94
- type: DataTypes.ENUM("AND", "OR"),
95
- allowNull: true,
96
- comment:
97
- "Operator between different groups (AND/OR) - only for first condition in group",
98
- },
99
- dateRangeType: {
100
- type: DataTypes.STRING(50),
101
- allowNull: true,
102
- comment:
103
- "Type of date range (last_7_days, yesterday, today, custom, etc.)",
104
- },
105
- dateRangeValue: {
106
- type: DataTypes.INTEGER,
107
- allowNull: true,
108
- comment: "Number of days for relative date ranges",
109
- },
110
- customStartDate: {
111
- type: DataTypes.DATE,
112
- allowNull: true,
113
- comment: "Custom start date if dateRangeType is custom",
114
- },
115
- customEndDate: {
116
- type: DataTypes.DATE,
117
- allowNull: true,
118
- comment: "Custom end date if dateRangeType is custom",
119
- },
120
- },
121
- {
122
- tableName: "RuleConditions",
123
- timestamps: true,
124
- // Remove indexes from model definition - they will be created by migration
125
- }
126
- );
127
-
128
- RuleCondition.associate = (models) => {
129
- // A condition belongs to a rule
130
- RuleCondition.belongsTo(models.AutomationRule, {
131
- foreignKey: "ruleId",
132
- as: "rule",
133
- });
134
- };
135
-
136
- return RuleCondition;
137
- };
1
+ const { DataTypes } = require("sequelize");
2
+
3
+ module.exports = (sequelize) => {
4
+ const RuleCondition = sequelize.define(
5
+ "RuleCondition",
6
+ {
7
+ id: {
8
+ type: DataTypes.UUID,
9
+ defaultValue: DataTypes.UUIDV4,
10
+ primaryKey: true,
11
+ },
12
+ ruleId: {
13
+ type: DataTypes.UUID,
14
+ allowNull: false,
15
+ references: {
16
+ model: "AutomationRule",
17
+ key: "id",
18
+ },
19
+ comment: "Reference to the parent rule",
20
+ },
21
+ field: {
22
+ type: DataTypes.STRING(100),
23
+ allowNull: false,
24
+ comment: "Field to evaluate (e.g., roi, ctr, campaign_name)",
25
+ },
26
+ type: {
27
+ type: DataTypes.ENUM("DIMENSION", "METRIC"),
28
+ allowNull: false,
29
+ defaultValue: "DIMENSION",
30
+ comment:
31
+ "Type of field - DIMENSION for filtering, METRIC for calculations",
32
+ },
33
+ operator: {
34
+ type: DataTypes.ENUM(
35
+ "EQUALS",
36
+ "NOT_EQUALS",
37
+ "GREATER_THAN",
38
+ "LESS_THAN",
39
+ "GREATER_THAN_OR_EQUAL",
40
+ "LESS_THAN_OR_EQUAL",
41
+ "BETWEEN",
42
+ "IN",
43
+ "NOT_IN",
44
+ "CONTAINS",
45
+ "NOT_CONTAINS",
46
+ "IS_NULL",
47
+ "IS_NOT_NULL"
48
+ ),
49
+ allowNull: false,
50
+ comment: "Comparison operator",
51
+ },
52
+ value: {
53
+ type: DataTypes.JSONB,
54
+ allowNull: true,
55
+ comment:
56
+ "Value(s) to compare against (can be array for BETWEEN, IN, etc.)",
57
+ },
58
+ valueType: {
59
+ type: DataTypes.ENUM("STRING", "NUMBER", "ARRAY"),
60
+ allowNull: true,
61
+ defaultValue: "STRING",
62
+ comment: "Type of the value field",
63
+ },
64
+ logicalOperator: {
65
+ type: DataTypes.ENUM("AND", "OR"),
66
+ allowNull: false,
67
+ defaultValue: "AND",
68
+ comment: "How this condition connects to the next one",
69
+ },
70
+ order: {
71
+ type: DataTypes.INTEGER,
72
+ allowNull: false,
73
+ defaultValue: 0,
74
+ comment: "Order of this condition within the rule",
75
+ },
76
+ isActive: {
77
+ type: DataTypes.BOOLEAN,
78
+ defaultValue: true,
79
+ allowNull: false,
80
+ comment: "Whether this condition is active",
81
+ },
82
+ groupId: {
83
+ type: DataTypes.STRING(50),
84
+ allowNull: true,
85
+ comment: "ID to group conditions together (e.g., group1, group2)",
86
+ },
87
+ groupOperator: {
88
+ type: DataTypes.ENUM("AND", "OR"),
89
+ allowNull: false,
90
+ defaultValue: "AND",
91
+ comment: "Operator within the group (AND/OR)",
92
+ },
93
+ betweenGroupsOperator: {
94
+ type: DataTypes.ENUM("AND", "OR"),
95
+ allowNull: true,
96
+ comment:
97
+ "Operator between different groups (AND/OR) - only for first condition in group",
98
+ },
99
+ dateRangeType: {
100
+ type: DataTypes.STRING(50),
101
+ allowNull: true,
102
+ comment:
103
+ "Type of date range (last_7_days, yesterday, today, custom, etc.)",
104
+ },
105
+ dateRangeValue: {
106
+ type: DataTypes.INTEGER,
107
+ allowNull: true,
108
+ comment: "Number of days for relative date ranges",
109
+ },
110
+ customStartDate: {
111
+ type: DataTypes.DATE,
112
+ allowNull: true,
113
+ comment: "Custom start date if dateRangeType is custom",
114
+ },
115
+ customEndDate: {
116
+ type: DataTypes.DATE,
117
+ allowNull: true,
118
+ comment: "Custom end date if dateRangeType is custom",
119
+ },
120
+ },
121
+ {
122
+ tableName: "RuleConditions",
123
+ timestamps: true,
124
+ // Remove indexes from model definition - they will be created by migration
125
+ }
126
+ );
127
+
128
+ RuleCondition.associate = (models) => {
129
+ // A condition belongs to a rule
130
+ RuleCondition.belongsTo(models.AutomationRule, {
131
+ foreignKey: "ruleId",
132
+ as: "rule",
133
+ });
134
+ };
135
+
136
+ return RuleCondition;
137
+ };