agrs-sequelize-sdk 1.3.12 → 1.3.14

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.
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ up: async (queryInterface, Sequelize) => {
5
+ // Change AdSetName column from VARCHAR(255) to TEXT
6
+ // This is a SAFE operation - PostgreSQL can convert VARCHAR to TEXT without data loss
7
+ // All existing data will be preserved
8
+
9
+ // First, check if column exists and get its current type
10
+ const [columns] = await queryInterface.sequelize.query(`
11
+ SELECT column_name, data_type, character_maximum_length
12
+ FROM information_schema.columns
13
+ WHERE table_name = 'AdSet' AND column_name = 'AdSetName'
14
+ `);
15
+
16
+ if (columns.length === 0) {
17
+ console.log("⚠️ AdSetName column not found, skipping migration");
18
+ return;
19
+ }
20
+
21
+ const currentType = columns[0].data_type;
22
+ const currentMaxLength = columns[0].character_maximum_length;
23
+
24
+ console.log(
25
+ `Current AdSetName type: ${currentType}(${
26
+ currentMaxLength || "unlimited"
27
+ })`
28
+ );
29
+
30
+ // Only change if it's currently VARCHAR with length limit
31
+ if (currentType === "character varying" && currentMaxLength) {
32
+ console.log("Converting AdSetName from VARCHAR to TEXT...");
33
+
34
+ // Use direct SQL for more control
35
+ await queryInterface.sequelize.query(`
36
+ ALTER TABLE "AdSet"
37
+ ALTER COLUMN "AdSetName" TYPE TEXT
38
+ USING "AdSetName"::TEXT
39
+ `);
40
+
41
+ console.log("✅ AdSetName successfully converted to TEXT");
42
+ } else if (currentType === "text") {
43
+ console.log("✅ AdSetName is already TEXT, no change needed");
44
+ } else {
45
+ console.log(`⚠️ AdSetName is ${currentType}, not changing`);
46
+ }
47
+ },
48
+
49
+ down: async (queryInterface, Sequelize) => {
50
+ // Revert back to VARCHAR(255)
51
+ // WARNING: This might truncate existing long values if any exist
52
+ console.log(
53
+ "⚠️ Reverting AdSetName to VARCHAR(255) - this may truncate long values!"
54
+ );
55
+
56
+ // Check for any values longer than 255 characters
57
+ const [longValues] = await queryInterface.sequelize.query(`
58
+ SELECT COUNT(*) as count
59
+ FROM "AdSet"
60
+ WHERE LENGTH("AdSetName") > 255
61
+ `);
62
+
63
+ if (longValues[0].count > 0) {
64
+ console.log(
65
+ `⚠️ WARNING: ${longValues[0].count} rows have AdSetName longer than 255 characters!`
66
+ );
67
+ console.log(
68
+ "⚠️ These will be truncated if you proceed with the down migration."
69
+ );
70
+ }
71
+
72
+ await queryInterface.changeColumn("AdSet", "AdSetName", {
73
+ type: Sequelize.STRING(255),
74
+ allowNull: true,
75
+ });
76
+
77
+ console.log("✅ AdSetName reverted to VARCHAR(255)");
78
+ },
79
+ };
package/models/Ad.js CHANGED
@@ -7,7 +7,7 @@ module.exports = (sequelize, DataTypes) => {
7
7
  primaryKey: true,
8
8
  },
9
9
  AdName: {
10
- type: DataTypes.STRING,
10
+ type: DataTypes.TEXT,
11
11
  allowNull: false,
12
12
  },
