20250517052533-cart.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use strict';
  2. /** @type {import('sequelize-cli').Migration} */
  3. module.exports = {
  4. async up (queryInterface, Sequelize) {
  5. await queryInterface.createTable('Cart', {
  6. id: {
  7. allowNull: false,
  8. autoIncrement: true,
  9. primaryKey: true,
  10. type: Sequelize.DataTypes.INTEGER
  11. },
  12. menuItemId: {
  13. type: Sequelize.DataTypes.INTEGER,
  14. allowNull: false,
  15. comment: 'для внешнего ключа'
  16. },
  17. quantity: {
  18. type: Sequelize.DataTypes.INTEGER,
  19. allowNull: false,
  20. comment: 'количество'
  21. }
  22. })
  23. /**
  24. * Внешний ключ корзина_блюдо
  25. */
  26. await queryInterface.addConstraint('Cart', {
  27. fields: ['menuItemId'],
  28. type: 'foreign key',
  29. name: 'FK_cart_menu-item',
  30. references: {
  31. table: 'MenuItem',
  32. field: 'id'
  33. },
  34. onDelete: 'no action',
  35. onUpdate: 'no action'
  36. })
  37. },
  38. async down (queryInterface, Sequelize) {
  39. await queryInterface.removeConstraint('Cart', 'FK_cart_menu-item')
  40. await queryInterface.dropTable('Cart')
  41. }
  42. }