gitlab-org--gitlab-foss/db/post_migrate
Yorick Peterse 0395c47193
Migrate events into a new format
This commit migrates events data in such a way that push events are
stored much more efficiently. This is done by creating a shadow table
called "events_for_migration", and a table called "push_event_payloads"
which is used for storing push data of push events. The background
migration in this commit will copy events from the "events" table into
the "events_for_migration" table, push events in will also have a row
created in "push_event_payloads".

This approach allows us to reclaim space in the next release by simply
swapping the "events" and "events_for_migration" tables, then dropping
the old events (now "events_for_migration") table.

The new table structure is also optimised for storage space, and does
not include the unused "title" column nor the "data" column (since this
data is moved to "push_event_payloads").

== Newly Created Events

Newly created events are inserted into both "events" and
"events_for_migration", both using the exact same primary key value. The
table "push_event_payloads" in turn has a foreign key to the _shadow_
table. This removes the need for recreating and validating the foreign
key after swapping the tables. Since the shadow table also has a foreign
key to "projects.id" we also don't have to worry about orphaned rows.

This approach however does require some additional storage as we're
duplicating a portion of the events data for at least 1 release. The
exact amount is hard to estimate, but for GitLab.com this is expected to
be between 10 and 20 GB at most. The background migration in this commit
deliberately does _not_ update the "events" table as doing so would put
a lot of pressure on PostgreSQL's auto vacuuming system.

== Supporting Both Old And New Events

Application code has also been adjusted to support push events using
both the old and new data formats. This is done by creating a PushEvent
class which extends the regular Event class. Using Rails' Single Table
Inheritance system we can ensure the right class is used for the right
data, which in this case is based on the value of `events.action`. To
support displaying old and new data at the same time the PushEvent class
re-defines a few methods of the Event class, falling back to their
original implementations for push events in the old format.

Once all existing events have been migrated the various push event
related methods can be removed from the Event model, and the calls to
`super` can be removed from the methods in the PushEvent model.

The UI and event atom feed have also been slightly changed to better
handle this new setup, fortunately only a few changes were necessary to
make this work.

== API Changes

