agrs-sequelize-sdk 1.4.19 → 1.4.22

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 (31) hide show
  1. package/migrations/2026-05-18-add-group-id-to-ai-campaign-queue.js +18 -0
  2. package/migrations/2026-05-18-add-platform-code-to-creation-logs.js +65 -0
  3. package/migrations/2026-05-18-add-platform-code-to-pixels.js +55 -0
  4. package/migrations/2026-05-18-add-platform-code-to-rsoc-feed-campaigns.js +55 -0
  5. package/migrations/2026-05-18-add-platform-date-index-to-adperformance.js +16 -0
  6. package/migrations/2026-05-18-add-platform-date-index-to-adsetperformance.js +16 -0
  7. package/migrations/2026-05-18-add-review-status-to-ad.js +36 -0
  8. package/migrations/2026-05-18-create-canonical-insights.js +84 -0
  9. package/migrations/2026-05-18-create-snapchat-public-profiles.js +68 -0
  10. package/migrations/2026-05-18-create-tiktok-identities.js +71 -0
  11. package/migrations/2026-05-18-create-tiktok-snapchat-campaigns.js +143 -0
  12. package/migrations/2026-05-18-create-tt-snp-adset-ad-tables.js +309 -0
  13. package/models/AICampaignQueue.js +9 -0
  14. package/models/Ad.js +12 -0
  15. package/models/AdPerformance.js +4 -0
  16. package/models/AdsetPerformance.js +5 -0
  17. package/models/CampaignCreationLog.js +12 -0
  18. package/models/CampaignCreationLogV2.js +8 -0
  19. package/models/CanonicalInsights.js +68 -0
  20. package/models/RSOCFeedCampaign.js +6 -0
  21. package/models/SnapchatAd.js +69 -0
  22. package/models/SnapchatAdSquad.js +92 -0
  23. package/models/SnapchatCampaign.js +69 -0
  24. package/models/SnapchatPublicProfiles.js +47 -0
  25. package/models/TikTokAd.js +71 -0
  26. package/models/TikTokAdGroup.js +82 -0
  27. package/models/TikTokCampaign.js +71 -0
  28. package/models/TiktokIdentities.js +51 -0
  29. package/models/Users.js +10 -0
  30. package/models/pixel.js +6 -0
  31. package/package.json +1 -1
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ up: async (queryInterface, Sequelize) => {
5
+ await queryInterface.addColumn("ai_campaign_queue", "group_id", {
6
+ type: Sequelize.UUID,
7
+ allowNull: true,
8
+ comment:
9
+ "Groups rows created by a single multi-platform fanout request",
10
+ });
11
+ await queryInterface.addIndex("ai_campaign_queue", ["group_id"]);
12
+ },
13
+
14
+ down: async (queryInterface) => {
15
+ await queryInterface.removeIndex("ai_campaign_queue", ["group_id"]);
16
+ await queryInterface.removeColumn("ai_campaign_queue", "group_id");
17
+ },
18
+ };
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * CampaignCreationLogs + CampaignCreationLogsV2 normalization (Phase 1):
5
+ * - Add canonical `platform_code` ENUM column ('fb' | 'tt' | 'snp').
6
+ * - Backfill from legacy VARCHAR `platform` column using case-insensitive mapping.
7
+ * - Keep legacy `platform` column untouched (dropped in a follow-up plan).
8
+ *
9
+ * Mapping (case-insensitive on legacy `platform`):
10
+ * facebook | fb -> fb
11
+ * tiktok | tt -> tt
12
+ * snapchat | snap | snp -> snp
13
+ * else -> fb (safe default)
14
+ */
15
+ module.exports = {
16
+ up: async (queryInterface, Sequelize) => {
17
+ const tables = ["CampaignCreationLogs", "CampaignCreationLogsV2"];
18
+
19
+ for (const table of tables) {
20
+ // 1. Add the new column as nullable so we can backfill before enforcing NOT NULL.
21
+ await queryInterface.addColumn(table, "platform_code", {
22
+ type: Sequelize.ENUM("fb", "tt", "snp"),
23
+ allowNull: true,
24
+ comment:
25
+ "Canonical ad platform identifier: fb=Facebook, tt=TikTok, snp=Snapchat",
26
+ });
27
+
28
+ // 2. Backfill from legacy `platform` column (idempotent on platform_code IS NULL).
29
+ await queryInterface.sequelize.query(`
30
+ UPDATE "${table}"
31
+ SET platform_code = CASE
32
+ WHEN LOWER(platform) IN ('facebook', 'fb') THEN 'fb'::"enum_${table}_platform_code"
33
+ WHEN LOWER(platform) IN ('tiktok', 'tt') THEN 'tt'::"enum_${table}_platform_code"
34
+ WHEN LOWER(platform) IN ('snapchat', 'snap', 'snp') THEN 'snp'::"enum_${table}_platform_code"
35
+ ELSE 'fb'::"enum_${table}_platform_code"
36
+ END
37
+ WHERE platform_code IS NULL;
38
+ `);
39
+
40
+ // 3. Enforce NOT NULL + default now that every row has a value.
41
+ await queryInterface.changeColumn(table, "platform_code", {
42
+ type: Sequelize.ENUM("fb", "tt", "snp"),
43
+ allowNull: false,
44
+ defaultValue: "fb",
45
+ comment:
46
+ "Canonical ad platform identifier: fb=Facebook, tt=TikTok, snp=Snapchat",
47
+ });
48
+
49
+ // 4. Index for filter performance.
50
+ await queryInterface.addIndex(table, ["platform_code"]);
51
+ }
52
+ },
53
+
54
+ down: async (queryInterface) => {
55
+ const tables = ["CampaignCreationLogs", "CampaignCreationLogsV2"];
56
+
57
+ for (const table of tables) {
58
+ await queryInterface.removeIndex(table, ["platform_code"]);
59
+ await queryInterface.removeColumn(table, "platform_code");
60
+ await queryInterface.sequelize.query(
61
+ `DROP TYPE IF EXISTS "enum_${table}_platform_code";`
62
+ );
63
+ }
64
+ },
65
+ };
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Pixels normalization (Phase 1):
5
+ * - Add canonical `platform_code` ENUM column ('fb' | 'tt' | 'snp').
6
+ * - Backfill from legacy VARCHAR `platform` column using case-insensitive mapping.
7
+ * - Keep legacy `platform` column untouched (dropped in a follow-up plan).
8
+ *
9
+ * Mapping (case-insensitive on legacy `platform`):
10
+ * facebook | fb -> fb
11
+ * tiktok | tt -> tt
12
+ * snapchat | snap | snp -> snp
13
+ * else -> fb (safe default)
14
+ */
15
+ module.exports = {
16
+ up: async (queryInterface, Sequelize) => {
17
+ // 1. Add the new column as nullable so we can backfill before enforcing NOT NULL.
18
+ await queryInterface.addColumn("Pixels", "platform_code", {
19
+ type: Sequelize.ENUM("fb", "tt", "snp"),
20
+ allowNull: true,
21
+ comment: "Canonical ad platform identifier: fb=Facebook, tt=TikTok, snp=Snapchat",
22
+ });
23
+
24
+ // 2. Backfill from legacy `platform` column (idempotent on platform_code IS NULL).
25
+ await queryInterface.sequelize.query(`
26
+ UPDATE "Pixels"
27
+ SET platform_code = CASE
28
+ WHEN LOWER(platform) IN ('facebook', 'fb') THEN 'fb'::"enum_Pixels_platform_code"
29
+ WHEN LOWER(platform) IN ('tiktok', 'tt') THEN 'tt'::"enum_Pixels_platform_code"
30
+ WHEN LOWER(platform) IN ('snapchat', 'snap', 'snp') THEN 'snp'::"enum_Pixels_platform_code"
31
+ ELSE 'fb'::"enum_Pixels_platform_code"
32
+ END
33
+ WHERE platform_code IS NULL;
34
+ `);
35
+
36
+ // 3. Enforce NOT NULL + default now that every row has a value.
37
+ await queryInterface.changeColumn("Pixels", "platform_code", {
38
+ type: Sequelize.ENUM("fb", "tt", "snp"),
39
+ allowNull: false,
40
+ defaultValue: "fb",
41
+ comment: "Canonical ad platform identifier: fb=Facebook, tt=TikTok, snp=Snapchat",
42
+ });
43
+
44
+ // 4. Index for filter performance.
45
+ await queryInterface.addIndex("Pixels", ["platform_code"]);
46
+ },
47
+
48
+ down: async (queryInterface) => {
49
+ await queryInterface.removeIndex("Pixels", ["platform_code"]);
50
+ await queryInterface.removeColumn("Pixels", "platform_code");
51
+ await queryInterface.sequelize.query(
52
+ 'DROP TYPE IF EXISTS "enum_Pixels_platform_code";'
53
+ );
54
+ },
55
+ };
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * rsoc_feed_campaigns normalization (Phase 1):
5
+ * - Add canonical `platform_code` ENUM column ('fb' | 'tt' | 'snp').
6
+ * - Backfill from legacy VARCHAR `platform` column using case-insensitive mapping.
7
+ * - Keep legacy `platform` column untouched (dropped in a follow-up plan).
8
+ *
9
+ * Mapping (case-insensitive on legacy `platform`):
10
+ * facebook | fb -> fb
11
+ * tiktok | tt -> tt
12
+ * snapchat | snap | snp -> snp
13
+ * else -> fb (safe default)
14
+ */
15
+ module.exports = {
16
+ up: async (queryInterface, Sequelize) => {
17
+ // 1. Add the new column as nullable so we can backfill before enforcing NOT NULL.
18
+ await queryInterface.addColumn("rsoc_feed_campaigns", "platform_code", {
19
+ type: Sequelize.ENUM("fb", "tt", "snp"),
20
+ allowNull: true,
21
+ comment: "Canonical ad platform identifier: fb=Facebook, tt=TikTok, snp=Snapchat",
22
+ });
23
+
24
+ // 2. Backfill from legacy `platform` column (idempotent on platform_code IS NULL).
25
+ await queryInterface.sequelize.query(`
26
+ UPDATE "rsoc_feed_campaigns"
27
+ SET platform_code = CASE
28
+ WHEN LOWER(platform) IN ('facebook', 'fb') THEN 'fb'::"enum_rsoc_feed_campaigns_platform_code"
29
+ WHEN LOWER(platform) IN ('tiktok', 'tt') THEN 'tt'::"enum_rsoc_feed_campaigns_platform_code"
30
+ WHEN LOWER(platform) IN ('snapchat', 'snap', 'snp') THEN 'snp'::"enum_rsoc_feed_campaigns_platform_code"
31
+ ELSE 'fb'::"enum_rsoc_feed_campaigns_platform_code"
32
+ END
33
+ WHERE platform_code IS NULL;
34
+ `);
35
+
36
+ // 3. Enforce NOT NULL + default now that every row has a value.
37
+ await queryInterface.changeColumn("rsoc_feed_campaigns", "platform_code", {
38
+ type: Sequelize.ENUM("fb", "tt", "snp"),
39
+ allowNull: false,
40
+ defaultValue: "fb",
41
+ comment: "Canonical ad platform identifier: fb=Facebook, tt=TikTok, snp=Snapchat",
42
+ });
43
+
44
+ // 4. Index for filter performance.
45
+ await queryInterface.addIndex("rsoc_feed_campaigns", ["platform_code"]);
46
+ },
47
+
48
+ down: async (queryInterface) => {
49
+ await queryInterface.removeIndex("rsoc_feed_campaigns", ["platform_code"]);
50
+ await queryInterface.removeColumn("rsoc_feed_campaigns", "platform_code");
51
+ await queryInterface.sequelize.query(
52
+ 'DROP TYPE IF EXISTS "enum_rsoc_feed_campaigns_platform_code";'
53
+ );
54
+ },
55
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ up: async (queryInterface) => {
5
+ await queryInterface.addIndex("AdPerformance", ["platform", "Date"], {
6
+ name: "AdPerformance_platform_Date_idx",
7
+ });
8
+ },
9
+
10
+ down: async (queryInterface) => {
11
+ await queryInterface.removeIndex(
12
+ "AdPerformance",
13
+ "AdPerformance_platform_Date_idx"
14
+ );
15
+ },
16
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ up: async (queryInterface) => {
5
+ await queryInterface.addIndex("AdSetPerformance", ["platform", "Date"], {
6
+ name: "AdSetPerformance_platform_Date_idx",
7
+ });
8
+ },
9
+
10
+ down: async (queryInterface) => {
11
+ await queryInterface.removeIndex(
12
+ "AdSetPerformance",
13
+ "AdSetPerformance_platform_Date_idx"
14
+ );
15
+ },
16
+ };
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Additive migration: add review_status + pending_review_since to Ad.
5
+ *
6
+ * Used by SnapchatStrategy.updateAd to optimistically flip an ad to
7
+ * PENDING_REVIEW immediately after editing copy/URL fields (brand_name,
8
+ * headline, url, landing_page_url) — Snapchat resends those ads to review
9
+ * upstream, and we want the UI to reflect that without waiting for the
10
+ * next status sync cycle.
11
+ *
12
+ * Backward compatible — both columns nullable, no default value, no
13
+ * destructive operations.
14
+ */
15
+
16
+ module.exports = {
17
+ up: async (queryInterface, Sequelize) => {
18
+ await queryInterface.addColumn("Ad", "review_status", {
19
+ type: Sequelize.STRING,
20
+ allowNull: true,
21
+ comment:
22
+ "Local review status mirror (e.g. PENDING_REVIEW after copy/URL edit on Snap). Cleared by status sync.",
23
+ });
24
+ await queryInterface.addColumn("Ad", "pending_review_since", {
25
+ type: Sequelize.DATE,
26
+ allowNull: true,
27
+ comment:
28
+ "Timestamp when ad was optimistically flipped to PENDING_REVIEW after a triggering edit. Cleared when upstream review settles.",
29
+ });
30
+ },
31
+
32
+ down: async (queryInterface) => {
33
+ await queryInterface.removeColumn("Ad", "pending_review_since");
34
+ await queryInterface.removeColumn("Ad", "review_status");
35
+ },
36
+ };
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ up: async (queryInterface, Sequelize) => {
5
+ await queryInterface.createTable("canonical_insights", {
6
+ id: {
7
+ type: Sequelize.BIGINT,
8
+ primaryKey: true,
9
+ autoIncrement: true,
10
+ allowNull: false,
11
+ },
12
+ platform: {
13
+ type: Sequelize.ENUM("fb", "tt", "snp"),
14
+ allowNull: false,
15
+ comment: "Ad platform identifier: fb=Facebook, tt=TikTok, snp=Snapchat",
16
+ },
17
+ entity_type: {
18
+ type: Sequelize.ENUM("campaign", "adset", "ad"),
19
+ allowNull: false,
20
+ },
21
+ entity_id: {
22
+ type: Sequelize.STRING(64),
23
+ allowNull: false,
24
+ },
25
+ date: {
26
+ type: Sequelize.DATEONLY,
27
+ allowNull: false,
28
+ },
29
+ impressions: {
30
+ type: Sequelize.BIGINT,
31
+ defaultValue: 0,
32
+ },
33
+ clicks: {
34
+ type: Sequelize.BIGINT,
35
+ defaultValue: 0,
36
+ },
37
+ spend: {
38
+ type: Sequelize.DECIMAL(14, 4),
39
+ defaultValue: 0,
40
+ },
41
+ conversions: {
42
+ type: Sequelize.BIGINT,
43
+ defaultValue: 0,
44
+ },
45
+ revenue: {
46
+ type: Sequelize.DECIMAL(14, 4),
47
+ defaultValue: 0,
48
+ },
49
+ raw_payload: {
50
+ type: Sequelize.JSONB,
51
+ allowNull: true,
52
+ },
53
+ createdAt: {
54
+ type: Sequelize.DATE,
55
+ allowNull: false,
56
+ },
57
+ updatedAt: {
58
+ type: Sequelize.DATE,
59
+ allowNull: false,
60
+ },
61
+ });
62
+
63
+ await queryInterface.addIndex(
64
+ "canonical_insights",
65
+ ["platform", "entity_type", "entity_id", "date"],
66
+ {
67
+ unique: true,
68
+ name: "canonical_insights_unique_per_entity_date",
69
+ }
70
+ );
71
+
72
+ await queryInterface.addIndex("canonical_insights", ["platform", "date"]);
73
+ },
74
+
75
+ down: async (queryInterface) => {
76
+ await queryInterface.dropTable("canonical_insights");
77
+ await queryInterface.sequelize.query(
78
+ 'DROP TYPE IF EXISTS "enum_canonical_insights_platform";'
79
+ );
80
+ await queryInterface.sequelize.query(
81
+ 'DROP TYPE IF EXISTS "enum_canonical_insights_entity_type";'
82
+ );
83
+ },
84
+ };
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Creates the `snapchat_public_profiles` rotation pool used by
5
+ * `assetResolver.getDefaultAssetForPlatform({ platform: 'snp' })`.
6
+ *
7
+ * Additive-only: no foreign keys, no touching of existing tables.
8
+ * Safe to apply on production. Pre-seed environments fall back to the
9
+ * `SNAPCHAT_DEFAULT_PUBLIC_PROFILE_ID` env var until rows exist.
10
+ */
11
+ module.exports = {
12
+ up: async (queryInterface, Sequelize) => {
13
+ await queryInterface.createTable("snapchat_public_profiles", {
14
+ id: {
15
+ type: Sequelize.BIGINT,
16
+ primaryKey: true,
17
+ autoIncrement: true,
18
+ },
19
+ public_profile_id: {
20
+ type: Sequelize.STRING(64),
21
+ allowNull: false,
22
+ unique: true,
23
+ },
24
+ name: {
25
+ type: Sequelize.STRING(255),
26
+ allowNull: true,
27
+ },
28
+ ad_account_id: {
29
+ type: Sequelize.STRING(64),
30
+ allowNull: false,
31
+ },
32
+ status: {
33
+ type: Sequelize.STRING(16),
34
+ allowNull: false,
35
+ defaultValue: "active",
36
+ },
37
+ tier: {
38
+ type: Sequelize.INTEGER,
39
+ allowNull: false,
40
+ defaultValue: 1,
41
+ },
42
+ createdAt: {
43
+ type: Sequelize.DATE,
44
+ allowNull: false,
45
+ defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
46
+ },
47
+ updatedAt: {
48
+ type: Sequelize.DATE,
49
+ allowNull: false,
50
+ defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
51
+ },
52
+ });
53
+
54
+ await queryInterface.addIndex(
55
+ "snapchat_public_profiles",
56
+ ["ad_account_id", "status"],
57
+ { name: "snapchat_public_profiles_ad_account_status_idx" }
58
+ );
59
+ },
60
+
61
+ down: async (queryInterface) => {
62
+ await queryInterface.removeIndex(
63
+ "snapchat_public_profiles",
64
+ "snapchat_public_profiles_ad_account_status_idx"
65
+ );
66
+ await queryInterface.dropTable("snapchat_public_profiles");
67
+ },
68
+ };
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Creates the `tiktok_identities` rotation pool used by
5
+ * `assetResolver.getDefaultAssetForPlatform({ platform: 'tt' })`.
6
+ *
7
+ * Additive-only: no foreign keys, no touching of existing tables.
8
+ * Safe to apply on production. Pre-seed environments fall back to the
9
+ * `TIKTOK_DEFAULT_IDENTITY_ID` env var until rows exist.
10
+ */
11
+ module.exports = {
12
+ up: async (queryInterface, Sequelize) => {
13
+ await queryInterface.createTable("tiktok_identities", {
14
+ id: {
15
+ type: Sequelize.BIGINT,
16
+ primaryKey: true,
17
+ autoIncrement: true,
18
+ },
19
+ identity_id: {
20
+ type: Sequelize.STRING(64),
21
+ allowNull: false,
22
+ unique: true,
23
+ },
24
+ identity_type: {
25
+ type: Sequelize.STRING(32),
26
+ allowNull: false,
27
+ defaultValue: "CUSTOMIZED_USER",
28
+ },
29
+ name: {
30
+ type: Sequelize.STRING(255),
31
+ allowNull: true,
32
+ },
33
+ ad_account_id: {
34
+ type: Sequelize.STRING(64),
35
+ allowNull: false,
36
+ },
37
+ status: {
38
+ type: Sequelize.STRING(16),
39
+ allowNull: false,
40
+ defaultValue: "active",
41
+ },
42
+ tier: {
43
+ type: Sequelize.INTEGER,
44
+ allowNull: false,
45
+ defaultValue: 1,
46
+ },
47
+ createdAt: {
48
+ type: Sequelize.DATE,
49
+ allowNull: false,
50
+ defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
51
+ },
52
+ updatedAt: {
53
+ type: Sequelize.DATE,
54
+ allowNull: false,
55
+ defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
56
+ },
57
+ });
58
+
59
+ await queryInterface.addIndex("tiktok_identities", ["ad_account_id", "status"], {
60
+ name: "tiktok_identities_ad_account_status_idx",
61
+ });
62
+ },
63
+
64
+ down: async (queryInterface) => {
65
+ await queryInterface.removeIndex(
66
+ "tiktok_identities",
67
+ "tiktok_identities_ad_account_status_idx"
68
+ );
69
+ await queryInterface.dropTable("tiktok_identities");
70
+ },
71
+ };
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+
3
+ // Additive migration — creates two new tables to mirror TikTok and Snapchat
4
+ // campaign state in the local DB. No FKs to existing tables; loose coupling
5
+ // keeps platform isolation. Reporting joins to canonical_insights at the MV
6
+ // layer (see dashboard migration 003-multi-platform-performance-view.sql).
7
+
8
+ module.exports = {
9
+ up: async (queryInterface, Sequelize) => {
10
+ // ----- TikTok Campaigns -----
11
+ await queryInterface.createTable("tiktok_campaigns", {
12
+ campaign_id: {
13
+ type: Sequelize.BIGINT,
14
+ primaryKey: true,
15
+ allowNull: false,
16
+ },
17
+ campaign_name: {
18
+ type: Sequelize.STRING(255),
19
+ allowNull: false,
20
+ },
21
+ ad_account_id: {
22
+ type: Sequelize.STRING(64),
23
+ allowNull: false,
24
+ },
25
+ objective_type: {
26
+ type: Sequelize.STRING(50),
27
+ allowNull: true,
28
+ },
29
+ budget_mode: {
30
+ type: Sequelize.STRING(50),
31
+ allowNull: true,
32
+ comment: "BUDGET_MODE_DAY or BUDGET_MODE_LIFETIME (TikTok native)",
33
+ },
34
+ daily_budget_usd: {
35
+ type: Sequelize.DECIMAL(12, 6),
36
+ allowNull: true,
37
+ comment: "Normalized USD value (TikTok returns native USD float)",
38
+ },
39
+ operation_status: {
40
+ type: Sequelize.STRING(50),
41
+ allowNull: true,
42
+ comment: "ENABLE or DISABLE (TikTok native)",
43
+ },
44
+ special_industries: {
45
+ type: Sequelize.TEXT,
46
+ allowNull: true,
47
+ comment: "JSON-serialized array of special industry tags",
48
+ },
49
+ schedule_start_time: {
50
+ type: Sequelize.DATE,
51
+ allowNull: true,
52
+ },
53
+ schedule_end_time: {
54
+ type: Sequelize.DATE,
55
+ allowNull: true,
56
+ },
57
+ created_at: {
58
+ type: Sequelize.DATE,
59
+ allowNull: false,
60
+ },
61
+ updated_at: {
62
+ type: Sequelize.DATE,
63
+ allowNull: true,
64
+ },
65
+ synced_at: {
66
+ type: Sequelize.DATE,
67
+ allowNull: false,
68
+ },
69
+ });
70
+
71
+ await queryInterface.addIndex("tiktok_campaigns", ["ad_account_id"]);
72
+ await queryInterface.addIndex("tiktok_campaigns", ["created_at"]);
73
+ await queryInterface.addIndex("tiktok_campaigns", ["operation_status"]);
74
+
75
+ // ----- Snapchat Campaigns -----
76
+ await queryInterface.createTable("snapchat_campaigns", {
77
+ id: {
78
+ type: Sequelize.STRING(36),
79
+ primaryKey: true,
80
+ allowNull: false,
81
+ comment: "Snapchat UUID",
82
+ },
83
+ name: {
84
+ type: Sequelize.STRING(255),
85
+ allowNull: false,
86
+ },
87
+ ad_account_id: {
88
+ type: Sequelize.STRING(36),
89
+ allowNull: false,
90
+ },
91
+ status: {
92
+ type: Sequelize.STRING(50),
93
+ allowNull: false,
94
+ comment: "ACTIVE or PAUSED (Snap native)",
95
+ },
96
+ objective: {
97
+ type: Sequelize.STRING(255),
98
+ allowNull: true,
99
+ },
100
+ daily_budget_micro: {
101
+ type: Sequelize.BIGINT,
102
+ allowNull: true,
103
+ },
104
+ lifetime_spend_cap_micro: {
105
+ type: Sequelize.BIGINT,
106
+ allowNull: true,
107
+ },
108
+ timezone: {
109
+ type: Sequelize.STRING(50),
110
+ allowNull: true,
111
+ },
112
+ start_time: {
113
+ type: Sequelize.DATE,
114
+ allowNull: true,
115
+ },
116
+ end_time: {
117
+ type: Sequelize.DATE,
118
+ allowNull: true,
119
+ },
120
+ created_at: {
121
+ type: Sequelize.DATE,
122
+ allowNull: false,
123
+ },
124
+ updated_at: {
125
+ type: Sequelize.DATE,
126
+ allowNull: true,
127
+ },
128
+ synced_at: {
129
+ type: Sequelize.DATE,
130
+ allowNull: false,
131
+ },
132
+ });
133
+
134
+ await queryInterface.addIndex("snapchat_campaigns", ["ad_account_id"]);
135
+ await queryInterface.addIndex("snapchat_campaigns", ["created_at"]);
136
+ await queryInterface.addIndex("snapchat_campaigns", ["status"]);
137
+ },
138
+
139
+ down: async (queryInterface) => {
140
+ await queryInterface.dropTable("snapchat_campaigns");
141
+ await queryInterface.dropTable("tiktok_campaigns");
142
+ },
143
+ };