# What this PR does Related to https://github.com/grafana/oncall-private/issues/2947 **NOTE** This PR introduces steps 1 and 2 of the 3 part migration proposed [here](https://raintank-corp.slack.com/archives/C06K1MQ07GS/p1732555465144099). Step 3, swapping reads to be from the new-column and dropping dual-writes, will be done in a future PR/release. --- I’m tackling this work now because _ultimately_ I want to move `AlertReceiveChannel.rate_limited_in_slack_at` to `SlackChannel.rate_limited_at` , but first I sorta need to refactor `SlackMessage.channel_id` from a `CHAR` field to a foreign key relationship (because in the spots where we touch Slack rate limiting, like [here](https://github.com/grafana/oncall/blob/dev/engine/apps/slack/alert_group_slack_service.py#L42-L50) for example, we only have `slack_message.channel_id`, which means I need to do extra queries to fetch the appropriate `SlackChannel` to then be able to get/set `SlackChannel.rate_limited_at` Other minor stuffs: - it also prepares us to drop `SlackMessage._slack_team_identity`. We already have a `@property` of `SlackMessage.slack_team_identity` (which [previously had some hacky logic](https://github.com/grafana/oncall/blob/dev/engine/apps/slack/models/slack_message.py#L74-L84)). I've refactored `SlackMessage.slack_team_identity` to simply point to `self.organization.slack_team_identity` + updated our code to _stop_ setting `SlackMessage._slack_team_identity` (will drop this column in future release) ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] Added the relevant release notes label (see labels prefixed w/ `release:`). These labels dictate how your PR will show up in the autogenerated release notes.
46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
import factory
|
|
|
|
from apps.slack.models import SlackChannel, SlackMessage, SlackTeamIdentity, SlackUserGroup, SlackUserIdentity
|
|
from common.utils import UniqueFaker
|
|
|
|
|
|
class SlackTeamIdentityFactory(factory.DjangoModelFactory):
|
|
slack_id = UniqueFaker("sentence", nb_words=3)
|
|
cached_name = factory.Faker("word")
|
|
|
|
class Meta:
|
|
model = SlackTeamIdentity
|
|
|
|
|
|
class SlackUserIdentityFactory(factory.DjangoModelFactory):
|
|
slack_id = UniqueFaker("sentence", nb_words=3)
|
|
cached_avatar = "TEST_SLACK_IMAGE_URL"
|
|
cached_name = "TEST_SLACK_NAME"
|
|
cached_slack_login = "TEST_SLACK_LOGIN"
|
|
|
|
class Meta:
|
|
model = SlackUserIdentity
|
|
|
|
|
|
class SlackUserGroupFactory(factory.DjangoModelFactory):
|
|
slack_id = UniqueFaker("sentence", nb_words=3)
|
|
name = factory.Faker("word")
|
|
handle = UniqueFaker("sentence", nb_words=3)
|
|
|
|
class Meta:
|
|
model = SlackUserGroup
|
|
|
|
|
|
class SlackChannelFactory(factory.DjangoModelFactory):
|
|
slack_id = factory.Sequence(lambda n: f"TEST_SLACK_ID_{n}")
|
|
name = factory.Faker("word")
|
|
|
|
class Meta:
|
|
model = SlackChannel
|
|
|
|
|
|
class SlackMessageFactory(factory.DjangoModelFactory):
|
|
slack_id = UniqueFaker("sentence", nb_words=3)
|
|
|
|
class Meta:
|
|
model = SlackMessage
|