text: module.exports = {
    up: async (queryInterface, Sequelize) => {
      /*
        Add altering commands here.
        Return a promise to correctly handle asynchronicity.
  
        Example:
        return queryInterface.createTable('users', { id: Sequelize.INTEGER });
      */
  
      const transaction = await queryInterface.sequelize.transaction();
  
      try {
        await queryInterface.createTable(
          'user_stores',
          {
            id: {
              type: Sequelize.INTEGER,
              allowNull: false,
              autoIncrement: true,
              primaryKey: true,
            },
            user_id: {
              type: Sequelize.INTEGER,
              references: { model: 'users', key: 'id' },
              onUpdate: 'CASCADE',
              onDelete: 'CASCADE',
              allowNull: false,
            },
            store_id: {
              type: Sequelize.INTEGER,
              references: { model: 'stores', key: 'id' },
              onUpdate: 'CASCADE',
              onDelete: 'CASCADE',
              allowNull: false,
            },
            created_at: {
              type: Sequelize.DATE,
              allowNull: false,
            },
            updated_at: {
              type: Sequelize.DATE,
              allowNull: false,
            },
          },
          { transaction },
        );
        await queryInterface.addIndex('user_stores', ['user_id', 'store_id'], {
          transaction,
          unique: true,
        });
        await transaction.commit();
      } catch (error) {
        console.log(error);
        await transaction.rollback();
        throw error;
      }
    },
  
    down: queryInterface => {
      /*
        Add reverting commands here.
        Return a promise to correctly handle asynchronicity.
  
        Example:
        return queryInterface.dropTable('users');
        */
      return queryInterface.dropTable('user_stores');
    },
  };
  