Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite migrations #493

Merged
merged 18 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/.env
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ ALLOWED_IPS=127.0.0.1, 11.22.33.44, 11.22.33.45, 11.22.33.46, 192.168.65.1
FRONTEND_URL=http://localhost:4173/

# JWT secret for running npm run dev in backend folder locally
JWT_SECRET="NKrbO2lpCsOpVAlqAPsjZ0tZXzIoKru7gAmYZ7XlHn0=qqwqeq"
JWT_SECRET="NKrbO2lpCsOpVAlqAPsjZ0tZXzIoKru7gAmYZ7XlHn0=qqwqeq"
74 changes: 74 additions & 0 deletions backend/migrations/0000-1.0-users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'use strict';

const settings = require('./../config/settings');

const TABLE_NAME = 'users'; // Define the table name

module.exports = {
up: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.createTable(TABLE_NAME, {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
},
name: {
type: Sequelize.STRING(50),
allowNull: false,
},
surname: {
type: Sequelize.STRING(50),
allowNull: true,
},
email: {
type: Sequelize.STRING(100),
allowNull: false,
unique: true,
},
password: {
type: Sequelize.STRING(100),
allowNull: false,
},
Comment on lines +30 to +33
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Heads up about that password field, fam! 🔒

The password field length should accommodate the hash output length. If you're using bcrypt (which you should), the hash is typically 60 characters.

-          type: Sequelize.STRING(100),
+          type: Sequelize.STRING(60),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
password: {
type: Sequelize.STRING(100),
allowNull: false,
},
password: {
type: Sequelize.STRING(60),
allowNull: false,
},

role: {
type: Sequelize.ENUM,
values: settings.user.roleEnum,
defaultValue: settings.user.role.admin,
allowNull: false,
},
picture:{
type: Sequelize.TEXT,
allowNull: true,
},
createdAt: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
},
Comment on lines +44 to +48
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Yo, where's the updatedAt timestamp at? 🕒

We've got createdAt but no updatedAt. In the streets of database design, we usually keep track of both timestamps.

Add this field:

        createdAt: {
          type: Sequelize.DATE,
          allowNull: false,
          defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
        },
+       updatedAt: {
+         type: Sequelize.DATE,
+         allowNull: false,
+         defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
+       },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
createdAt: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
},
createdAt: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
},
updatedAt: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
},

}, { transaction });

// Commit the transaction
await transaction.commit();
} catch (error) {
// Rollback the transaction in case of an error
await transaction.rollback();
throw error;
}
},

down: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction();
try {
// Drop the guide_logs table
await queryInterface.dropTable(TABLE_NAME, { transaction });

// Commit the transaction
await transaction.commit();
} catch (error) {
// Rollback the transaction in case of an error
await transaction.rollback();
throw error;
}
}
};
68 changes: 68 additions & 0 deletions backend/migrations/0001-1.0-helperlink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
'use strict';

const TABLE_NAME = 'helper_link'; // Define the table name

module.exports = {
up: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.createTable(TABLE_NAME, {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
title: {
type: Sequelize.STRING(255),
allowNull: false,
},
headerBackgroundColor: {
type: Sequelize.STRING(7),
allowNull: false,
defaultValue : '#F8F9F8'
},
linkFontColor: {
type: Sequelize.STRING(7),
allowNull: false,
defaultValue : '#344054'
},
iconColor: {
type: Sequelize.STRING(7),
allowNull: false,
defaultValue: '#7F56D9'
},
createdBy: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: 'users',
key: 'id'
}
}
}, { transaction });
Comment on lines +9 to +43
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

There's timestamps missing on his sweater already 🕒

The table lacks created_at and updated_at timestamps which are crucial for auditing and data management.

Add these fields to the table definition:

       createdBy: {
         type: Sequelize.INTEGER,
         allowNull: false,
         references: {
           model: 'users',
           key: 'id'
         }
-      }
+      },
+      created_at: {
+        allowNull: false,
+        type: Sequelize.DATE,
+        defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
+      },
+      updated_at: {
+        allowNull: false,
+        type: Sequelize.DATE,
+        defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
+      }
     }, { transaction });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
