agrs-sequelize-sdk 1.2.68 → 1.2.69
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 +89 -89
- package/models/AdSet.js +289 -289
- package/models/AdSetHistory.js +30 -30
- package/models/AdsetPerformance.js +126 -126
- package/models/Article.js +170 -170
- package/models/Buyers.js +25 -25
- package/models/Campaign.js +145 -145
- package/models/CampaignCreationLog.js +280 -280
- package/models/CampaignHistory.js +33 -33
- package/models/Channel.js +55 -55
- package/models/Domain.js +25 -25
- package/models/DynamicFeed.js +89 -89
- package/models/ExplorAdsChannel.js +61 -61
- package/models/Feed.js +33 -33
- package/models/FrontStoryChannel.js +59 -59
- package/models/Pages.js +73 -73
- 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/Rule.js +133 -19
- package/models/RuleAction.js +92 -0
- package/models/RuleCondition.js +97 -0
- package/models/RuleExecution.js +120 -0
- package/models/RulesValues.js +56 -56
- package/models/SupportedLocale.js +23 -23
- package/models/SyncHistory.js +249 -249
- 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,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
|
};
|
package/models/Rule.js
CHANGED
|
@@ -1,39 +1,153 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
const { DataTypes } = require('sequelize');
|
|
2
|
+
|
|
3
|
+
module.exports = (sequelize) => {
|
|
4
|
+
const Rule = sequelize.define('Rule', {
|
|
5
|
+
id: {
|
|
6
|
+
type: DataTypes.UUID,
|
|
7
|
+
defaultValue: DataTypes.UUIDV4,
|
|
8
|
+
primaryKey: true,
|
|
9
|
+
},
|
|
10
|
+
name: {
|
|
11
|
+
type: DataTypes.STRING(255),
|
|
5
12
|
allowNull: false,
|
|
13
|
+
comment: 'Rule name for identification',
|
|
14
|
+
},
|
|
15
|
+
description: {
|
|
16
|
+
type: DataTypes.TEXT,
|
|
17
|
+
allowNull: true,
|
|
18
|
+
comment: 'Optional description of what this rule does',
|
|
6
19
|
},
|
|
7
|
-
|
|
8
|
-
type: DataTypes.
|
|
20
|
+
isActive: {
|
|
21
|
+
type: DataTypes.BOOLEAN,
|
|
22
|
+
defaultValue: true,
|
|
9
23
|
allowNull: false,
|
|
24
|
+
comment: 'Whether the rule is currently active',
|
|
10
25
|
},
|
|
11
|
-
|
|
12
|
-
type: DataTypes.
|
|
26
|
+
ruleType: {
|
|
27
|
+
type: DataTypes.ENUM(
|
|
28
|
+
'PAUSE',
|
|
29
|
+
'BUDGET',
|
|
30
|
+
'BID',
|
|
31
|
+
'STATUS',
|
|
32
|
+
'CUSTOM'
|
|
33
|
+
),
|
|
13
34
|
allowNull: false,
|
|
35
|
+
comment: 'Type of rule - determines the action category',
|
|
14
36
|
},
|
|
15
|
-
|
|
16
|
-
type: DataTypes.
|
|
17
|
-
|
|
37
|
+
targetLevel: {
|
|
38
|
+
type: DataTypes.ENUM(
|
|
39
|
+
'CAMPAIGN',
|
|
40
|
+
'ADSET',
|
|
41
|
+
'AD'
|
|
42
|
+
),
|
|
43
|
+
allowNull: false,
|
|
44
|
+
comment: 'Level at which the rule operates',
|
|
18
45
|
},
|
|
19
|
-
|
|
46
|
+
scheduleType: {
|
|
47
|
+
type: DataTypes.ENUM(
|
|
48
|
+
'INTERVAL',
|
|
49
|
+
'CRON',
|
|
50
|
+
'MANUAL'
|
|
51
|
+
),
|
|
52
|
+
allowNull: false,
|
|
53
|
+
defaultValue: 'MANUAL',
|
|
54
|
+
comment: 'How the rule is triggered',
|
|
55
|
+
},
|
|
56
|
+
scheduleConfig: {
|
|
20
57
|
type: DataTypes.JSONB,
|
|
21
58
|
allowNull: true,
|
|
59
|
+
comment: 'Schedule configuration (interval minutes, cron expression, etc.)',
|
|
22
60
|
},
|
|
23
|
-
|
|
24
|
-
type: DataTypes.
|
|
61
|
+
gcpJobName: {
|
|
62
|
+
type: DataTypes.STRING(255),
|
|
63
|
+
allowNull: true,
|
|
64
|
+
comment: 'GCP Cloud Scheduler job name for this rule',
|
|
65
|
+
},
|
|
66
|
+
lastExecuted: {
|
|
67
|
+
type: DataTypes.DATE,
|
|
68
|
+
allowNull: true,
|
|
69
|
+
comment: 'When the rule was last executed',
|
|
70
|
+
},
|
|
71
|
+
nextExecution: {
|
|
72
|
+
type: DataTypes.DATE,
|
|
73
|
+
allowNull: true,
|
|
74
|
+
comment: 'When the rule is scheduled to run next',
|
|
75
|
+
},
|
|
76
|
+
executionCount: {
|
|
77
|
+
type: DataTypes.INTEGER,
|
|
78
|
+
defaultValue: 0,
|
|
25
79
|
allowNull: false,
|
|
80
|
+
comment: 'Number of times this rule has been executed',
|
|
26
81
|
},
|
|
27
|
-
|
|
28
|
-
type: DataTypes.
|
|
82
|
+
successCount: {
|
|
83
|
+
type: DataTypes.INTEGER,
|
|
84
|
+
defaultValue: 0,
|
|
29
85
|
allowNull: false,
|
|
86
|
+
comment: 'Number of successful executions',
|
|
30
87
|
},
|
|
31
|
-
|
|
32
|
-
type: DataTypes.
|
|
88
|
+
failureCount: {
|
|
89
|
+
type: DataTypes.INTEGER,
|
|
90
|
+
defaultValue: 0,
|
|
33
91
|
allowNull: false,
|
|
34
|
-
|
|
92
|
+
comment: 'Number of failed executions',
|
|
35
93
|
},
|
|
94
|
+
createdBy: {
|
|
95
|
+
type: DataTypes.STRING(255),
|
|
96
|
+
allowNull: true,
|
|
97
|
+
comment: 'User who created this rule',
|
|
98
|
+
},
|
|
99
|
+
updatedBy: {
|
|
100
|
+
type: DataTypes.STRING(255),
|
|
101
|
+
allowNull: true,
|
|
102
|
+
comment: 'User who last updated this rule',
|
|
103
|
+
},
|
|
104
|
+
}, {
|
|
105
|
+
tableName: 'Rules',
|
|
106
|
+
timestamps: true,
|
|
107
|
+
indexes: [
|
|
108
|
+
{
|
|
109
|
+
fields: ['isActive'],
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
fields: ['ruleType'],
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
fields: ['targetLevel'],
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
fields: ['scheduleType'],
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
fields: ['nextExecution'],
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
fields: ['createdBy'],
|
|
125
|
+
},
|
|
126
|
+
],
|
|
36
127
|
});
|
|
37
128
|
|
|
129
|
+
Rule.associate = (models) => {
|
|
130
|
+
// A rule has many conditions
|
|
131
|
+
Rule.hasMany(models.RuleCondition, {
|
|
132
|
+
foreignKey: 'ruleId',
|
|
133
|
+
as: 'conditions',
|
|
134
|
+
onDelete: 'CASCADE',
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// A rule has many actions
|
|
138
|
+
Rule.hasMany(models.RuleAction, {
|
|
139
|
+
foreignKey: 'ruleId',
|
|
140
|
+
as: 'actions',
|
|
141
|
+
onDelete: 'CASCADE',
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// A rule has many execution logs
|
|
145
|
+
Rule.hasMany(models.RuleExecution, {
|
|
146
|
+
foreignKey: 'ruleId',
|
|
147
|
+
as: 'executions',
|
|
148
|
+
onDelete: 'CASCADE',
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
|
|
38
152
|
return Rule;
|
|
39
153
|
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
const { DataTypes } = require('sequelize');
|
|
2
|
+
|
|
3
|
+
module.exports = (sequelize) => {
|
|
4
|
+
const RuleAction = sequelize.define('RuleAction', {
|
|
5
|
+
id: {
|
|
6
|
+
type: DataTypes.UUID,
|
|
7
|
+
defaultValue: DataTypes.UUIDV4,
|
|
8
|
+
primaryKey: true,
|
|
9
|
+
},
|
|
10
|
+
ruleId: {
|
|
11
|
+
type: DataTypes.UUID,
|
|
12
|
+
allowNull: false,
|
|
13
|
+
references: {
|
|
14
|
+
model: 'Rules',
|
|
15
|
+
key: 'id',
|
|
16
|
+
},
|
|
17
|
+
comment: 'Reference to the parent rule',
|
|
18
|
+
},
|
|
19
|
+
actionType: {
|
|
20
|
+
type: DataTypes.ENUM(
|
|
21
|
+
// Campaign level actions
|
|
22
|
+
'PAUSE_CAMPAIGN',
|
|
23
|
+
'ACTIVATE_CAMPAIGN',
|
|
24
|
+
'CHANGE_CAMPAIGN_BUDGET',
|
|
25
|
+
'CHANGE_CAMPAIGN_BID_STRATEGY',
|
|
26
|
+
|
|
27
|
+
// AdSet level actions
|
|
28
|
+
'PAUSE_ADSET',
|
|
29
|
+
'ACTIVATE_ADSET',
|
|
30
|
+
'CHANGE_ADSET_BUDGET',
|
|
31
|
+
'CHANGE_ADSET_BID',
|
|
32
|
+
'CHANGE_ADSET_BID_STRATEGY',
|
|
33
|
+
|
|
34
|
+
// Ad level actions
|
|
35
|
+
'PAUSE_AD',
|
|
36
|
+
'ACTIVATE_AD',
|
|
37
|
+
|
|
38
|
+
// Custom actions
|
|
39
|
+
'CUSTOM_ACTION'
|
|
40
|
+
),
|
|
41
|
+
allowNull: false,
|
|
42
|
+
comment: 'Type of action to perform',
|
|
43
|
+
},
|
|
44
|
+
actionConfig: {
|
|
45
|
+
type: DataTypes.JSONB,
|
|
46
|
+
allowNull: true,
|
|
47
|
+
comment: 'Configuration for the action (budget amount, bid strategy, etc.)',
|
|
48
|
+
},
|
|
49
|
+
order: {
|
|
50
|
+
type: DataTypes.INTEGER,
|
|
51
|
+
allowNull: false,
|
|
52
|
+
defaultValue: 0,
|
|
53
|
+
comment: 'Order of this action within the rule',
|
|
54
|
+
},
|
|
55
|
+
isActive: {
|
|
56
|
+
type: DataTypes.BOOLEAN,
|
|
57
|
+
defaultValue: true,
|
|
58
|
+
allowNull: false,
|
|
59
|
+
comment: 'Whether this action is active',
|
|
60
|
+
},
|
|
61
|
+
delayMinutes: {
|
|
62
|
+
type: DataTypes.INTEGER,
|
|
63
|
+
allowNull: true,
|
|
64
|
+
defaultValue: 0,
|
|
65
|
+
comment: 'Delay in minutes before executing this action',
|
|
66
|
+
},
|
|
67
|
+
}, {
|
|
68
|
+
tableName: 'RuleActions',
|
|
69
|
+
timestamps: true,
|
|
70
|
+
indexes: [
|
|
71
|
+
{
|
|
72
|
+
fields: ['ruleId'],
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
fields: ['actionType'],
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
fields: ['order'],
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
RuleAction.associate = (models) => {
|
|
84
|
+
// An action belongs to a rule
|
|
85
|
+
RuleAction.belongsTo(models.Rule, {
|
|
86
|
+
foreignKey: 'ruleId',
|
|
87
|
+
as: 'rule',
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
return RuleAction;
|
|
92
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
const { DataTypes } = require('sequelize');
|
|
2
|
+
|
|
3
|
+
module.exports = (sequelize) => {
|
|
4
|
+
const RuleCondition = sequelize.define('RuleCondition', {
|
|
5
|
+
id: {
|
|
6
|
+
type: DataTypes.UUID,
|
|
7
|
+
defaultValue: DataTypes.UUIDV4,
|
|
8
|
+
primaryKey: true,
|
|
9
|
+
},
|
|
10
|
+
ruleId: {
|
|
11
|
+
type: DataTypes.UUID,
|
|
12
|
+
allowNull: false,
|
|
13
|
+
references: {
|
|
14
|
+
model: 'Rules',
|
|
15
|
+
key: 'id',
|
|
16
|
+
},
|
|
17
|
+
comment: 'Reference to the parent rule',
|
|
18
|
+
},
|
|
19
|
+
field: {
|
|
20
|
+
type: DataTypes.STRING(100),
|
|
21
|
+
allowNull: false,
|
|
22
|
+
comment: 'Field to evaluate (e.g., roi, ctr, campaign_name)',
|
|
23
|
+
},
|
|
24
|
+
operator: {
|
|
25
|
+
type: DataTypes.ENUM(
|
|
26
|
+
'EQUALS',
|
|
27
|
+
'NOT_EQUALS',
|
|
28
|
+
'GREATER_THAN',
|
|
29
|
+
'LESS_THAN',
|
|
30
|
+
'GREATER_THAN_OR_EQUAL',
|
|
31
|
+
'LESS_THAN_OR_EQUAL',
|
|
32
|
+
'BETWEEN',
|
|
33
|
+
'IN',
|
|
34
|
+
'NOT_IN',
|
|
35
|
+
'CONTAINS',
|
|
36
|
+
'NOT_CONTAINS',
|
|
37
|
+
'IS_NULL',
|
|
38
|
+
'IS_NOT_NULL'
|
|
39
|
+
),
|
|
40
|
+
allowNull: false,
|
|
41
|
+
comment: 'Comparison operator',
|
|
42
|
+
},
|
|
43
|
+
value: {
|
|
44
|
+
type: DataTypes.JSONB,
|
|
45
|
+
allowNull: true,
|
|
46
|
+
comment: 'Value(s) to compare against (can be array for BETWEEN, IN, etc.)',
|
|
47
|
+
},
|
|
48
|
+
logicalOperator: {
|
|
49
|
+
type: DataTypes.ENUM(
|
|
50
|
+
'AND',
|
|
51
|
+
'OR'
|
|
52
|
+
),
|
|
53
|
+
allowNull: false,
|
|
54
|
+
defaultValue: 'AND',
|
|
55
|
+
comment: 'How this condition connects to the next one',
|
|
56
|
+
},
|
|
57
|
+
order: {
|
|
58
|
+
type: DataTypes.INTEGER,
|
|
59
|
+
allowNull: false,
|
|
60
|
+
defaultValue: 0,
|
|
61
|
+
comment: 'Order of this condition within the rule',
|
|
62
|
+
},
|
|
63
|
+
isActive: {
|
|
64
|
+
type: DataTypes.BOOLEAN,
|
|
65
|
+
defaultValue: true,
|
|
66
|
+
allowNull: false,
|
|
67
|
+
comment: 'Whether this condition is active',
|
|
68
|
+
},
|
|
69
|
+
}, {
|
|
70
|
+
tableName: 'RuleConditions',
|
|
71
|
+
timestamps: true,
|
|
72
|
+
indexes: [
|
|
73
|
+
{
|
|
74
|
+
fields: ['ruleId'],
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
fields: ['field'],
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
fields: ['operator'],
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
fields: ['order'],
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
RuleCondition.associate = (models) => {
|
|
89
|
+
// A condition belongs to a rule
|
|
90
|
+
RuleCondition.belongsTo(models.Rule, {
|
|
91
|
+
foreignKey: 'ruleId',
|
|
92
|
+
as: 'rule',
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
return RuleCondition;
|
|
97
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
const { DataTypes } = require('sequelize');
|
|
2
|
+
|
|
3
|
+
module.exports = (sequelize) => {
|
|
4
|
+
const RuleExecution = sequelize.define('RuleExecution', {
|
|
5
|
+
id: {
|
|
6
|
+
type: DataTypes.UUID,
|
|
7
|
+
defaultValue: DataTypes.UUIDV4,
|
|
8
|
+
primaryKey: true,
|
|
9
|
+
},
|
|
10
|
+
ruleId: {
|
|
11
|
+
type: DataTypes.UUID,
|
|
12
|
+
allowNull: false,
|
|
13
|
+
references: {
|
|
14
|
+
model: 'Rules',
|
|
15
|
+
key: 'id',
|
|
16
|
+
},
|
|
17
|
+
comment: 'Reference to the executed rule',
|
|
18
|
+
},
|
|
19
|
+
executionType: {
|
|
20
|
+
type: DataTypes.ENUM(
|
|
21
|
+
'SCHEDULED',
|
|
22
|
+
'MANUAL',
|
|
23
|
+
'API_TRIGGER'
|
|
24
|
+
),
|
|
25
|
+
allowNull: false,
|
|
26
|
+
comment: 'How the rule was triggered',
|
|
27
|
+
},
|
|
28
|
+
status: {
|
|
29
|
+
type: DataTypes.ENUM(
|
|
30
|
+
'RUNNING',
|
|
31
|
+
'SUCCESS',
|
|
32
|
+
'FAILED',
|
|
33
|
+
'PARTIAL_SUCCESS'
|
|
34
|
+
),
|
|
35
|
+
allowNull: false,
|
|
36
|
+
comment: 'Execution status',
|
|
37
|
+
},
|
|
38
|
+
startTime: {
|
|
39
|
+
type: DataTypes.DATE,
|
|
40
|
+
allowNull: false,
|
|
41
|
+
comment: 'When execution started',
|
|
42
|
+
},
|
|
43
|
+
endTime: {
|
|
44
|
+
type: DataTypes.DATE,
|
|
45
|
+
allowNull: true,
|
|
46
|
+
comment: 'When execution completed',
|
|
47
|
+
},
|
|
48
|
+
duration: {
|
|
49
|
+
type: DataTypes.INTEGER,
|
|
50
|
+
allowNull: true,
|
|
51
|
+
comment: 'Execution duration in milliseconds',
|
|
52
|
+
},
|
|
53
|
+
itemsEvaluated: {
|
|
54
|
+
type: DataTypes.INTEGER,
|
|
55
|
+
defaultValue: 0,
|
|
56
|
+
allowNull: false,
|
|
57
|
+
comment: 'Number of items (campaigns/adsets/ads) evaluated',
|
|
58
|
+
},
|
|
59
|
+
itemsMatched: {
|
|
60
|
+
type: DataTypes.INTEGER,
|
|
61
|
+
defaultValue: 0,
|
|
62
|
+
allowNull: false,
|
|
63
|
+
comment: 'Number of items that matched the conditions',
|
|
64
|
+
},
|
|
65
|
+
actionsExecuted: {
|
|
66
|
+
type: DataTypes.INTEGER,
|
|
67
|
+
defaultValue: 0,
|
|
68
|
+
allowNull: false,
|
|
69
|
+
comment: 'Number of actions successfully executed',
|
|
70
|
+
},
|
|
71
|
+
actionsFailed: {
|
|
72
|
+
type: DataTypes.INTEGER,
|
|
73
|
+
defaultValue: 0,
|
|
74
|
+
allowNull: false,
|
|
75
|
+
comment: 'Number of actions that failed',
|
|
76
|
+
},
|
|
77
|
+
errorMessage: {
|
|
78
|
+
type: DataTypes.TEXT,
|
|
79
|
+
allowNull: true,
|
|
80
|
+
comment: 'Error message if execution failed',
|
|
81
|
+
},
|
|
82
|
+
executionDetails: {
|
|
83
|
+
type: DataTypes.JSONB,
|
|
84
|
+
allowNull: true,
|
|
85
|
+
comment: 'Detailed execution results and logs',
|
|
86
|
+
},
|
|
87
|
+
triggeredBy: {
|
|
88
|
+
type: DataTypes.STRING(255),
|
|
89
|
+
allowNull: true,
|
|
90
|
+
comment: 'User or system that triggered the execution',
|
|
91
|
+
},
|
|
92
|
+
}, {
|
|
93
|
+
tableName: 'RuleExecutions',
|
|
94
|
+
timestamps: true,
|
|
95
|
+
indexes: [
|
|
96
|
+
{
|
|
97
|
+
fields: ['ruleId'],
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
fields: ['status'],
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
fields: ['startTime'],
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
fields: ['executionType'],
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
RuleExecution.associate = (models) => {
|
|
112
|
+
// An execution belongs to a rule
|
|
113
|
+
RuleExecution.belongsTo(models.Rule, {
|
|
114
|
+
foreignKey: 'ruleId',
|
|
115
|
+
as: 'rule',
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
return RuleExecution;
|
|
120
|
+
};
|