Verifiquei e isso é esperado, pois excluímos registros com deleted_at preenchido, mesmo com find_by:
ChatChannel.find_by(slug: "sec-fhir")
ChatChannel Load (0.4ms) SELECT "chat_channels".* FROM "chat_channels" WHERE "chat_channels"."deleted_at" IS NULL AND "chat_channels"."slug" = 'sec-fhir' LIMIT 1
=> nil
Você precisará fazer isso em vez disso (adicionando with_deleted):
ChatChannel.with_deleted.find_by(slug: "sec-fhir")
ChatChannel Load (0.3ms) SELECT "chat_channels".* FROM "chat_channels" WHERE "chat_channels"."slug" = 'sec-fhir' LIMIT 1
=> #<CategoryChannel:0x00007fc9bfb4abf0
id: 124,
chatable_id: 19,
deleted_at: Wed, 15 Feb 2023 01:19:20.982181000 UTC +00:00,
deleted_by_id: nil,
featured_in_category_id: nil,
delete_after_seconds: nil,
chatable_type: "Category",
created_at: Fri, 13 Jan 2023 01:46:43.730329000 UTC +00:00,
updated_at: Wed, 15 Feb 2023 01:19:56.427647000 UTC +00:00,
name: "test channel",
description: "",
status: "archived",
user_count: 1,
last_message_sent_at: Fri, 13 Jan 2023 01:46:51.130903000 UTC +00:00,
auto_join_users: false,
user_count_stale: false,
slug: "sec-fhir",
type: "CategoryChannel",
allow_channel_wide_mentions: true,
messages_count: 0,
threading_enabled: false>
Portanto, para limpar o antigo slug do canal excluído, faça algo como isto:
channel = ChatChannel.with_deleted.find_by(slug: "sec-fhir")
channel.update!(slug: "#{channel.deleted_at.strftime("%Y%m%d-%H%M")}-#{channel.slug}-deleted")
Talvez precisemos de uma migração para corrigir isso, @mcwumbly e @j.jaffeux?