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} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.dropTable('Users',{cascade:true})
await queryInterface.createTable('Users', {
id: {
allowNull: false,

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

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

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

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

Loading…
Cancel
Save