Skip to content

Drop packages_events table

Context

The !45802 (merged) added the feature flag :collect_package_events disabled by default to stop doing tracking of package events using the database, since the data was growing too fast and this solution was abandoned in favor of a redis solution.

In !114749 (merged) the application code related to the table packages_events was deleted.

Now we can drop the packages_events table.
The table contains 8648260 rows: https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/16405/commands/56350

🦀 What does this MR

  1. It removes the foreign key to the packages_packages table.

  2. It drops the packages_events table.

Screenshots or screen recordings

🔼 Migration up

$ rails db:migrate:main
main: == 20230316164917 RemovePackagesEventsPackageIdFk: migrating ==================
main: -- transaction_open?()
main:    -> 0.0000s
main: == 20230316164917 RemovePackagesEventsPackageIdFk: migrated (0.1123s) =========

main: == 20230316185746 DropPackagesEventsTable: migrating ==========================
main: -- drop_table(:packages_events)
main:    -> 0.0074s
main: == 20230316185746 DropPackagesEventsTable: migrated (0.0105s) =================

🔽 Migration down

$ rails db:rollback:main
main: == 20230316185746 DropPackagesEventsTable: reverting ==========================
main: -- create_table(:packages_events)
main:    -> 0.0121s
main: == 20230316185746 DropPackagesEventsTable: reverted (0.1002s) =================

$ rails db:rollback:main
main: == 20230316164917 RemovePackagesEventsPackageIdFk: reverting ==================
main: -- transaction_open?()
main:    -> 0.0000s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0003s
main: -- execute("ALTER TABLE packages_events VALIDATE CONSTRAINT fk_rails_c6c20d0094;")
main:    -> 0.0004s
main: -- execute("RESET statement_timeout")
main:    -> 0.0002s
main: == 20230316164917 RemovePackagesEventsPackageIdFk: reverted (0.1475s) =========

🔬 How to set up and validate locally

  1. Run migrations from this MR:

    rails db:migrate:main
  2. Run postgres console:

    $ gdk psql
  3. Check that the packages_events table doesn't exist:

    \d packages_events;
  4. Rollback changes:

    $ rails db:migrate:down:main VERSION=20230316185746
    $ rails db:migrate:down:main VERSION=20230316164917

🏁 MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #333827 (closed)

Edited by Dzmitry Meshcharakou

Merge request reports