Page MenuHomePhabricator

Update DB schema for storing event types
Closed, ResolvedPublic3 Estimated Story Points

Description

Context: we would like to associate every event with multiple event types (see list in the task description of T355253; we'll allow at most 2-3 types per event). The campaign_events table already has an unused event_type column added long ago, but that was meant to store a single type, not multiple types. Because there is a fixed list of topics, and the list is quite short, and given DBA recommendations (T387483#10760357), we will rename the column to event_types and change its type from varbinary to integer, so it can be used as a bitfield.

NOTE: when designing the schema change, we need a final decision on whether "other" can be used together with other types or not (assuming that existing events will get the type "other" by default). If the answer is yes, we cannot assign it the value 0 as it wouldn't work in a bitfield.

Acceptance Criteria:

  • Define the updated database schema for storing types of event
  • Implement a schema change for it
  • Create the schema in production and beta (T394509)

Event Timeline

cmelo changed the task status from Open to In Progress.Mar 31 2025, 1:21 PM
cmelo claimed this task.
cmelo removed cmelo as the assignee of this task.Mar 31 2025, 8:20 PM
cmelo subscribed.
Daimona renamed this task from Create DB schema for storing event types to Update DB schema for storing event types.Apr 23 2025, 2:43 PM
Daimona added a project: Schema-change.
Daimona updated the task description. (Show Details)

Change #1143082 had a related patch set uploaded (by Mhorsey; author: Mhorsey):

[mediawiki/extensions/CampaignEvents@master] Rename existing event_type field and change to integer type

https://gerrit.wikimedia.org/r/1143082

The field will be created aw described in the AC, by renaming the existing event_type field and changig the type to integer. As this is a low-cardinality field, not index is required.

DBA please confirm this plan is acceptable

@ifried can you please confirm that "other" is an independant option, that is to say it can only be selected alone and selecting it in combination with other options is invalid?

Confirmed! Yes, other will be an independent option that can only be selected alone.

Change #1143581 had a related patch set uploaded (by Mhorsey; author: Mhorsey):

[mediawiki/extensions/CampaignEvents@master] Remove reference to unused event_type field

https://gerrit.wikimedia.org/r/1143581

Change #1143581 merged by jenkins-bot:

[mediawiki/extensions/CampaignEvents@master] Remove reference to unused event_type field

https://gerrit.wikimedia.org/r/1143581

The field will be created aw described in the AC, by renaming the existing event_type field and changig the type to integer. As this is a low-cardinality field, not index is required.

DBA please confirm this plan is acceptable

Renaming a field is not as easy as it looks, we need to drop the column and insert a new one on every database and it can break replication and other issues. In this case, the tables are small enough that I think we can run them on the primary database with replication but please don't make schema changes for cosmetics if it can be avoided.

@Ladsgroup noted, thank you. Would you prefer in this instance if we didn't change the field name?

@Ladsgroup noted, thank you. Would you prefer in this instance if we didn't change the field name?

Yes please! I'd appreciate it.

@Ladsgroup we would still need to change the field datatype, would that not result in a drop/insert also?

if you're changing the data type, then yeah, we can rename it at the same time but also need to remember the data will be gone since in the eyes of mariadb we are dropping and recreating.

That's fine, we don't have actually use that field currently. Thanks @Ladsgroup !

This is just pending a +2 on the patch from someone in DBA now

Change #1143082 merged by jenkins-bot:

[mediawiki/extensions/CampaignEvents@master] Rename existing event_type field and change to integer type

https://gerrit.wikimedia.org/r/1143082

I stay subscribed in case we are needed.

vaughnwalters subscribed.

event_types is now of type int. Marking this as done / resolved

Screenshot 2025-05-23 at 10.49.59 AM.png (1,454×872 px, 245 KB)

Screenshot 2025-05-23 at 10.51.57 AM.png (1,464×40 px, 13 KB)