The API only displays push data of events in the new format. Supporting
both formats in the API is a bit more difficult compared to the UI.
Since the old push data was not really well documented (apart from one
example that used an incorrect "action" nmae) I decided that supporting
both was not worth the effort, especially since events will be migrated
in a few days _and_ new events are created in the correct format.
2017-08-10 17:45:44 +02:00
..
.gitkeep
20160824121037_change_personal_access_tokens_default_back_to_empty_array.rb
20161011222551_remove_inactive_jira_service_properties.rb Exclude migrations from Style/MutableConstant 2017-02-23 09:32:42 -06:00
20161109150329_fix_project_records_with_invalid_visibility.rb Enable Style/DotPosition Rubocop 👮 2017-06-21 13:48:12 +00:00
20161128170531_drop_user_activities_table.rb Remove unused user activities code 2017-04-14 15:20:55 +02:00
20161221140236_remove_unneeded_services.rb Disable timeout while removing services 2016-12-27 11:10:15 +01:00
20161221153951_rename_reserved_project_names.rb Enable Style/DotPosition Rubocop 👮 2017-06-21 13:48:12 +00:00
20170104150317_requeue_pending_delete_projects.rb Enable Style/DotPosition Rubocop 👮 2017-06-21 13:48:12 +00:00
20170106142508_fill_authorized_projects.rb Enable Style/DotPosition Rubocop 👮 2017-06-21 13:48:12 +00:00
20170106172224_remove_project_authorizations_id_column.rb Remove the project_authorizations.id column 2017-01-08 13:56:50 +01:00
20170131214021_reset_users_authorized_projects_populated.rb Disable Migration/UpdateColumnInBatches for old migrations 2017-05-29 11:28:23 +02:00
20170206040400_remove_inactive_default_email_services.rb Use Gitlab::Database.with_connection_pool from !9192 2017-02-14 20:29:36 +08:00
20170206101007_remove_trackable_columns_from_timelogs.rb Add a test which would rollback db and migrate again 2017-03-14 02:12:55 +08:00
20170206101030_validate_foreign_keys_on_timelogs.rb Refactor migration to not require downtime 2017-02-07 10:42:42 -05:00
20170209140523_validate_foreign_keys_on_oauth_openid_requests.rb Implement OpenID Connect identity provider 2017-03-07 14:54:35 +01:00
20170211073944_disable_invalid_service_templates.rb Disable the inheritance column of services in DisableInvalidServiceTemplates migration 2017-03-01 14:06:50 +01:00
20170214111112_delete_deprecated_gitlab_ci_service.rb Remove deprecated CI service 2017-02-14 15:15:41 +01:00
20170215200045_remove_theme_id_from_users.rb Remove comments in migration 2017-02-16 08:25:09 -06:00
20170301205640_migrate_build_events_to_pipeline_events.rb removes redundant code from database.rb 2017-04-11 20:20:19 +01:00
20170306170512_migrate_legacy_manual_actions.rb Fix statements timeout in manual actions migration 2017-03-16 09:57:53 +01:00
20170309171644_reset_relative_position_for_issue.rb Disable transactions in migrations that should not use it 2017-06-21 14:35:06 +02:00
20170313133418_rename_more_reserved_project_names.rb Enable Style/DotPosition Rubocop 👮 2017-06-21 13:48:12 +00:00
20170317162059_update_upload_paths_to_system.rb Disable transactions in migrations that should not use it 2017-06-21 14:35:06 +02:00
20170324160416_migrate_user_activities_to_users_last_activity_on.rb Support multiple Redis instances based on queue type 2017-07-11 03:35:47 +00:00
20170404170532_remove_notes_original_discussion_id.rb Remove and ignore notes.original_discussion_id column 2017-04-05 17:44:14 +01:00
20170406111121_clean_upload_symlinks.rb Merge branch 'bvl-remove-appearance-symlink' into 'security-9-3' 2017-07-19 22:28:17 -05:00
20170406142253_migrate_user_project_view.rb Disable transactions in migrations that should not use it 2017-06-21 14:35:06 +02:00
20170408033905_remove_old_cache_directories.rb Periodically clean up temporary upload files to recover storage space 2017-04-10 08:48:44 +11:00
20170412174900_rename_reserved_dynamic_paths.rb Reject EE reserved namespace paths in CE as well 2017-05-04 18:11:31 +02:00
20170425121605_migrate_trigger_schedules_to_pipeline_schedules.rb Fix data migration from trigger schedules 2017-05-17 22:47:47 +02:00
20170425130047_drop_ci_trigger_schedules_table.rb Add database helpers 'add_timestamps_with_timezone' and 'timestamps_with_timezone' 2017-06-13 22:44:13 +11:00
20170502070007_enable_auto_cancel_pending_pipelines_for_all.rb Disable statement timeout in CI pipelines migration 2017-06-19 14:45:50 +02:00
20170502101023_cleanup_namespaceless_pending_delete_projects.rb Enable the Layout/SpaceBeforeBlockBraces cop 2017-08-09 11:52:22 +02:00
20170503004427_update_retried_for_ci_build.rb Fix migrations for older PostgreSQL versions 2017-05-23 00:08:51 +02:00
20170503120310_remove_users_authorized_projects_populated.rb Use CTEs for nested groups and authorizations 2017-05-17 16:51:08 +02:00
20170508170547_add_head_pipeline_for_each_merge_request.rb Merge branch 'master' into fix/gb/improve-updating-column-in-batches-helper 2017-06-22 12:37:38 +02:00
20170510101043_add_foreign_key_on_pipeline_schedule_owner.rb Add foreign key on pipeline_schedules.owner_id 2017-05-15 10:01:29 +02:00
20170511100900_cleanup_rename_web_hooks_build_events_to_job_events.rb Merge branch 'bvl-rename-build-events-to-job-events' into 'master' 2017-05-16 14:12:19 +02:00
20170511101000_cleanup_rename_services_build_events_to_job_events.rb Merge branch 'bvl-rename-build-events-to-job-events' into 'master' 2017-05-16 14:12:19 +02:00
20170516165238_cleanup_trigger_for_issues.rb Improve migration for Multipple issue assignee feature 2017-05-16 23:51:50 +03:00
20170516181025_add_constraints_to_issue_assignees_table.rb Adding NULL:false constraint with change_column_null instead of change_column 2017-05-18 11:21:01 +03:00
20170518200835_rename_users_with_renamed_namespace.rb Rename users on mysql 2017-05-19 21:21:32 +02:00
20170518231126_fix_wrongly_renamed_routes.rb Fix incorrectly renamed routes 2017-05-19 12:25:23 +02:00
20170523083112_migrate_old_artifacts.rb Add missing specs 2017-06-01 16:34:48 +02:00
20170525140254_rename_all_reserved_paths_again.rb Disable statement timeout 2017-06-26 17:49:30 +02:00
20170526185842_migrate_pipeline_stages.rb Migrate stages only with correct foreign references 2017-06-06 14:32:24 +02:00
20170526185858_create_index_in_pipeline_stages.rb Create index on pipeline stages after migrating stages 2017-06-06 14:13:51 +02:00
20170526185901_remove_stage_id_index_from_builds.rb Fix adding/removing foreign keys on MySQL 2017-06-21 13:18:38 +02:00
20170526185921_migrate_build_stage_reference.rb Fix migration specs that can not run within transaction 2017-06-21 16:21:12 +02:00
20170526190000_migrate_build_stage_reference_again.rb Bump build stage id reference migration identifier 2017-06-21 13:55:28 +02:00
20170531203055_cleanup_users_ldap_email_rename.rb Sync email address from specified omniauth provider - db changes 2017-06-07 11:13:57 -04:00
20170606202615_move_appearance_to_system_dir.rb Bring in security changes from the 9.2.5 release 2017-06-07 21:16:20 -07:00
20170607121233_convert_custom_notification_settings_to_columns.rb Deserialise existing custom notification settings 2017-06-15 15:15:13 +01:00
20170609183112_remove_position_from_issuables.rb Migration - Remove position field from issues and merge requests 2017-06-16 12:03:15 -03:00
20170612071012_move_personal_snippets_files.rb Merge branch '33359-pers-snippet-files-location' into 'security-9-3' 2017-07-19 22:28:27 -05:00
20170613111224_clean_appearance_symlinks.rb Merge branch 'bvl-remove-appearance-symlink' into 'security-9-3' 2017-07-19 22:28:17 -05:00
20170621102400_add_stage_id_index_to_builds.rb Improve stage_id in ci_builds foreign key migration 2017-07-03 20:24:32 +02:00
20170627101016_schedule_event_migrations.rb Migrate events into a new format 2017-08-10 17:45:44 +02:00
20170628080858_migrate_stage_id_reference_in_background.rb Do not schedule bg migration when it is not needed 2017-07-07 15:50:33 +02:00
20170629180131_cleanup_application_settings_signin_enabled_rename.rb Fixes needed when GitLab sign-in is not enabled 2017-07-13 10:08:27 -04:00
20170703130158_schedule_merge_request_diff_migrations.rb Migrate MR commits and diffs to new tables 2017-08-03 13:20:26 +01:00
20170717111152_cleanup_move_system_upload_folder_symlink.rb Move the uploads/system folder to uploads/-/system 2017-07-18 15:38:54 +02:00
20170717150329_enqueue_migrate_system_uploads_to_new_folder.rb Add a background migration to rename uploads in the uploads table 2017-07-18 15:38:54 +02:00
20170719150301_merge_issuable_reopened_into_opened_state.rb Merge issuable "reopened" state into "opened" 2017-07-28 13:31:51 +02:00
20170728101014_remove_events_from_notification_settings.rb Remove events column from notification settings 2017-07-31 11:18:55 +01:00
20170803090603_calculate_conv_dev_index_percentages.rb Store & use ConvDev percentages returned by Version app 2017-08-07 20:52:08 +02:00
20170807160457_remove_locked_at_column_from_merge_requests.rb Re-add column locked_at on migration rollback 2017-08-07 18:09:53 -03:00