Enhance schema migration files

master
nicekid1 2 months ago
parent 35521f8e0c
commit 122bbacc0d
  1. 1
      migrations/20250104074851-create-user.js
  2. 2
      migrations/20250104094702-create-admin.js
  3. 8
      migrations/20250104112403-create-product.js
  4. 2
      migrations/20250105063054-create-cart.js
  5. 40
      migrations/20250105085732-create-invoice.js

@ -3,6 +3,7 @@
/** @type {import('sequelize-cli').Migration} */ /** @type {import('sequelize-cli').Migration} */
module.exports = { module.exports = {
async up(queryInterface, Sequelize) { async up(queryInterface, Sequelize) {
await queryInterface.dropTable('Users',{cascade:true})
await queryInterface.createTable('Users', { await queryInterface.createTable('Users', {
id: { id: {
allowNull: false, allowNull: false,

@ -2,6 +2,8 @@
module.exports = { module.exports = {
up: async (queryInterface, Sequelize) => { up: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('Admins', { cascade: true });
await queryInterface.createTable('Admins', { await queryInterface.createTable('Admins', {
id: { id: {
allowNull: false, allowNull: false,

@ -1,8 +1,10 @@
'use strict'; "use strict";
module.exports = { module.exports = {
up: async (queryInterface, Sequelize) => { up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('Products', { await queryInterface.dropTable("Products", { cascade: true });
await queryInterface.createTable("Products", {
id: { id: {
type: Sequelize.INTEGER, type: Sequelize.INTEGER,
allowNull: false, allowNull: false,
@ -60,6 +62,6 @@ module.exports = {
}, },
down: async (queryInterface, Sequelize) => { down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('Products'); await queryInterface.dropTable("Products");
}, },
}; };

@ -2,6 +2,8 @@
module.exports = { module.exports = {
up: async (queryInterface, Sequelize) => { up: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('Carts', { cascade: true });
await queryInterface.createTable('Carts', { await queryInterface.createTable('Carts', {
id: { id: {
type: Sequelize.INTEGER, type: Sequelize.INTEGER,

@ -2,12 +2,14 @@
module.exports = { module.exports = {
up: async (queryInterface, Sequelize) => { up: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('Invoices', { cascade: true });
await queryInterface.createTable('Invoices', { await queryInterface.createTable('Invoices', {
id: { id: {
type: Sequelize.INTEGER, type: Sequelize.INTEGER,
allowNull: false,
autoIncrement: true, autoIncrement: true,
primaryKey: true, primaryKey: true,
allowNull: false,
}, },
userId: { userId: {
type: Sequelize.INTEGER, type: Sequelize.INTEGER,
@ -18,36 +20,58 @@ module.exports = {
}, },
onDelete: 'CASCADE', onDelete: 'CASCADE',
}, },
firstName: {
type: Sequelize.STRING,
allowNull: false,
},
lastName: {
type: Sequelize.STRING,
allowNull: false,
},
phoneNumber: {
type: Sequelize.STRING,
allowNull: false,
},
email: {
type: Sequelize.STRING,
allowNull: false,
unique: false,
},
totalAmount: { totalAmount: {
type: Sequelize.FLOAT,
allowNull: true,
},
productId: {
type: Sequelize.INTEGER, type: Sequelize.INTEGER,
allowNull: false, allowNull: false,
}, },
products: { quantity: {
type: Sequelize.JSON, type: Sequelize.INTEGER,
allowNull: false, allowNull: false,
}, },
paymentStatus: { price: {
type: Sequelize.STRING, type: Sequelize.DECIMAL(10, 2),
allowNull: false, allowNull: false,
}, },
refId: { productName: {
type: Sequelize.STRING, type: Sequelize.STRING,
allowNull: false, allowNull: false,
}, },
createdAt: { createdAt: {
type: Sequelize.DATE, type: Sequelize.DATE,
allowNull: false, allowNull: false,
defaultValue: Sequelize.NOW, defaultValue: Sequelize.fn('NOW'),
}, },
updatedAt: { updatedAt: {
type: Sequelize.DATE, type: Sequelize.DATE,
allowNull: false, allowNull: false,
defaultValue: Sequelize.NOW, defaultValue: Sequelize.fn('NOW'),
}, },
}); });
}, },
down: async (queryInterface, Sequelize) => { down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('Invoices'); await queryInterface.dropTable('Invoices');
}, },
}; };

Loading…
Cancel
Save