13
13
  AdSetID: {
package/models/AdSet.js CHANGED
@@ -151,7 +151,7 @@ module.exports = (sequelize, DataTypes) => {
151
151
  primaryKey: true,
152
152
  },
153
153
  AdSetName: {
154
- type: DataTypes.STRING,
154
+ type: DataTypes.TEXT,
155
155
  allowNull: true,
156
156
  },
157
157
  Status: {
@@ -229,7 +229,7 @@ module.exports = (sequelize, DataTypes) => {
229
229
  target_roas: {
230
230
  type: DataTypes.FLOAT,
231
231
  allowNull: true,
232
- comment: 'Target ROAS as decimal (0.9 = 90%)',
232
+ comment: "Target ROAS as decimal (0.9 = 90%)",
233
233
  },
234
234
  waiting: {
235
235
  type: DataTypes.BOOLEAN,
@@ -7,7 +7,7 @@ module.exports = (sequelize, DataTypes) => {
7
7
  primaryKey: true,
8
8
  },
9
9
  CampaignName: {
10
- type: DataTypes.STRING,
10
+ type: DataTypes.TEXT,
11
11
  allowNull: true,
12
12
  },
13
13
  pixelId: {
@@ -54,7 +54,7 @@ module.exports = (sequelize, DataTypes) => {
54
54
  allowNull: true,
55
55
  },
56
56
  campaignName: {
57
- type: DataTypes.STRING,
57
+ type: DataTypes.TEXT,
58
58
  allowNull: false,
59
59
  },
60
60
  campaignId: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agrs-sequelize-sdk",
3
- "version": "1.3.12",
3
+ "version": "1.3.14",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "start": "node index.js",
@@ -42,9 +42,56 @@ async function syncDatabase() {
42
42
  console.log("==============================\n");
43
43
 
44
44
  // Sync with alter: true to update schema
45
+ // NOTE: This is SAFE for VARCHAR->TEXT conversions (expanding type, no data loss)
46
+ // Sequelize will use ALTER COLUMN TYPE which preserves all existing data
47
+
48
+ // Safety check: Count existing AdSets before sync
49
+ let adSetCountBefore = null;
50
+ try {
51
+ const [result] = await db.sequelize.query(
52
+ 'SELECT COUNT(*) as count FROM "AdSet"',
53
+ { type: db.sequelize.QueryTypes.SELECT }
54
+ );
55
+ adSetCountBefore = result.count;
56
+ console.log(`📊 Current AdSet count in database: ${adSetCountBefore}`);
57
+ } catch (error) {
58
+ console.log("⚠️ Could not count AdSets (table might not exist yet)");
59
+ }
60
+
45
61
  console.log("Syncing database schema...");
62
+ console.log(
63
+ "⚠️ Using alter: true - this will update column types to match models"
64
+ );
65
+ console.log(
66
+ " Safe operations: VARCHAR->TEXT (expanding), adding columns"
67
+ );
68
+ console.log(
69
+ " Unsafe operations: TEXT->VARCHAR (truncating), dropping columns"
70
+ );
71
+
46
72
  await db.sequelize.sync({ alter: true });
47
73
 
74
+ // Safety check: Verify AdSet count after sync
75
+ if (adSetCountBefore !== null) {
76
+ try {
77
+ const [result] = await db.sequelize.query(
78
+ 'SELECT COUNT(*) as count FROM "AdSet"',
79
+ { type: db.sequelize.QueryTypes.SELECT }
80
+ );
81
+ const adSetCountAfter = result.count;
82
+ console.log(`📊 AdSet count after sync: ${adSetCountAfter}`);
83
+ if (adSetCountBefore !== adSetCountAfter) {
84
+ console.error(
85
+ `❌ WARNING: AdSet count changed from ${adSetCountBefore} to ${adSetCountAfter}!`
86
+ );
87
+ } else {
88
+ console.log("✅ AdSet count unchanged - no data loss confirmed");
89
+ }
90
+ } catch (error) {
91
+ console.log("⚠️ Could not verify AdSet count after sync");
92
+ }
93
+ }
94
+
48
95
  console.log("✅ Database synchronized successfully!");
49
96
  console.log("Schema has been updated to match model definitions.");
50
97