Update Migrations to Include Commented-Out Orphaned Record Query

This commit is contained in:
Neal Chambers
2023-10-02 10:14:41 +09:00
parent 2d6784b88d
commit fd8e94cb50
27 changed files with 180 additions and 76 deletions

View File

@@ -1,6 +0,0 @@
class AddForeignKeyToSpreeStockMovementsSpreeStockItems < ActiveRecord::Migration[6.0]
def change
add_foreign_key :spree_stock_movements, :spree_stock_items, column: :stock_item_id
end
end

View File

@@ -1,5 +0,0 @@
class AddForeignKeyToTagRulesEnterprises < ActiveRecord::Migration[6.0]
def change
add_foreign_key :enterprises, :spree_addresses, column: :business_address_id
end
end

View File

@@ -1,5 +0,0 @@
class AddForeignKeyToInventoryItemsEnterprises < ActiveRecord::Migration[6.0]
def change
add_foreign_key :inventory_items, :enterprises, column: :enterprise_id, on_delete: :cascade
end
end

View File

@@ -1,5 +0,0 @@
class AddForeignKeyToInventoryItemsSpreeVariants < ActiveRecord::Migration[6.0]
def change
add_foreign_key :inventory_items, :spree_variants, column: :variant_id, on_delete: :cascade
end
end

View File

@@ -1,5 +0,0 @@
class AddForeignKeyToReportRenderingOptionsSpreeUsers < ActiveRecord::Migration[6.0]
def change
add_foreign_key :report_rendering_options, :spree_users, column: :user_id, on_delete: :cascade
end
end

View File

@@ -1,5 +0,0 @@
class AddForeignKeyToSpreeShipmentsSpreeStockLocations < ActiveRecord::Migration[6.0]
def change
add_foreign_key :spree_shipments, :spree_stock_locations, column: :stock_location_id
end
end

View File

@@ -1,5 +0,0 @@
class AddForeignKeyToSpreeShippingMethodCategoriesSpreeShippingCategories < ActiveRecord::Migration[6.0]
def change
add_foreign_key :spree_shipping_method_categories, :spree_shipping_categories, column: :shipping_category_id, on_delete: :cascade
end
end

View File

@@ -1,5 +0,0 @@
class AddForeignKeyToSpreeShippingMethodCategoriesSpreeShippingMethods < ActiveRecord::Migration[6.0]
def change
add_foreign_key :spree_shipping_method_categories, :spree_shipping_methods, column: :shipping_method_id, on_delete: :cascade
end
end

View File

@@ -1,5 +0,0 @@
class AddForeignKeyToSpreeStockItemsSpreeStockLocations < ActiveRecord::Migration[6.0]
def change
add_foreign_key :spree_stock_items, :spree_stock_locations, column: :stock_location_id
end
end

View File

@@ -1,5 +0,0 @@
class AddForeignKeyToSpreeStockItemsSpreeVariants < ActiveRecord::Migration[6.0]
def change
add_foreign_key :spree_stock_items, :spree_variants, column: :variant_id
end
end

View File

@@ -1,5 +0,0 @@
class AddForeignKeyToSpreeStockLocationsSpreeCountries < ActiveRecord::Migration[6.0]
def change
add_foreign_key :spree_stock_locations, :spree_countries, column: :country_id
end
end

View File

@@ -1,5 +0,0 @@
class AddForeignKeyToSpreeStockLocationsSpreeStates < ActiveRecord::Migration[6.0]
def change
add_foreign_key :spree_stock_locations, :spree_states, column: :state_id
end
end

View File

@@ -1,5 +0,0 @@
class AddForeignKeyToSpreeStockMovementsSpreeStockItems < ActiveRecord::Migration[6.0]
def change
add_foreign_key :spree_stock_movements, :spree_stock_items, column: :stock_item_id
end
end

View File

@@ -1,5 +0,0 @@
class AddForeignKeyToStripeAccountsEnterprises < ActiveRecord::Migration[6.0]
def change
add_foreign_key :stripe_accounts, :enterprises, column: :enterprise_id
end
end

View File

@@ -1,5 +0,0 @@
class AddForeignKeyToTagRulesEnterprises < ActiveRecord::Migration[6.0]
def change
add_foreign_key :tag_rules, :enterprises, column: :enterprise_id
end
end

View File

@@ -0,0 +1,15 @@
# Orphaned records can be found before running this migration with the following SQL:
# SELECT COUNT(*)
# FROM spree_stock_items
# LEFT JOIN spree_stock_locations
# ON spree_stock_items.stock_location_id = spree_stock_locations.id
# WHERE spree_stock_locations.id IS NULL
# AND spree_stock_items.stock_location_id IS NOT NULL
class AddForeignKeyToSpreeStockItemsSpreeStockLocations < ActiveRecord::Migration[6.0]
def change
add_foreign_key :spree_stock_items, :spree_stock_locations, column: :stock_location_id
end
end

View File

@@ -0,0 +1,15 @@
# Orphaned records can be found before running this migration with the following SQL:
# SELECT COUNT(*)
# FROM spree_stock_items
# LEFT JOIN spree_variants
# ON spree_stock_items.variant_id = spree_variants.id
# WHERE spree_variants.id IS NULL
# AND spree_stock_items.variant_id IS NOT NULL
class AddForeignKeyToSpreeStockItemsSpreeVariants < ActiveRecord::Migration[6.0]
def change
add_foreign_key :spree_stock_items, :spree_variants, column: :variant_id
end
end

View File