await queryInterface.createTable(TABLE_NAME, {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
title: {
type: Sequelize.STRING(255),
allowNull: false,
},
headerBackgroundColor: {
type: Sequelize.STRING(7),
allowNull: false,
defaultValue : '#F8F9F8'
},
linkFontColor: {
type: Sequelize.STRING(7),
allowNull: false,
defaultValue : '#344054'
},
iconColor: {
type: Sequelize.STRING(7),
allowNull: false,
defaultValue: '#7F56D9'
},
createdBy: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: 'users',
key: 'id'
}
}
}, { transaction });
await queryInterface.createTable(TABLE_NAME, {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
title: {
type: Sequelize.STRING(255),
allowNull: false,
},
headerBackgroundColor: {
type: Sequelize.STRING(7),
allowNull: false,
defaultValue : '#F8F9F8'
},
linkFontColor: {
type: Sequelize.STRING(7),
allowNull: false,
defaultValue : '#344054'
},
iconColor: {
type: Sequelize.STRING(7),
allowNull: false,
defaultValue: '#7F56D9'
},
createdBy: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: 'users',
key: 'id'
}
},
created_at: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
},
updated_at: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
}
}, { transaction });


// Commit the transaction
await transaction.commit();
} catch (error) {
// Rollback the transaction in case of an error
await transaction.rollback();
throw error;
}
},

down: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction();
try {
// Drop the guide_logs table
await queryInterface.dropTable(TABLE_NAME, { transaction });

// Commit the transaction
await transaction.commit();
} catch (error) {
// Rollback the transaction in case of an error
await transaction.rollback();
throw error;
}
}
};
68 changes: 68 additions & 0 deletions backend/migrations/0003-1.0-link.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
'use strict';

const TABLE_NAME = 'link'; // Define the table name

module.exports = {
up: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.createTable(TABLE_NAME, {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
},
title: {
type: Sequelize.STRING(255),
allowNull: false,
},
url: {
type: Sequelize.STRING(255),
allowNull: false,
},
order: {
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 1,
},
target: {
type: Sequelize.BOOLEAN,
defaultValue: true,
allowNull: true,
},
Comment on lines +28 to +32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Nervous about that nullable 'target' field with a default value! 😰

There's vomit on his sweater already... I mean, having both defaultValue: true and allowNull: true is like putting two different sauces on your spaghetti - it's confusing! If we have a default value, we probably don't need to allow NULL values.

  target: {
    type: Sequelize.BOOLEAN,
    defaultValue: true,
-   allowNull: true,
+   allowNull: false,
  },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
target: {
type: Sequelize.BOOLEAN,
defaultValue: true,
allowNull: true,
},
target: {
type: Sequelize.BOOLEAN,
defaultValue: true,
allowNull: false,
},

helperId: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: "helper_link",
key: "id",
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
},
}, { transaction });
Comment on lines +9 to +43
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Lost yourself in the moment? You better never let timestamps go! 🎤

The table's missing createdAt and updatedAt timestamp fields. These are essential for tracking when records are modified, like keeping track of how long mom's spaghetti has been in the fridge.

Add these fields to the table definition:

  helperId: {
    // ... existing field definition
  },
+ createdAt: {
+   type: Sequelize.DATE,
+   allowNull: false,
+ },
+ updatedAt: {
+   type: Sequelize.DATE,
+   allowNull: false,
+ },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
await queryInterface.createTable(TABLE_NAME, {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
},
title: {
type: Sequelize.STRING(255),
allowNull: false,
},
url: {
type: Sequelize.STRING(255),
allowNull: false,
},
order: {
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 1,
},
target: {
type: Sequelize.BOOLEAN,
defaultValue: true,
allowNull: true,
},
helperId: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: "helper_link",
key: "id",
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
},
}, { transaction });
await queryInterface.createTable(TABLE_NAME, {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
},
title: {
type: Sequelize.STRING(255),
allowNull: false,
},
url: {
type: Sequelize.STRING(255),
allowNull: false,
},
order: {
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 1,
},
target: {
type: Sequelize.BOOLEAN,
defaultValue: true,
allowNull: true,
},
helperId: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: "helper_link",
key: "id",
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
},
createdAt: {
type: Sequelize.DATE,
allowNull: false,
},
updatedAt: {
type: Sequelize.DATE,
allowNull: false,
},
}, { transaction });


// Commit the transaction
await transaction.commit();
} catch (error) {
// Rollback the transaction in case of an error
await transaction.rollback();
throw error;
}
},

down: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction();
try {
// Drop the guide_logs table
await queryInterface.dropTable(TABLE_NAME, { transaction });

// Commit the transaction
await transaction.commit();
} catch (error) {
// Rollback the transaction in case of an error
await transaction.rollback();
throw error;
}
}
};
67 changes: 67 additions & 0 deletions backend/migrations/0004-1.0-tokens.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'use strict';

