mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Add migrations to fix index on category slugs
Slugs can be the empty string, but the added index didn't account for that. This commit changes the migration, stopping it from being unique so that it can be applied everywhere and adds another migration that recreates the index properly.
This commit is contained in:
@@ -5,8 +5,7 @@ class AddUniqueIndexCategoriesOnSlug < ActiveRecord::Migration[6.0]
|
||||
add_index(
|
||||
:categories,
|
||||
'COALESCE(parent_category_id, -1), slug',
|
||||
name: 'unique_index_categories_on_slug',
|
||||
unique: true
|
||||
name: 'unique_index_categories_on_slug'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
15
db/migrate/20191016124059_fix_category_slugs_index.rb
Normal file
15
db/migrate/20191016124059_fix_category_slugs_index.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class FixCategorySlugsIndex < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
remove_index(:categories, name: 'unique_index_categories_on_slug')
|
||||
|
||||
add_index(
|
||||
:categories,
|
||||
'COALESCE(parent_category_id, -1), slug',
|
||||
name: 'unique_index_categories_on_slug',
|
||||
where: "slug != ''",
|
||||
unique: true
|
||||
)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user