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
a0e76d5c
Commit
a0e76d5c
authored
Sep 11, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
d442eca8
70302281
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
112 additions
and
0 deletions
+112
-0
doc/development/rake_tasks.md
doc/development/rake_tasks.md
+10
-0
lib/gitlab/database/obsolete_ignored_columns.rb
lib/gitlab/database/obsolete_ignored_columns.rb
+38
-0
lib/tasks/db_obsolete_ignored_columns.rake
lib/tasks/db_obsolete_ignored_columns.rake
+21
-0
spec/lib/gitlab/database/obsolete_ignored_columns_spec.rb
spec/lib/gitlab/database/obsolete_ignored_columns_spec.rb
+43
-0
No files found.
doc/development/rake_tasks.md
View file @
a0e76d5c
...
...
@@ -216,3 +216,13 @@ bundle exec rake routes
Since these take some time to create, it's often helpful to save the output to
a file for quick reference.
## Show obsolete `ignored_columns`
To see a list of all obsolete
`ignored_columns`
run:
```
bundle exec rake db:obsolete_ignored_columns
```
Feel free to remove their definitions from their
`ignored_columns`
definitions.
lib/gitlab/database/obsolete_ignored_columns.rb
0 → 100644
View file @
a0e76d5c
# frozen_string_literal: true
module
Gitlab
module
Database
# Checks which `ignored_columns` can be safely removed by scanning
# the current schema for all `ApplicationRecord` descendants.
class
ObsoleteIgnoredColumns
def
initialize
(
base
=
ApplicationRecord
)
@base
=
base
end
def
execute
@base
.
descendants
.
map
do
|
klass
|
next
if
klass
.
abstract_class?
safe_to_remove
=
ignored_columns_safe_to_remove_for
(
klass
)
next
if
safe_to_remove
.
empty?
[
klass
.
name
,
safe_to_remove
]
end
.
compact
.
sort_by
(
&
:first
)
end
private
def
ignored_columns_safe_to_remove_for
(
klass
)
ignored
=
klass
.
ignored_columns
.
map
(
&
:to_s
)
return
[]
if
ignored
.
empty?
schema
=
klass
.
connection
.
schema_cache
.
columns_hash
(
klass
.
table_name
)
existing
=
schema
.
values
.
map
(
&
:name
)
used
=
ignored
&
existing
ignored
-
used
end
end
end
end
lib/tasks/db_obsolete_ignored_columns.rake
0 → 100644
View file @
a0e76d5c
desc
'Show a list of obsolete `ignored_columns`'
task
'db:obsolete_ignored_columns'
=>
:environment
do
list
=
Gitlab
::
Database
::
ObsoleteIgnoredColumns
.
new
.
execute
if
list
.
empty?
puts
'No obsolete `ignored_columns` found.'
else
puts
'The following `ignored_columns` are obsolete and can be removed:'
list
.
each
do
|
name
,
ignored_columns
|
puts
"-
#{
name
}
:
#{
ignored_columns
.
join
(
', '
)
}
"
end
puts
<<~
TEXT
WARNING: Removing columns is tricky because running GitLab processes may still be using the columns.
See also https://docs.gitlab.com/ee/development/what_requires_downtime.html#dropping-columns
TEXT
end
end
spec/lib/gitlab/database/obsolete_ignored_columns_spec.rb
0 → 100644
View file @
a0e76d5c
# frozen_string_literal: true
require
'spec_helper'
describe
Gitlab
::
Database
::
ObsoleteIgnoredColumns
do
module
Testing
class
MyBase
<
ApplicationRecord
end
class
SomeAbstract
<
MyBase
self
.
abstract_class
=
true
self
.
table_name
=
'projects'
self
.
ignored_columns
+=
%i[unused]
end
class
B
<
MyBase
self
.
table_name
=
'issues'
self
.
ignored_columns
+=
%i[id other]
end
class
A
<
SomeAbstract
self
.
ignored_columns
+=
%i[id also_unused]
end
class
C
<
MyBase
self
.
table_name
=
'users'
end
end
subject
{
described_class
.
new
(
Testing
::
MyBase
)
}
describe
'#execute'
do
it
'returns a list of class names and columns pairs'
do
expect
(
subject
.
execute
).
to
eq
([
[
'Testing::A'
,
%w(unused also_unused)
],
[
'Testing::B'
,
%w(other)
]
])
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