const TABLE_NAME = 'tokens'; // Define the table name

module.exports = {
up: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.createTable(TABLE_NAME, {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
allowNull: false,
},
token: {
type: Sequelize.STRING(500),
allowNull: false,
},
userId: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: 'users',
key: 'id'
}
},
type: {
type: Sequelize.STRING(10),
allowNull: false,
},
expiresAt: {
type: Sequelize.DATE,
allowNull: true,
},
createdAt: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
},

}, { transaction });
Comment on lines +9 to +42
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

🛠️ Refactor suggestion

Yo dawg, I take back some of that spaghetti! 🍝

After diving deep into the codebase (palms still sweaty), I see some of my suggestions were off base, but here's what's still cookin':

  1. Add an index on the token field (make it unique if tokens should be unique):
+ await queryInterface.addIndex(TABLE_NAME, ['token'], {
+   transaction,
+   unique: true,  // Remove if tokens can be duplicated
+ });

The other stuff I mentioned? Forget about it! The foreign key's already got that sweet CASCADE action, and the timestamp setup matches the project's pattern. We good!

🔗 Analysis chain

Mom's spaghetti time - let's beef up this schema! 🍝

Yo, the table structure is solid, but we could make it even better:

  1. Add indexes for performance:
    • Token field (likely used for lookups)
    • userId (foreign key)
  2. Add updatedAt timestamp for better auditing
  3. Specify foreign key behavior

Here's the heat 🔥:

 await queryInterface.createTable(TABLE_NAME, {
   // ... existing fields ...
   createdAt: {
     type: Sequelize.DATE,
     allowNull: false,
     defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
   },
+  updatedAt: {
+    type: Sequelize.DATE,
+    allowNull: false,
+    defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
+  },
 }, { transaction });

+ await queryInterface.addIndex(TABLE_NAME, ['token'], {
+   transaction,
+   unique: true,
+ });
+
+ await queryInterface.addIndex(TABLE_NAME, ['userId'], {
+   transaction,
+ });

Also, consider adding onDelete and onUpdate behavior to the foreign key. What should happen to tokens when a user is deleted? 🤔

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Find model definitions and related files
echo "=== Looking for model definitions ==="
fd -e js -e ts "token|user" --type f

echo -e "\n=== Searching for migrations ==="
fd -e js "migrations" --type f

echo -e "\n=== Looking for token-related code ==="
rg -l "token" --type js --type ts

echo -e "\n=== Checking for existing indexes ==="
rg "addIndex.*token" --type js

Length of output: 1621


Script:

#!/bin/bash
# Check model definitions and users migration
echo "=== Token Model Definition ==="
cat backend/src/models/Token.js

echo -e "\n=== User Model Definition ==="
cat backend/src/models/User.js

echo -e "\n=== Users Migration ==="
cat backend/migrations/0000-1.0-users.js

Length of output: 4442


// Commit the transaction
await transaction.commit();
} catch (error) {
// Rollback the transaction in case of an error
await transaction.rollback();
throw error;
}
},

down: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction();
try {
// Drop the guide_logs table
await queryInterface.dropTable(TABLE_NAME, { transaction });

// Commit the transaction
await transaction.commit();
} catch (error) {
// Rollback the transaction in case of an error
await transaction.rollback();
throw error;
}
}
};
83 changes: 83 additions & 0 deletions backend/migrations/0005-1.0-banner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
'use strict';

const TABLE_NAME = 'banners'; // Define the table name

