gitlab-org--gitlab-foss/app/models
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
..
blob_viewer Clean up some backend 2017-08-03 14:29:35 +02:00
ci Rename many path_with_namespace -> full_path 2017-08-01 07:26:58 +02:00
concerns Re-enable SqlInjection and CommandInjection 2017-08-08 10:50:54 -04:00
conversational_development_index Store & use ConvDev percentages returned by Version app 2017-08-07 20:52:08 +02:00
cycle_analytics
diff_viewer Implement diff viewers 2017-06-14 10:12:21 -05:00
hooks Wrong data type when testing webhooks 2017-07-20 15:12:06 +00:00
issue
members Allow group reporters to manage group labels 2017-06-05 11:58:53 +01:00
merge_request
network Enable the Layout/SpaceBeforeBlockBraces cop 2017-08-09 11:52:22 +02:00
project_services Ensure `JIRA::Resource::Issue` responds to `resolution` before calling it 2017-08-03 15:25:47 +02:00
protected_branch Enabled no-one as a merge access level in protected branches 2017-05-10 17:19:40 +01:00
protected_tag Renamed ProtectedTag push_access_levels to create_access_levels 2017-04-04 03:38:58 +01:00
.gitkeep
ability.rb bugfix: use `require_dependency` to bring in DeclarativePolicy 2017-06-29 11:57:59 -07:00
abuse_report.rb Refactor the DeleteUserWorker 2017-06-05 13:08:06 +01:00
appearance.rb Added Cop to blacklist the use of `dependent:` 2017-07-06 12:01:36 +02:00
application_setting.rb Remove deprecated `repository_storage` attribute 2017-07-27 11:49:27 +02:00
audit_event.rb Rename ActiverecordSerialize cop 2017-07-06 12:01:36 +02:00
award_emoji.rb Enable Style/DotPosition Rubocop 👮 2017-06-21 13:48:12 +00:00
blob.rb Detect if file that appears to be text in the first 1024 bytes is actually binary afer loading all data 2017-06-08 12:49:03 -05:00
board.rb Added Cop to blacklist the use of `dependent:` 2017-07-06 12:01:36 +02:00
broadcast_message.rb #13336 - display multiple messages in both the UI and git output 2017-06-15 13:47:33 +00:00
chat_name.rb
chat_team.rb Remove Mattermost team with GitLab group 2017-07-28 09:09:55 +02:00
commit.rb Move `deltas` and `diff_from_parents` logic to Gitlab::Git::Commit 2017-08-07 23:33:40 -04:00
commit_range.rb
commit_status.rb Check warnings when building compound status SQL query 2017-06-20 15:32:29 +02:00
compare.rb
container_repository.rb Sanitize container repository path in model class 2017-04-13 11:54:02 +02:00
cycle_analytics.rb
dashboard_milestone.rb Native group milestones 2017-07-07 15:08:49 +00:00
deploy_key.rb Added Cop to blacklist the use of `dependent:` 2017-07-06 12:01:36 +02:00
deploy_keys_project.rb
deployment.rb Merge remote-tracking branch 'upstream/master' into 28717-additional-metrics-review-branch 2017-06-22 15:05:52 +02:00
diff_discussion.rb Update diff discussion position per discussion instead of per note 2017-05-31 14:34:56 -05:00
diff_note.rb Rename ActiverecordSerialize cop 2017-07-06 12:01:36 +02:00
directly_addressed_user.rb
discussion.rb Fix replying to a commit discussion displayed in the context of an MR 2017-06-01 09:52:11 -05:00
discussion_note.rb Refactor resolvability checks based on type 2017-04-06 10:51:45 -05:00
email.rb
environment.rb Added Cop to blacklist the use of `dependent:` 2017-07-06 12:01:36 +02:00
event.rb Migrate events into a new format 2017-08-10 17:45:44 +02:00
event_for_migration.rb Migrate events into a new format 2017-08-10 17:45:44 +02:00
external_issue.rb Improve support for external issue references 2017-06-30 14:47:53 +02:00
forked_project_link.rb Don't resolve fork relationships for projects pending delete 2017-07-04 12:02:29 +01:00
generic_commit_status.rb Allow to access pipelines even if they are disabled, but only present jobs and commit statuses without giving ability to access them 2017-06-13 09:52:48 +02:00
global_label.rb Fix dashboard labels dropdown 2017-07-07 14:35:16 +01:00
global_milestone.rb Native group milestones 2017-07-07 15:08:49 +00:00
gpg_key.rb improve gpg key validation 2017-07-27 15:46:04 +02:00
gpg_signature.rb validate the foreign_key instead of the relation 2017-07-27 15:46:04 +02:00
group.rb Don't treat anonymous users as owners when group has pending invites 2017-07-24 16:58:04 +01:00
group_label.rb
group_milestone.rb Native group milestones 2017-07-07 15:08:49 +00:00
guest.rb
identity.rb Implement search by extern_uid in Users API 2017-04-18 14:55:32 -04:00
individual_note_discussion.rb Ensure replying to an individual note by email creates a note with its own discussion ID 2017-04-24 12:24:39 -05:00
issue.rb Merge issuable "reopened" state into "opened" 2017-07-28 13:31:51 +02:00
issue_assignee.rb Move update_assignee_cache_counts to the service 2017-05-12 14:12:29 +03:00
issue_collection.rb Enable Style/DotPosition Rubocop 👮 2017-06-21 13:48:12 +00:00
key.rb fix #35133 strip new lines from ssh keys 2017-08-03 16:39:10 +00:00
label.rb Added Cop to blacklist the use of `dependent:` 2017-07-06 12:01:36 +02:00
label_link.rb Added Cop to blacklist polymorphic associations 2017-06-07 17:36:55 +02:00
label_priority.rb
legacy_diff_discussion.rb Allow commenting on older versions of the diff and comparisons between diff versions 2017-05-03 14:47:21 -05:00
legacy_diff_note.rb Rename ActiverecordSerialize cop 2017-07-06 12:01:36 +02:00
lfs_object.rb Added Cop to blacklist the use of `dependent:` 2017-07-06 12:01:36 +02:00
lfs_objects_project.rb Don’t schedule workers from inside transactions 2017-06-02 11:43:32 -05:00
list.rb Merge branch 'expand-backlog-closed-lists-issue-boards' into 'master' 2017-06-07 15:05:37 +00:00
member.rb Enable Style/DotPosition Rubocop 👮 2017-06-21 13:48:12 +00:00
merge_request.rb Re-enable SqlInjection and CommandInjection 2017-08-08 10:50:54 -04:00
merge_request_diff.rb Refactor Gitlab::Git::Commit to include a repository 2017-08-07 22:34:34 -04:00
merge_request_diff_commit.rb Re-enable SqlInjection and CommandInjection 2017-08-08 10:50:54 -04:00
merge_request_diff_file.rb Fix saving diffs that are not valid UTF-8 2017-07-26 15:34:57 +01:00
merge_requests_closing_issues.rb Enable Style/DotPosition Rubocop 👮 2017-06-21 13:48:12 +00:00
milestone.rb Support references to group milestones 2017-08-07 11:55:00 +01:00
namespace.rb Small refactor in LegacyNamespace and moved back send_update_instructions 2017-08-01 07:45:04 +02:00
note.rb Enable the Layout/SpaceBeforeBlockBraces cop 2017-08-09 11:52:22 +02:00
notification_recipient.rb move the read_ability logic into NotificationRecipient 2017-08-03 09:07:18 -07:00
notification_setting.rb Re-enable SqlInjection and CommandInjection 2017-08-08 10:50:54 -04:00
oauth_access_grant.rb
oauth_access_token.rb
out_of_context_discussion.rb Ensure replying to an individual note by email creates a note with its own discussion ID 2017-04-24 12:24:39 -05:00
pages_domain.rb Allow numeric pages domain 2017-06-06 12:39:37 +01:00
personal_access_token.rb Rename ActiverecordSerialize cop 2017-07-06 12:01:36 +02:00
personal_snippet.rb
project.rb Merge branch 'add-rubocop-gitlab-security' into 'master' 2017-08-08 19:31:24 +00:00
project_authorization.rb Enable Style/DotPosition Rubocop 👮 2017-06-21 13:48:12 +00:00
project_feature.rb Re-enable SqlInjection and CommandInjection 2017-08-08 10:50:54 -04:00
project_group_link.rb
project_import_data.rb Backport changes in https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/2551 to CE 2017-08-07 19:17:11 +01:00
project_label.rb
project_snippet.rb
project_statistics.rb Re-enable SqlInjection and CommandInjection 2017-08-08 10:50:54 -04:00
project_team.rb Enable Style/DotPosition Rubocop 👮 2017-06-21 13:48:12 +00:00
project_wiki.rb Allow wiki pages to be renamed in the UI 2017-08-03 07:38:11 +07:00
protectable_dropdown.rb Protected Tags backend review changes 2017-04-06 10:56:21 +01:00
protected_branch.rb Backport EE refactorings for Protected Tag EE-only functionality 2017-05-31 13:06:29 +01:00
protected_ref_matcher.rb Protected tags changes from backend maintainer review 2017-04-07 01:17:38 +01:00
protected_tag.rb Backport EE refactorings for Protected Tag EE-only functionality 2017-05-31 13:06:29 +01:00
push_event.rb Migrate events into a new format 2017-08-10 17:45:44 +02:00
push_event_payload.rb Migrate events into a new format 2017-08-10 17:45:44 +02:00
readme_blob.rb Load tree readme asynchronously 2017-05-10 08:21:58 -05:00
redirect_route.rb Remove unnecessary work for MySQL 2017-08-08 10:30:07 -07:00
release.rb
repository.rb Re-enable SqlInjection and CommandInjection 2017-08-08 10:50:54 -04:00
route.rb Added Cop to blacklist polymorphic associations 2017-06-07 17:36:55 +02:00
security_event.rb
sent_notification.rb Rename ActiverecordSerialize cop 2017-07-06 12:01:36 +02:00
service.rb Merge branch 'backport_slack_application_changes' into 'master' 2017-07-06 14:50:22 +00:00
snippet.rb Added Cop to blacklist the use of `dependent:` 2017-07-06 12:01:36 +02:00
snippet_blob.rb Refactor Blob support of external storage in preparation of job artifact blobs 2017-05-03 10:20:05 -05:00
spam_log.rb Refactor the DeleteUserWorker 2017-06-05 13:08:06 +01:00
subscription.rb Added Cop to blacklist polymorphic associations 2017-06-07 17:36:55 +02:00
system_note_metadata.rb Changes based on MR feedback. 2017-07-20 15:33:24 +01:00
timelog.rb
todo.rb Enable Style/DotPosition Rubocop 👮 2017-06-21 13:48:12 +00:00
tree.rb Load tree readme asynchronously 2017-05-10 08:21:58 -05:00
trending_project.rb
u2f_registration.rb
upload.rb Added Cop to blacklist polymorphic associations 2017-06-07 17:36:55 +02:00
user.rb Prevent user from changing username with container registry tags 2017-08-09 16:24:49 +00:00
user_agent_detail.rb Added Cop to blacklist polymorphic associations 2017-06-07 17:36:55 +02:00
users_star_project.rb
wiki_directory.rb
wiki_page.rb Allow wiki pages to be renamed in the UI 2017-08-03 07:38:11 +07:00