@@ -0,0 +1,15 @@
# Orphaned records can be found before running this migration with the following SQL:
# SELECT COUNT(*)
# FROM spree_shipping_method_categories
# LEFT JOIN spree_shipping_methods
# ON spree_shipping_method_categories.shipping_method_id = spree_shipping_methods.id
# WHERE spree_shipping_methods.id IS NULL
# AND spree_shipping_method_categories.shipping_method_id IS NOT NULL
class AddForeignKeyToSpreeShippingMethodCategoriesSpreeShippingMethods < ActiveRecord::Migration[6.0]
def change
add_foreign_key :spree_shipping_method_categories, :spree_shipping_methods, column: :shipping_method_id
end
end

View File

@@ -0,0 +1,15 @@
# Orphaned records can be found before running this migration with the following SQL:
# SELECT COUNT(*)
# FROM spree_shipping_method_categories
# LEFT JOIN spree_shipping_categories
# ON spree_shipping_method_categories.shipping_category_id = spree_shipping_categories.id
# WHERE spree_shipping_categories.id IS NULL
# AND spree_shipping_method_categories.shipping_category_id IS NOT NULL
class AddForeignKeyToSpreeShippingMethodCategoriesSpreeShippingCategories < ActiveRecord::Migration[6.0]
def change
add_foreign_key :spree_shipping_method_categories, :spree_shipping_categories, column: :shipping_category_id
end
end

View File

@@ -0,0 +1,15 @@
# Orphaned records can be found before running this migration with the following SQL:
# SELECT COUNT(*)
# FROM report_rendering_options
# LEFT JOIN spree_users
# ON report_rendering_options.user_id = spree_users.id
# WHERE spree_users.id IS NULL
# AND report_rendering_options.user_id IS NOT NULL
class AddForeignKeyToReportRenderingOptionsSpreeUsers < ActiveRecord::Migration[6.0]
def change
add_foreign_key :report_rendering_options, :spree_users, column: :user_id
end
end

View File

@@ -0,0 +1,15 @@
# Orphaned records can be found before running this migration with the following SQL:
# SELECT COUNT(*)
# FROM tag_rules
# LEFT JOIN enterprises
# ON tag_rules.enterprise_id = enterprises.id
# WHERE enterprises.id IS NULL
# AND tag_rules.enterprise_id IS NOT NULL
class AddForeignKeyToTagRulesEnterprises < ActiveRecord::Migration[6.0]
def change
add_foreign_key :tag_rules, :enterprises, column: :enterprise_id
end
end

View File

@@ -0,0 +1,15 @@
# Orphaned records can be found before running this migration with the following SQL:
# SELECT COUNT(*)
# FROM spree_stock_movements
# LEFT JOIN spree_stock_items
# ON spree_stock_movements.stock_item_id = spree_stock_items.id
# WHERE spree_stock_items.id IS NULL
# AND spree_stock_movements.stock_item_id IS NOT NULL
class AddForeignKeyToSpreeStockMovementsSpreeStockItems < ActiveRecord::Migration[6.0]
def change
add_foreign_key :spree_stock_movements, :spree_stock_items, column: :stock_item_id
end
end

View File

@@ -0,0 +1,15 @@
# Orphaned records can be found before running this migration with the following SQL:
# SELECT COUNT(*)
# FROM spree_stock_locations
# LEFT JOIN spree_states
# ON spree_stock_locations.state_id = spree_states.id
# WHERE spree_states.id IS NULL
# AND spree_stock_locations.state_id IS NOT NULL
class AddForeignKeyToSpreeStockLocationsSpreeStates < ActiveRecord::Migration[6.0]
def change
add_foreign_key :spree_stock_locations, :spree_states, column: :state_id
end
end

View File

@@ -0,0 +1,15 @@
# Orphaned records can be found before running this migration with the following SQL:
# SELECT COUNT(*)
# FROM spree_stock_locations
# LEFT JOIN spree_countries
# ON spree_stock_locations.country_id = spree_countries.id
# WHERE spree_countries.id IS NULL
# AND spree_stock_locations.country_id IS NOT NULL
class AddForeignKeyToSpreeStockLocationsSpreeCountries < ActiveRecord::Migration[6.0]
def change
add_foreign_key :spree_stock_locations, :spree_countries, column: :country_id
end
end

View File

@@ -0,0 +1,15 @@
# Orphaned records can be found before running this migration with the following SQL:
# SELECT COUNT(*)
# FROM spree_shipments
# LEFT JOIN spree_stock_locations
# ON spree_shipments.stock_location_id = spree_stock_locations.id
# WHERE spree_stock_locations.id IS NULL
# AND spree_shipments.stock_location_id IS NOT NULL
class AddForeignKeyToSpreeShipmentsSpreeStockLocations < ActiveRecord::Migration[6.0]
def change
add_foreign_key :spree_shipments, :spree_stock_locations, column: :stock_location_id
end
end

View File

@@ -0,0 +1,15 @@
# Orphaned records can be found before running this migration with the following SQL:
# SELECT COUNT(*)
# FROM inventory_items
# LEFT JOIN enterprises
# ON inventory_items.enterprise_id = enterprises.id
# WHERE enterprises.id IS NULL
# AND inventory_items.enterprise_id IS NOT NULL
class AddForeignKeyToInventoryItemsEnterprises < ActiveRecord::Migration[6.0]
def change
add_foreign_key :inventory_items, :enterprises, column: :enterprise_id
end
end

View File

@@ -0,0 +1,15 @@
# Orphaned records can be found before running this migration with the following SQL:
# SELECT COUNT(*)
# FROM inventory_items
# LEFT JOIN spree_variants
# ON inventory_items.variant_id = spree_variants.id
# WHERE spree_variants.id IS NULL
# AND inventory_items.variant_id IS NOT NULL
class AddForeignKeyToInventoryItemsSpreeVariants < ActiveRecord::Migration[6.0]
def change
add_foreign_key :inventory_items, :spree_variants, column: :variant_id
end
end