module.exports = {
up: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.createTable(TABLE_NAME, {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
closeButtonAction: {
type: Sequelize.STRING(255),
allowNull: false
Comment on lines +17 to +18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Yo, these string lengths got me nervous! 😰

All columns are using VARCHAR(255) without considering actual data requirements. We should adjust these based on actual needs:

  • closeButtonAction: Probably needs less than 255 chars
  • repetitionType: Could be an ENUM since it has predefined values
  • position: Could be an ENUM (top, bottom, etc.)
  • url and actionUrl: Consider using TEXT for longer URLs

Here's a suggested fix:

 closeButtonAction: {
-  type: Sequelize.STRING(255),
+  type: Sequelize.STRING(50),
   allowNull: false
 },
 repetitionType: {
-  type: Sequelize.STRING(255),
+  type: Sequelize.ENUM('show only once', 'show always'),
   allowNull: false,
   defaultValue: 'show only once'
 },
 position: {
-  type: Sequelize.STRING(255),
+  type: Sequelize.ENUM('top', 'bottom', 'middle'),
   allowNull: false
 },

Also applies to: 21-22, 26-27, 30-31, 34-35, 39-40, 44-45, 49-50

},
repetitionType: {
type: Sequelize.STRING(255),
allowNull: false,
defaultValue: 'show only once'
},
position: {
type: Sequelize.STRING(255),
allowNull: false
},
url: {
type: Sequelize.STRING(255),
allowNull: true
},
fontColor: {
type: Sequelize.STRING(255),
allowNull: false,
defaultValue: "#FFFFFF"
},
Comment on lines +36 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

These default colors making me weak in the knees! 🎨

Default white (#FFFFFF) for both font and background color would make the text invisible! We should set contrasting defaults.

 fontColor: {
   type: Sequelize.STRING(255),
   allowNull: false,
-  defaultValue: "#FFFFFF"
+  defaultValue: "#000000"
 },
 backgroundColor: {
   type: Sequelize.STRING(255),
   allowNull: false,
-  defaultValue: "#FFFFFF"
+  defaultValue: "#F5F5F5"
 },

Also applies to: 41-42

backgroundColor: {
type: Sequelize.STRING(255),
allowNull: false,
defaultValue: "#FFFFFF"
},
bannerText: {
type: Sequelize.STRING(255),
allowNull: false,
defaultValue: ""
},
actionUrl: {
type: Sequelize.STRING(255),
allowNull: true
},
createdBy: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: 'users',
key: 'id'
}
}
}, { transaction });
Comment on lines +9 to +60
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Timestamp columns got lost in the sauce! ⏰

We're missing created_at and updated_at columns that are crucial for tracking banner lifecycle.

Add these columns to the table definition:

 createdBy: {
   // ... existing definition
 },
+ created_at: {
+   type: Sequelize.DATE,
+   allowNull: false,
+   defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
+ },
+ updated_at: {
+   type: Sequelize.DATE,
+   allowNull: false,
+   defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
+   onUpdate: Sequelize.literal('CURRENT_TIMESTAMP')
+ }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
await queryInterface.createTable(TABLE_NAME, {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
closeButtonAction: {
type: Sequelize.STRING(255),
allowNull: false
},
repetitionType: {
type: Sequelize.STRING(255),
allowNull: false,
defaultValue: 'show only once'
},
position: {
type: Sequelize.STRING(255),
allowNull: false
},
url: {
type: Sequelize.STRING(255),
allowNull: true
},
fontColor: {
type: Sequelize.STRING(255),
allowNull: false,
defaultValue: "#FFFFFF"
},
backgroundColor: {
type: Sequelize.STRING(255),
allowNull: false,
defaultValue: "#FFFFFF"
},
bannerText: {
type: Sequelize.STRING(255),
allowNull: false,
defaultValue: ""
},
actionUrl: {
type: Sequelize.STRING(255),
allowNull: true
},
createdBy: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: 'users',
key: 'id'
}
}
}, { transaction });
await queryInterface.createTable(TABLE_NAME, {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
closeButtonAction: {
type: Sequelize.STRING(255),
allowNull: false
},
repetitionType: {
type: Sequelize.STRING(255),
allowNull: false,
defaultValue: 'show only once'
},
position: {
type: Sequelize.STRING(255),
allowNull: false
},
url: {
type: Sequelize.STRING(255),
allowNull: true
},
fontColor: {
type: Sequelize.STRING(255),
allowNull: false,
defaultValue: "#FFFFFF"
},
backgroundColor: {
type: Sequelize.STRING(255),
allowNull: false,
defaultValue: "#FFFFFF"
},
bannerText: {
type: Sequelize.STRING(255),
allowNull: false,
defaultValue: ""
},
actionUrl: {
type: Sequelize.STRING(255),
allowNull: true
},
createdBy: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: 'users',
key: 'id'
}
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
},
updated_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
onUpdate: Sequelize.literal('CURRENT_TIMESTAMP')
}
}, { transaction });


// Commit the transaction
await transaction.commit();
} catch (error) {
// Rollback the transaction in case of an error
await transaction.rollback();
throw error;
}
},

down: async (queryInterface, Sequelize) => {
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.dropTable(TABLE_NAME, { transaction });
// Commit the transaction
await transaction.commit();
} catch (error) {
// Rollback the transaction in case of an error
await transaction.rollback();
throw error;
}
}
};
Loading
Loading