summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-08-30 15:38:16 +0200
committerYorick Peterse <yorickpeterse@gmail.com>2017-09-06 16:40:31 +0200
commit235b105c917c16ab14a79ba13280aff4fd9f1cf9 (patch)
tree27bfe7e1ff2e4caacbdc4450e510164771b66c19 /app/models
parent1632ffa6ad16738994122f0e84f331d50f220879 (diff)
downloadgitlab-ce-235b105c917c16ab14a79ba13280aff4fd9f1cf9.tar.gz
Finish migration to the new events setupevents-migration-cleanup
This finishes the procedure for migrating events from the old format into the new format. Code no longer uses the old setup and the database tables used during the migration process are swapped, with the old table being dropped. While the database migration can be reversed this will 1) take a lot of time as data has to be coped around 2) won't restore data in the "events.data" column as we have no way of restoring this. Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/37241
Diffstat (limited to 'app/models')
-rw-r--r--app/models/event.rb102
-rw-r--r--app/models/event_for_migration.rb5
-rw-r--r--app/models/push_event.rb77
3 files changed, 22 insertions, 162 deletions
diff --git a/app/models/event.rb b/app/models/event.rb
index 996768a267b..c313bbb66f8 100644
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -1,5 +1,6 @@
class Event < ActiveRecord::Base
include Sortable
+ include IgnorableColumn
default_scope { reorder(nil).where.not(author_id: nil) }
CREATED = 1
@@ -50,13 +51,9 @@ class Event < ActiveRecord::Base
belongs_to :target, polymorphic: true # rubocop:disable Cop/PolymorphicAssociations
has_one :push_event_payload, foreign_key: :event_id
- # For Hash only
- serialize :data # rubocop:disable Cop/ActiveRecordSerialize
-
# Callbacks
after_create :reset_project_activity
after_create :set_last_repository_updated_at, if: :push?
- after_create :replicate_event_for_push_events_migration
# Scopes
scope :recent, -> { reorder(id: :desc) }
@@ -82,6 +79,10 @@ class Event < ActiveRecord::Base
self.inheritance_column = 'action'
+ # "data" will be removed in 10.0 but it may be possible that JOINs happen that
+ # include this column, hence we're ignoring it as well.
+ ignore_column :data
+
class << self
def model_name
ActiveModel::Name.new(self, nil, 'event')
@@ -159,7 +160,7 @@ class Event < ActiveRecord::Base
end
def push?
- action == PUSHED && valid_push?
+ false
end
def merged?
@@ -272,87 +273,6 @@ class Event < ActiveRecord::Base
end
end
- def valid_push?
- data[:ref] && ref_name.present?
- rescue
- false
- end
-
- def tag?
- Gitlab::Git.tag_ref?(data[:ref])
- end
-
- def branch?
- Gitlab::Git.branch_ref?(data[:ref])
- end
-
- def new_ref?
- Gitlab::Git.blank_ref?(commit_from)
- end
-
- def rm_ref?
- Gitlab::Git.blank_ref?(commit_to)
- end
-
- def md_ref?
- !(rm_ref? || new_ref?)
- end
-
- def commit_from
- data[:before]
- end
-
- def commit_to
- data[:after]
- end
-
- def ref_name
- if tag?
- tag_name
- else
- branch_name
- end
- end
-
- def branch_name
- @branch_name ||= Gitlab::Git.ref_name(data[:ref])
- end
-
- def tag_name
- @tag_name ||= Gitlab::Git.ref_name(data[:ref])
- end
-
- # Max 20 commits from push DESC
- def commits
- @commits ||= (data[:commits] || []).reverse
- end
-
- def commit_title
- commit = commits.last
-
- commit[:message] if commit
- end
-
- def commit_id
- commit_to || commit_from
- end
-
- def commits_count
- data[:total_commits_count] || commits.count || 0
- end
-
- def ref_type
- tag? ? "tag" : "branch"
- end
-
- def push_with_commits?
- !commits.empty? && commit_from && commit_to
- end
-
- def last_push_to_non_root?
- branch? && project.default_branch != branch_name
- end
-
def target_iid
target.respond_to?(:iid) ? target.iid : target_id
end
@@ -432,16 +352,6 @@ class Event < ActiveRecord::Base
user ? author_id == user.id : false
end
- # We're manually replicating data into the new table since database triggers
- # are not dumped to db/schema.rb. This could mean that a new installation
- # would not have the triggers in place, thus losing events data in GitLab
- # 10.0.
- def replicate_event_for_push_events_migration
- new_attributes = attributes.with_indifferent_access.except(:title, :data)
-
- EventForMigration.create!(new_attributes)
- end
-
def to_partial_path
# We are intentionally using `Event` rather than `self.class` so that
# subclasses also use the `Event` implementation.
diff --git a/app/models/event_for_migration.rb b/app/models/event_for_migration.rb
deleted file mode 100644
index a1672da5eec..00000000000
--- a/app/models/event_for_migration.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-# This model is used to replicate events between the old "events" table and the
-# new "events_for_migration" table that will replace "events" in GitLab 10.0.
-class EventForMigration < ActiveRecord::Base
- self.table_name = 'events_for_migration'
-end
diff --git a/app/models/push_event.rb b/app/models/push_event.rb
index 3f1ff979de6..23ffb0d4ea8 100644
--- a/app/models/push_event.rb
+++ b/app/models/push_event.rb
@@ -15,15 +15,21 @@ class PushEvent < Event
# should ensure the ID points to a valid project.
validates :project_id, presence: true
- # The "data" field must not be set for push events since it's not used and a
- # waste of space.
- validates :data, absence: true
-
# These fields are also not used for push events, thus storing them would be a
# waste.
validates :target_id, absence: true
validates :target_type, absence: true
+ delegate :branch?, to: :push_event_payload
+ delegate :tag?, to: :push_event_payload
+ delegate :commit_from, to: :push_event_payload
+ delegate :commit_to, to: :push_event_payload
+ delegate :ref_type, to: :push_event_payload
+ delegate :commit_title, to: :push_event_payload
+
+ delegate :commit_count, to: :push_event_payload
+ alias_method :commits_count, :commit_count
+
def self.sti_name
PUSHED
end
@@ -36,86 +42,35 @@ class PushEvent < Event
!!(commit_from && commit_to)
end
- def tag?
- return super unless push_event_payload
-
- push_event_payload.tag?
- end
-
- def branch?
- return super unless push_event_payload
-
- push_event_payload.branch?
- end
-
def valid_push?
- return super unless push_event_payload
-
push_event_payload.ref.present?
end
def new_ref?
- return super unless push_event_payload
-
push_event_payload.created?
end
def rm_ref?
- return super unless push_event_payload
-
push_event_payload.removed?
end
- def commit_from
- return super unless push_event_payload
-
- push_event_payload.commit_from
- end
-
- def commit_to
- return super unless push_event_payload
-
- push_event_payload.commit_to
+ def md_ref?
+ !(rm_ref? || new_ref?)
end
def ref_name
- return super unless push_event_payload
-
push_event_payload.ref
end
- def ref_type
- return super unless push_event_payload
-
- push_event_payload.ref_type
- end
-
- def branch_name
- return super unless push_event_payload
-
- ref_name
- end
-
- def tag_name
- return super unless push_event_payload
-
- ref_name
- end
-
- def commit_title
- return super unless push_event_payload
-
- push_event_payload.commit_title
- end
+ alias_method :branch_name, :ref_name
+ alias_method :tag_name, :ref_name
def commit_id
commit_to || commit_from
end
- def commits_count
- return super unless push_event_payload
-
- push_event_payload.commit_count
+ def last_push_to_non_root?
+ branch? && project.default_branch != branch_name
end
def validate_push_action