sequelize / cli

The Sequelize CLI
MIT License
2.53k stars 528 forks source link

BulkInsert "relation does not exist" in migration script #1377

Open yourinium opened 1 year ago

yourinium commented 1 year ago

Issue Creation Checklist

Bug Description

I have created a migration script that creates a table and then bulk inserts a bunch of values. The CreateTable statement works no problem but when it comes to inserting the data it keeps telling me that the relation does not exist and I have tried everything to try and get around that to no avail.

Reproducible Example

// sequelize script migration to create the lookup-google-places-types table
module.exports = {
  up: async (queryInterface, Sequelize) => {
    await queryInterface.sequelize.transaction(async (t) => {
      await queryInterface.createTable(
        'lookup__google_places_types',
        {
          place_type: {
            type: Sequelize.STRING,
            primaryKey: true,
          },
          report_type: {
            type: Sequelize.STRING,
            allowNull: false,
          },
          google_reviews: {
            type: Sequelize.BOOLEAN,
            defaultValue: false,
          },
          contacts: {
            type: Sequelize.BOOLEAN,
            defaultValue: false,
          },
          social_links: {
            type: Sequelize.BOOLEAN,
            defaultValue: false,
          },
          competitors_map: {
            type: Sequelize.BOOLEAN,
            defaultValue: false,
          },
          created_at: {
            allowNull: false,
            type: Sequelize.DATE,
            defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
          },
          updated_at: {
            allowNull: false,
            type: Sequelize.DATE,
            defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
          },
          deleted_at: {
            type: Sequelize.DATE,
          },
        },
        {
          schema: 'backend',
          transaction: t,
        }
      );

      // Insert statements for lookup__google_places_types to fill in place_type and report_type with a series of tuples
      // example being ('accounting', 'full') or ('airport', 'plus')
      await queryInterface.bulkInsert(
        {
          tableName: 'lookup__google_places_types',
          schema: 'backend',
          transaction: t,
        },
        [
          {
            place_type: 'accounting',
            report_type: 'full',
          },
          {
            place_type: 'airport',
            report_type: 'plus',
          },
          {
            place_type: 'amusement_park',
            report_type: 'full',
          },
          {
            place_type: 'aquarium',
            report_type: 'full',
          },
          {
            place_type: 'art_gallery',
            report_type: 'full',
          },
          {
            place_type: 'atm',
            report_type: 'plus',
          },
          {
            place_type: 'bakery',
            report_type: 'full',
          },
          {
            place_type: 'bank',
            report_type: 'full',
          },
          {
            place_type: 'bar',
            report_type: 'full',
          },
          {
            place_type: 'beauty_salon',
            report_type: 'full',
          },
          {
            place_type: 'bicycle_store',
            report_type: 'full',
          },
          {
            place_type: 'book_store',
            report_type: 'full',
          },
          {
            place_type: 'bowling_alley',
            report_type: 'full',
          },
          {
            place_type: 'bus_station',
            report_type: 'plus',
          },
          {
            place_type: 'cafe',
            report_type: 'full',
          },
          {
            place_type: 'campground',
            report_type: 'full',
          },
          {
            place_type: 'car_dealer',
            report_type: 'full',
          },
          {
            place_type: 'car_rental',
            report_type: 'full',
          },
          {
            place_type: 'car_repair',
            report_type: 'full',
          },
          {
            place_type: 'car_wash',
            report_type: 'full',
          },
          {
            place_type: 'casino',
            report_type: 'full',
          },
          {
            place_type: 'cemetery',
            report_type: 'full',
          },
          {
            place_type: 'church',
            report_type: 'thin',
          },
          {
            place_type: 'city_hall',
            report_type: 'thin',
          },
          {
            place_type: 'clothing_store',
            report_type: 'full',
          },
          {
            place_type: 'convenience_store',
            report_type: 'full',
          },
          {
            place_type: 'courthouse',
            report_type: 'thin',
          },
          {
            place_type: 'dentist',
            report_type: 'full',
          },
          {
            place_type: 'department_store',
            report_type: 'full',
          },
          {
            place_type: 'doctor',
            report_type: 'full',
          },
          {
            place_type: 'drugstore',
            report_type: 'full',
          },
          {
            place_type: 'electrician',
            report_type: 'full',
          },
          {
            place_type: 'electronics_store',
            report_type: 'full',
          },
          {
            place_type: 'embassy',
            report_type: 'thin',
          },
          {
            place_type: 'fire_station',
            report_type: 'thin',
          },
          {
            place_type: 'florist',
            report_type: 'full',
          },
          {
            place_type: 'funeral_home',
            report_type: 'full',
          },
          {
            place_type: 'furniture_store',
            report_type: 'full',
          },
          {
            place_type: 'gas_station',
            report_type: 'full',
          },
          {
            place_type: 'gym',
            report_type: 'full',
          },
          {
            place_type: 'hair_care',
            report_type: 'full',
          },
          {
            place_type: 'hardware_store',
            report_type: 'full',
          },
          {
            place_type: 'hindu_temple',
            report_type: 'thin',
          },
          {
            place_type: 'home_goods_store',
            report_type: 'full',
          },
          {
            place_type: 'hospital',
            report_type: 'full',
          },
          {
            place_type: 'insurance_agency',
            report_type: 'full',
          },
          {
            place_type: 'jewelry_store',
            report_type: 'full',
          },
          {
            place_type: 'laundry',
            report_type: 'full',
          },
          {
            place_type: 'lawyer',
            report_type: 'full',
          },
          {
            place_type: 'library',
            report_type: 'plus',
          },
          {
            place_type: 'light_rail_station',
            report_type: 'plus',
          },
          {
            place_type: 'liquor_store',
            report_type: 'full',
          },
          {
            place_type: 'local_government_office',
            report_type: 'thin',
          },
          {
            place_type: 'locksmith',
            report_type: 'full',
          },
          {
            place_type: 'lodging',
            report_type: 'full',
          },
          {
            place_type: 'meal_delivery',
            report_type: 'full',
          },
          {
            place_type: 'meal_takeaway',
            report_type: 'full',
          },
          {
            place_type: 'mosque',
            report_type: 'thin',
          },
          {
            place_type: 'movie_rental',
            report_type: 'full',
          },
          {
            place_type: 'movie_theater',
            report_type: 'full',
          },
          {
            place_type: 'moving_company',
            report_type: 'full',
          },
          {
            place_type: 'museum',
            report_type: 'full',
          },
          {
            place_type: 'night_club',
            report_type: 'full',
          },
          {
            place_type: 'painter',
            report_type: 'full',
          },
          {
            place_type: 'park',
            report_type: 'plus',
          },
          {
            place_type: 'parking',
            report_type: 'full',
          },
          {
            place_type: 'pet_store',
            report_type: 'full',
          },
          {
            place_type: 'pharmacy',
            report_type: 'full',
          },
          {
            place_type: 'physiotherapist',
            report_type: 'full',
          },
          {
            place_type: 'plumber',
            report_type: 'full',
          },
          {
            place_type: 'police',
            report_type: 'thin',
          },
          {
            place_type: 'post_office',
            report_type: 'plus',
          },
          {
            place_type: 'primary_school',
            report_type: 'plus',
          },
          {
            place_type: 'real_estate_agency',
            report_type: 'full',
          },
          {
            place_type: 'restaurant',
            report_type: 'full',
          },
          {
            place_type: 'roofing_contractor',
            report_type: 'full',
          },
          {
            place_type: 'rv_park',
            report_type: 'full',
          },
          {
            place_type: 'school',
            report_type: 'plus',
          },
          {
            place_type: 'secondary_school',
            report_type: 'plus',
          },
          {
            place_type: 'shoe_store',
            report_type: 'full',
          },
          {
            place_type: 'shopping_mall',
            report_type: 'full',
          },
          {
            place_type: 'spa',
            report_type: 'full',
          },
          {
            place_type: 'stadium',
            report_type: 'plus',
          },
          {
            place_type: 'storage',
            report_type: 'full',
          },
          {
            place_type: 'store',
            report_type: 'full',
          },
          {
            place_type: 'subway_station',
            report_type: 'plus',
          },
          {
            place_type: 'supermarket',
            report_type: 'full',
          },
          {
            place_type: 'synagogue',
            report_type: 'thin',
          },
          {
            place_type: 'taxi_stand',
            report_type: 'full',
          },
          {
            place_type: 'tourist_attraction',
            report_type: 'full',
          },
          {
            place_type: 'train_station',
            report_type: 'plus',
          },
          {
            place_type: 'transit_station',
            report_type: 'plus',
          },
          {
            place_type: 'travel_agency',
            report_type: 'full',
          },
          {
            place_type: 'university',
            report_type: 'full',
          },
          {
            place_type: 'veterinary_care',
            report_type: 'full',
          },
          {
            place_type: 'zoo',
            report_type: 'full',
          },
        ],
        {}
      );
    });
  },
  down: async (queryInterface, Sequelize) => {
    await queryInterface.dropTable('lookup__google_places_types');
  },
};

What do you expect to happen?

Table should be created and the records inserted!

What is actually happening?

image

Environment

Would you be willing to resolve this issue by submitting a Pull Request?


Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.