Untitled

 avatar
unknown
plain_text
a year ago
2.5 kB
91
Indexable
// src/sequelize/migrations/YYYYMMDDHHMMSS-create-commande.js
'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    await queryInterface.createTable('commandes', {
      id: {
        type: Sequelize.UUID,
        defaultValue: Sequelize.UUIDV7,
        primaryKey: true
      },
      user_id: {
        type: Sequelize.UUID,
        references: {
          model: 'users',
          key: 'id'
        }
      },
      is_paid: {
        type: Sequelize.BOOLEAN,
        defaultValue: false
      },
      payment_failed_message: {
        type: Sequelize.STRING,
        allowNull: true
      },
      delivery_status: {
        type: Sequelize.ENUM('processing', 'shipping', 'delivered', 'delivery_issue'),
        defaultValue: 'processing'
      },
      created_at: {
        type: Sequelize.DATE,
        allowNull: false,
        defaultValue: Sequelize.fn('now')
      },
      updated_at: {
        type: Sequelize.DATE,
        allowNull: false,
        defaultValue: Sequelize.fn('now')
      }
    });
  },

  down: async (queryInterface, Sequelize) => {
    await queryInterface.dropTable('commandes');
  }
};

// src/sequelize/migrations/YYYYMMDDHHMMSS-create-commande-detail.js
'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    await queryInterface.createTable('commande_details', {
      id: {
        type: Sequelize.UUID,
        defaultValue: Sequelize.UUIDV7,
        primaryKey: true
      },
      commande_id: {
        type: Sequelize.UUID,
        references: {
          model: 'commandes',
          key: 'id'
        }
      },
      price: {
        type: Sequelize.DECIMAL(10, 2),
        allowNull: false
      },
      quantity: {
        type: Sequelize.INTEGER,
        allowNull: false
      },
      image_name: {
        type: Sequelize.STRING,
        allowNull: false
      },
      promotion_name: {
        type: Sequelize.STRING,
        allowNull: true
      },
      promotion_value: {
        type: Sequelize.DECIMAL(5, 2),
        allowNull: true
      },
      created_at: {
        type: Sequelize.DATE,
        allowNull: false,
        defaultValue: Sequelize.fn('now')
      },
      updated_at: {
        type: Sequelize.DATE,
        allowNull: false,
        defaultValue: Sequelize.fn('now')
      }
    });
  },

  down: async (queryInterface, Sequelize) => {
    await queryInterface.dropTable('commande_details');
  }
};
Editor is loading...
Leave a Comment