Drop ai_events_counts table and remove its no-op worker

What does this MR do and why?

Phase 2 of #628407 (closed).

Phase 1 (!254687 (merged), 19.5) removed the aiMetricsBasic GraphQL field, the Ai::EventsCount model, the services, the cron entry and partition registration, and left Analytics::AiAnalytics::EventsCountAggregationWorker as a no-op for one release. 19.5 is out, so this MR removes the rest:

  • Drops the no-op worker and its spec, and its all_queues.yml entry.
  • Post-deploy migration to remove the ai_events_counts FK to organizations (fk_rails_99a3f4a8f1).
  • Post-deploy migration to drop the ai_events_counts partitioned table. Attached partitions go with it.
  • Moves the dictionary file to db/docs/deleted_tables and removes the table from the schema spec, org transfer config, destroy service FK todo and retention allowlist.

FK removal and table drop are separate migrations as per dropping tables. Same shape as !267973 (merged).

db/init_structure.sql is not touched, it gets regenerated on the next squash.

No user facing change.

Data deletion

  • Records affected: the whole ai_events_counts table, 1.82 GiB on GitLab.com as per the migration testing below. Nothing has written to it since phase 1 was deployed (19.5).
  • User impact: none. Nothing reads this table since phase 1 removed aiMetricsBasic and the model.
  • Recovery: the table only had daily counts aggregated from ai_usage_events, which is not touched here. Rolling back the two migrations recreates the table. Both tables keep 3 months of data, so most of the old counts can't be rebuilt from ai_usage_events anymore and would have to come from a backup. Since nothing uses them, we don't expect to need that.

How to set up and validate locally

bin/rails db:migrate
bin/rails db:rollback:main STEP=2   # table, indexes and FK come back same as master
bin/rails db:migrate

Migration output

Migration testing on GitLab.com data passed for both. The only warning is DROP TABLE taking 231 ms, that's the parent and its partitions being dropped. It runs inside with_lock_retries and nothing else uses the table.

Up

main: == 20261106101342 RemoveFkAiEventsCountsToOrganizations: migrating ============
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- execute("LOCK TABLE organizations, ai_events_counts IN ACCESS EXCLUSIVE MODE")
main:    -> 0.0005s
main: -- remove_foreign_key(:ai_events_counts, :organizations, {name: :fk_rails_99a3f4a8f1})
main:    -> 0.0056s
main: == 20261106101342 RemoveFkAiEventsCountsToOrganizations: migrated (0.0759s) ===
main: == 20261106101405 DropAiEventsCounts: migrating ===============================
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- drop_table(:ai_events_counts, {if_exists: true})
main:    -> 0.0020s
main: == 20261106101405 DropAiEventsCounts: migrated (0.0178s) ======================

Down

main: == 20261106101405 DropAiEventsCounts: reverting ===============================
main: -- create_table(:ai_events_counts, {primary_key: [:id, :events_date], options: "PARTITION BY RANGE (events_date)", if_not_exists: true})
main:    -> 0.0178s
main: -- add_index(:ai_events_counts, [:events_date, :namespace_id, :event, :user_id], {unique: true, include: [:total_occurrences], nulls_not_distinct: true, name: "idx_ai_events_counts_unique_tuple", if_not_exists: true})
main:    -> 0.0006s
main: == 20261106101405 DropAiEventsCounts: reverted (0.0660s) ======================
main: == 20261106101342 RemoveFkAiEventsCountsToOrganizations: reverting ============
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- execute("LOCK TABLE organizations, ai_events_counts IN ACCESS EXCLUSIVE MODE")
main:    -> 0.0004s
main: -- execute("ALTER TABLE ai_events_counts ADD CONSTRAINT fk_rails_99a3f4a8f1 FOREIGN KEY (organization_id) REFERENCES organizations (id) ON DELETE CASCADE ;")
main:    -> 0.0027s
main: -- execute("ALTER TABLE ai_events_counts VALIDATE CONSTRAINT fk_rails_99a3f4a8f1;")
main:    -> 0.0004s
main: == 20261106101342 RemoveFkAiEventsCountsToOrganizations: reverted (0.0744s) ===

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist.

Edited by Jatin Parihar

Merge request reports

Loading
Loading