Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions app/models/access_token.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

class AccessToken < ApplicationRecord
include Uuidable

FORMAT_BY_PROVIDER = {
Providerable::GITHUB => 'github_pat_',
Providerable::GITLAB => 'glpat-'
Expand Down
2 changes: 0 additions & 2 deletions app/models/api_access_token.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

class ApiAccessToken < ApplicationRecord
include Uuidable

encrypts :value, deterministic: true

belongs_to :user
Expand Down
2 changes: 0 additions & 2 deletions app/models/companies/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module Companies
class User < ApplicationRecord
self.table_name = :companies_users

include Uuidable

READ = 'read'
WRITE = 'write'

Expand Down
1 change: 0 additions & 1 deletion app/models/company.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

class Company < ApplicationRecord
include Uuidable
include Tokenable
include Insightable
include Configurable
Expand Down
13 changes: 0 additions & 13 deletions app/models/concerns/uuidable.rb

This file was deleted.

1 change: 0 additions & 1 deletion app/models/entity.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

class Entity < ApplicationRecord
include Uuidable
include Providerable

EMPTY_PAYLOAD = {
Expand Down
2 changes: 0 additions & 2 deletions app/models/entity/ignore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ class Entity
class Ignore < ApplicationRecord
self.table_name = :ignores

include Uuidable

belongs_to :insightable, polymorphic: true
end
end
2 changes: 0 additions & 2 deletions app/models/excludes/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module Excludes
class Group < ApplicationRecord
self.table_name = :excludes_groups

include Uuidable

FREE_GROUPS_AMOUNT = 2

belongs_to :insightable, polymorphic: true
Expand Down
2 changes: 0 additions & 2 deletions app/models/excludes/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module Excludes
class Rule < ApplicationRecord
self.table_name = :excludes_rules

include Uuidable

FREE_RULES_AMOUNT = 3

TITLE_TARGET = 'title'
Expand Down
2 changes: 0 additions & 2 deletions app/models/invite.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

class Invite < ApplicationRecord
include Uuidable

INVITEABLE_TYPES = %w[
User
Company
Expand Down
2 changes: 0 additions & 2 deletions app/models/issue.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

class Issue < ApplicationRecord
include Uuidable

belongs_to :repository

has_many :comments, class_name: 'Issue::Comment', dependent: :destroy
Expand Down
2 changes: 0 additions & 2 deletions app/models/issue/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

class Issue
class Comment < ApplicationRecord
include Uuidable

belongs_to :issue
end
end
1 change: 0 additions & 1 deletion app/models/kudos/achievement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class Achievement < Kudos::ApplicationRecord
self.table_name = :kudos_achievements

include Kudos
include Uuidable

belongs_to :kudos_achievement_group, class_name: 'Kudos::AchievementGroup'

Expand Down
2 changes: 0 additions & 2 deletions app/models/kudos/achievement_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module Kudos
class AchievementGroup < ApplicationRecord
self.table_name = :kudos_achievement_groups

include Uuidable

belongs_to :parent,
class_name: 'Kudos::AchievementGroup',
foreign_key: :parent_id,
Expand Down
2 changes: 0 additions & 2 deletions app/models/notification.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

class Notification < ApplicationRecord
include Uuidable

NOTIFYABLE_TYPES = %w[
Company
Repository
Expand Down
2 changes: 0 additions & 2 deletions app/models/pull_request.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

class PullRequest < ApplicationRecord
include Uuidable

belongs_to :repository
belongs_to :entity

Expand Down
1 change: 0 additions & 1 deletion app/models/repository.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

class Repository < ApplicationRecord
include Uuidable
include Tokenable
include Insightable
include Providerable
Expand Down
1 change: 0 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

class User < ApplicationRecord
include Uuidable
include Kudos::Achievementable
include Notifyable
include Inviteable
Expand Down
2 changes: 0 additions & 2 deletions app/models/user/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ class User
class Session < ApplicationRecord
self.table_name = :users_sessions

include Uuidable

belongs_to :user
end
end
2 changes: 0 additions & 2 deletions app/models/webhook.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

class Webhook < ApplicationRecord
include Uuidable

CUSTOM = 'custom'
SLACK = 'slack'
DISCORD = 'discord'
Expand Down
38 changes: 38 additions & 0 deletions db/migrate/20241207103004_add_uuids_to_tables.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class AddUuidsToTables < ActiveRecord::Migration[7.2]
disable_ddl_transaction!

TABLES_WITH_MODELS = {
work_times: WorkTime,
vacations: User::Vacation,
subscriptions: User::Subscription,
subscribers: Subscriber,
repositories_insights: Repositories::Insight,
pull_requests_reviews: PullRequest::Review,
pull_requests_comments: PullRequest::Comment,
insights: Insight,
identities: Identity,
feedbacks: User::Feedback
}

def up
TABLES_WITH_MODELS.each do |table, model|
add_column table, :uuid, :uuid
change_column_default table, :uuid, 'gen_random_uuid()'
add_index table, :uuid, unique: true, algorithm: :concurrently

model.unscoped.in_batches do |relation|
relation.where(uuid: nil).update_all('uuid = gen_random_uuid()')
end

safety_assured { change_column_null table, :uuid, false }
end
end

def down
safety_assured do
TABLES_WITH_MODELS.each_key do |table|
remove_column table, :uuid
end
end
end
end
15 changes: 15 additions & 0 deletions db/migrate/20241207105035_change_uuid_defaults.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class ChangeUuidDefaults < ActiveRecord::Migration[7.2]
TABLES = %i[
webhooks users_sessions users repositories pull_requests
notifications issues issue_comments invites ignores excludes_rules
excludes_groups entities companies_users companies api_access_tokens access_tokens
]

def change
safety_assured do
TABLES.each do |table|
change_column_default table, :uuid, 'gen_random_uuid()'
end
end
end
end
13 changes: 13 additions & 0 deletions db/migrate/20241207105036_change_uuid_defaults_kudos.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class ChangeUuidDefaultsKudos < ActiveRecord::Migration[7.2]
TABLES = %i[
kudos_achievements kudos_achievement_groups
]

def change
safety_assured do
TABLES.each do |table|
change_column_default table, :uuid, 'gen_random_uuid()'
end
end
end
end
Loading
Loading