Sha256: 8462ea7c015b28550abf7d07eb5dc9a2171c80fcda08abbf508de8e7c641048c
Contents?: true
Size: 941 Bytes
Versions: 7
Compression:
Stored size: 941 Bytes
Contents
class CreateSpreePromotionsStores < ActiveRecord::Migration[5.2] def up unless table_exists?(:spree_promotions_stores) create_table :spree_promotions_stores do |t| t.references :promotion, index: true t.references :store, index: true t.timestamps t.index [:promotion_id, :store_id], unique: true end stores = Spree::Store.all promotion_ids = Spree::Promotion.order(:id).ids stores.find_each do |store| prepared_values = promotion_ids.map { |id| "(#{id}, #{store.id}, '#{Time.current.to_s(:db)}', '#{Time.current.to_s(:db)}')" }.join(', ') next if prepared_values.empty? begin execute "INSERT INTO spree_promotions_stores (promotion_id, store_id, created_at, updated_at) VALUES #{prepared_values};" rescue ActiveRecord::RecordNotUnique; end end end end def down drop_table :spree_promotions_stores end end
Version data entries
7 entries across 7 versions & 1 rubygems