FIX: Fix incorrect hashtag setting migration (#19857)

Added in c2013865d7,
this migration was supposed to only turn off the hashtag
setting for existing sites (since that was the old default)
but its doing it for new ones too because we run all migrations
on new sites.

Instead, we should only run this if the first migration was
only just created, meaning its a new site.
This commit is contained in:
Martin Brennan 2023-01-16 10:53:00 +10:00 committed by Bianca Nenciu
parent 0d4a27bd96
commit 273d0f2f13
6 changed files with 33 additions and 2 deletions

View File

@ -2,11 +2,21 @@
class MakeExperimentalHashtagFeatureDefaultForNewSites < ActiveRecord::Migration[7.0] class MakeExperimentalHashtagFeatureDefaultForNewSites < ActiveRecord::Migration[7.0]
def up def up
execute(<<~SQL) result = execute <<~SQL
SELECT created_at
FROM schema_migration_details
ORDER BY created_at
LIMIT 1
SQL
settings_insert_query = <<~SQL
INSERT INTO site_settings (name, data_type, value, created_at, updated_at) INSERT INTO site_settings (name, data_type, value, created_at, updated_at)
VALUES ('enable_experimental_hashtag_autocomplete', 5, 'f', now(), now()) VALUES ('enable_experimental_hashtag_autocomplete', 5, 'f', now(), now())
ON CONFLICT DO NOTHING ON CONFLICT DO NOTHING
SQL SQL
# keep enable_experimental_hashtag_autocomplete disabled for for existing sites
execute settings_insert_query if result.first["created_at"].to_datetime < 1.hour.ago
end end
def down def down

View File

@ -234,8 +234,10 @@ describe ChatMessage do
expect(cooked).to eq("<p><span class=\"mention\">@mention</span></p>") expect(cooked).to eq("<p><span class=\"mention\">@mention</span></p>")
end end
# TODO (martin) Remove this when enable_experimental_hashtag_autocomplete is default
it "supports category-hashtag plugin" do it "supports category-hashtag plugin" do
# TODO (martin) Remove when enable_experimental_hashtag_autocomplete is default for all sites
SiteSetting.enable_experimental_hashtag_autocomplete = false
category = Fabricate(:category) category = Fabricate(:category)
cooked = ChatMessage.cook("##{category.slug}") cooked = ChatMessage.cook("##{category.slug}")

View File

@ -494,6 +494,9 @@ RSpec.describe DiscourseNarrativeBot::AdvancedUserNarrative do
end end
it "should create the right reply" do it "should create the right reply" do
# TODO (martin) Remove when enable_experimental_hashtag_autocomplete is default for all sites
SiteSetting.enable_experimental_hashtag_autocomplete = false
category = Fabricate(:category) category = Fabricate(:category)
post.update!(raw: "Check out this ##{category.slug}") post.update!(raw: "Check out this ##{category.slug}")

View File

@ -5,6 +5,9 @@ RSpec.describe "CommonMark" do
SiteSetting.enable_markdown_typographer = false SiteSetting.enable_markdown_typographer = false
SiteSetting.highlighted_languages = "ruby|aa" SiteSetting.highlighted_languages = "ruby|aa"
# TODO (martin) Remove when enable_experimental_hashtag_autocomplete is default for all sites
SiteSetting.enable_experimental_hashtag_autocomplete = false
html, state, md = nil html, state, md = nil
failed = 0 failed = 0

View File

@ -1619,6 +1619,9 @@ RSpec.describe PrettyText do
end end
it "produces hashtag links" do it "produces hashtag links" do
# TODO (martin) Remove when enable_experimental_hashtag_autocomplete is default for all sites
SiteSetting.enable_experimental_hashtag_autocomplete = false
category = Fabricate(:category, name: "testing") category = Fabricate(:category, name: "testing")
category2 = Fabricate(:category, name: "known") category2 = Fabricate(:category, name: "known")
Fabricate(:topic, tags: [Fabricate(:tag, name: "known")]) Fabricate(:topic, tags: [Fabricate(:tag, name: "known")])
@ -1908,6 +1911,9 @@ HTML
end end
it "does not replace hashtags and mentions" do it "does not replace hashtags and mentions" do
# TODO (martin) Remove when enable_experimental_hashtag_autocomplete is default for all sites
SiteSetting.enable_experimental_hashtag_autocomplete = false
Fabricate(:user, username: "test") Fabricate(:user, username: "test")
category = Fabricate(:category, slug: "test") category = Fabricate(:category, slug: "test")
Fabricate( Fabricate(
@ -1927,6 +1933,9 @@ HTML
end end
it "does not replace hashtags and mentions when watched words are regular expressions" do it "does not replace hashtags and mentions when watched words are regular expressions" do
# TODO (martin) Remove when enable_experimental_hashtag_autocomplete is default for all sites
SiteSetting.enable_experimental_hashtag_autocomplete = false
SiteSetting.watched_words_regular_expressions = true SiteSetting.watched_words_regular_expressions = true
Fabricate(:user, username: "test") Fabricate(:user, username: "test")

View File

@ -14,6 +14,10 @@ RSpec.describe HashtagsController do
before do before do
SiteSetting.tagging_enabled = true SiteSetting.tagging_enabled = true
# TODO (martin) Remove when enable_experimental_hashtag_autocomplete is default for all sites
SiteSetting.enable_experimental_hashtag_autocomplete = false
tag_group tag_group
end end