Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
fa6f19d1
Commit
fa6f19d1
authored
Aug 30, 2019
by
dineshpanda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove dependency on IgnorableColumn concern
parent
921d4f37
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
29 additions
and
110 deletions
+29
-110
app/models/application_setting.rb
app/models/application_setting.rb
+8
-7
app/models/ci/build.rb
app/models/ci/build.rb
+8
-7
app/models/ci/runner.rb
app/models/ci/runner.rb
+1
-2
app/models/concerns/ignorable_column.rb
app/models/concerns/ignorable_column.rb
+0
-30
app/models/deploy_key.rb
app/models/deploy_key.rb
+1
-2
app/models/event.rb
app/models/event.rb
+0
-1
app/models/merge_request_diff.rb
app/models/merge_request_diff.rb
+0
-1
app/models/note.rb
app/models/note.rb
+1
-2
app/models/notification_setting.rb
app/models/notification_setting.rb
+1
-2
app/models/user.rb
app/models/user.rb
+5
-4
doc/development/what_requires_downtime.md
doc/development/what_requires_downtime.md
+4
-8
spec/models/concerns/ignorable_column_spec.rb
spec/models/concerns/ignorable_column_spec.rb
+0
-44
No files found.
app/models/application_setting.rb
View file @
fa6f19d1
...
...
@@ -4,7 +4,6 @@ class ApplicationSetting < ApplicationRecord
include
CacheableAttributes
include
CacheMarkdownField
include
TokenAuthenticatable
include
IgnorableColumn
include
ChronicDurationAttribute
add_authentication_token_field
:runners_registration_token
,
encrypted:
->
{
Feature
.
enabled?
(
:application_settings_tokens_optional_encryption
,
default_enabled:
true
)
?
:optional
:
:required
}
...
...
@@ -25,12 +24,14 @@ class ApplicationSetting < ApplicationRecord
serialize
:domain_blacklist
,
Array
# rubocop:disable Cop/ActiveRecordSerialize
serialize
:repository_storages
# rubocop:disable Cop/ActiveRecordSerialize
ignore_column
:koding_url
ignore_column
:koding_enabled
ignore_column
:sentry_enabled
ignore_column
:sentry_dsn
ignore_column
:clientside_sentry_enabled
ignore_column
:clientside_sentry_dsn
self
.
ignored_columns
=
%i[
clientside_sentry_dsn
clientside_sentry_enabled
koding_enabled
koding_url
sentry_dsn
sentry_enabled
]
cache_markdown_field
:sign_in_text
cache_markdown_field
:help_page_text
...
...
app/models/ci/build.rb
View file @
fa6f19d1
...
...
@@ -11,19 +11,20 @@ module Ci
include
ObjectStorage
::
BackgroundMove
include
Presentable
include
Importable
include
IgnorableColumn
include
Gitlab
::
Utils
::
StrongMemoize
include
Deployable
include
HasRef
BuildArchivedError
=
Class
.
new
(
StandardError
)
ignore_column
:commands
ignore_column
:artifacts_file
ignore_column
:artifacts_metadata
ignore_column
:artifacts_file_store
ignore_column
:artifacts_metadata_store
ignore_column
:artifacts_size
self
.
ignored_columns
=
%i[
artifacts_file
artifacts_file_store
artifacts_metadata
artifacts_metadata_store
artifacts_size
commands
]
belongs_to
:project
,
inverse_of: :builds
belongs_to
:runner
...
...
app/models/ci/runner.rb
View file @
fa6f19d1
...
...
@@ -4,7 +4,6 @@ module Ci
class
Runner
<
ApplicationRecord
extend
Gitlab
::
Ci
::
Model
include
Gitlab
::
SQL
::
Pattern
include
IgnorableColumn
include
RedisCacheable
include
ChronicDurationAttribute
include
FromUnion
...
...
@@ -36,7 +35,7 @@ module Ci
FORM_EDITABLE
=
%i[description tag_list active run_untagged locked access_level maximum_timeout_human_readable]
.
freeze
ignore_column
:is_shared
self
.
ignored_columns
=
%i[is_shared]
has_many
:builds
has_many
:runner_projects
,
inverse_of: :runner
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
...
...
app/models/concerns/ignorable_column.rb
deleted
100644 → 0
View file @
921d4f37
# frozen_string_literal: true
# Module that can be included into a model to make it easier to ignore database
# columns.
#
# Example:
#
# class User < ApplicationRecord
# include IgnorableColumn
#
# ignore_column :updated_at
# end
#
module
IgnorableColumn
extend
ActiveSupport
::
Concern
class_methods
do
def
columns
super
.
reject
{
|
column
|
ignored_columns
.
include?
(
column
.
name
)
}
end
def
ignored_columns
@ignored_columns
||=
Set
.
new
end
def
ignore_column
(
*
names
)
ignored_columns
.
merge
(
names
.
map
(
&
:to_s
))
end
end
end
app/models/deploy_key.rb
View file @
fa6f19d1
# frozen_string_literal: true
class
DeployKey
<
Key
include
IgnorableColumn
include
FromUnion
has_many
:deploy_keys_projects
,
inverse_of: :deploy_key
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
...
...
@@ -11,7 +10,7 @@ class DeployKey < Key
scope
:are_public
,
->
{
where
(
public:
true
)
}
scope
:with_projects
,
->
{
includes
(
deploy_keys_projects:
{
project:
[
:route
,
:namespace
]
})
}
ignore_column
:can_push
self
.
ignored_columns
=
%i[can_push]
accepts_nested_attributes_for
:deploy_keys_projects
...
...
app/models/event.rb
View file @
fa6f19d1
...
...
@@ -2,7 +2,6 @@
class
Event
<
ApplicationRecord
include
Sortable
include
IgnorableColumn
include
FromUnion
default_scope
{
reorder
(
nil
)
}
...
...
app/models/merge_request_diff.rb
View file @
fa6f19d1
...
...
@@ -4,7 +4,6 @@ class MergeRequestDiff < ApplicationRecord
include
Sortable
include
Importable
include
ManualInverseAssociation
include
IgnorableColumn
include
EachBatch
include
Gitlab
::
Utils
::
StrongMemoize
include
ObjectStorage
::
BackgroundMove
...
...
app/models/note.rb
View file @
fa6f19d1
...
...
@@ -14,7 +14,6 @@ class Note < ApplicationRecord
include
CacheMarkdownField
include
AfterCommitQueue
include
ResolvableNote
include
IgnorableColumn
include
Editable
include
Gitlab
::
SQL
::
Pattern
include
ThrottledTouch
...
...
@@ -34,7 +33,7 @@ class Note < ApplicationRecord
end
end
ignore_column
:original_discussion_id
self
.
ignored_columns
=
%i[original_discussion_id]
cache_markdown_field
:note
,
pipeline: :note
,
issuable_state_filter_enabled:
true
...
...
app/models/notification_setting.rb
View file @
fa6f19d1
# frozen_string_literal: true
class
NotificationSetting
<
ApplicationRecord
include
IgnorableColumn
ignore_column
:events
self
.
ignored_columns
=
%i[events]
enum
level:
{
global:
3
,
watch:
2
,
participating:
1
,
mention:
4
,
disabled:
0
,
custom:
5
}
...
...
app/models/user.rb
View file @
fa6f19d1
...
...
@@ -13,7 +13,6 @@ class User < ApplicationRecord
include
Sortable
include
CaseSensitivity
include
TokenAuthenticatable
include
IgnorableColumn
include
FeatureGate
include
CreatedAtFilterable
include
BulkMemberAccessLoad
...
...
@@ -24,9 +23,11 @@ class User < ApplicationRecord
DEFAULT_NOTIFICATION_LEVEL
=
:participating
ignore_column
:external_email
ignore_column
:email_provider
ignore_column
:authentication_token
self
.
ignored_columns
=
%i[
authentication_token
email_provider
external_email
]
add_authentication_token_field
:incoming_email_token
,
token_generator:
->
{
SecureRandom
.
hex
.
to_i
(
16
).
to_s
(
36
)
}
add_authentication_token_field
:feed_token
...
...
doc/development/what_requires_downtime.md
View file @
fa6f19d1
...
...
@@ -45,15 +45,12 @@ rule.
The first step is to ignore the column in the application code. This is
necessary because Rails caches the columns and re-uses this cache in various
places. This can be done by including the
`IgnorableColumn`
module into the
model, followed by defining the columns to ignore. For example, to ignore
places. This can be done by defining the columns to ignore. For example, to ignore
`updated_at`
in the User model you'd use the following:
```
ruby
class
User
<
ActiveRecord
::
Base
include
IgnorableColumn
ignore_column
:updated_at
class
User
<
ApplicationRecord
self
.
ignored_columns
=
%i[updated_at]
end
```
...
...
@@ -64,8 +61,7 @@ column. Both these changes should be submitted in the same merge request.
Once the changes from step 1 have been released & deployed you can set up a
separate merge request that removes the ignore rule. This merge request can
simply remove the
`ignore_column`
line, and the
`include IgnorableColumn`
line
if no other
`ignore_column`
calls remain.
simply remove the
`self.ignored_columns`
line.
## Renaming Columns
...
...
spec/models/concerns/ignorable_column_spec.rb
deleted
100644 → 0
View file @
921d4f37
# frozen_string_literal: true
require
'spec_helper'
describe
IgnorableColumn
do
let
:base_class
do
Class
.
new
do
def
self
.
columns
# This method does not have access to "double"
[
Struct
.
new
(
:name
).
new
(
'id'
),
Struct
.
new
(
:name
).
new
(
'title'
),
Struct
.
new
(
:name
).
new
(
'date'
)
]
end
end
end
let
:model
do
Class
.
new
(
base_class
)
do
include
IgnorableColumn
end
end
describe
'.columns'
do
it
'returns the columns, excluding the ignored ones'
do
model
.
ignore_column
(
:title
,
:date
)
expect
(
model
.
columns
.
map
(
&
:name
)).
to
eq
(
%w(id)
)
end
end
describe
'.ignored_columns'
do
it
'returns a Set'
do
expect
(
model
.
ignored_columns
).
to
be_an_instance_of
(
Set
)
end
it
'returns the names of the ignored columns'
do
model
.
ignore_column
(
:title
,
:date
)
expect
(
model
.
ignored_columns
).
to
eq
(
Set
.
new
(
%w(title date)
))
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment