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
a84476b5
Commit
a84476b5
authored
Jul 30, 2020
by
Aakriti Gupta
Committed by
Michael Kozono
Jul 30, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate binary column exists when geo is enabled
and only in dev
parent
d896709f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
15 deletions
+6
-15
app/models/concerns/sha_attribute.rb
app/models/concerns/sha_attribute.rb
+3
-10
spec/models/concerns/sha_attribute_spec.rb
spec/models/concerns/sha_attribute_spec.rb
+3
-5
No files found.
app/models/concerns/sha_attribute.rb
View file @
a84476b5
...
@@ -7,7 +7,7 @@ module ShaAttribute
...
@@ -7,7 +7,7 @@ module ShaAttribute
def
sha_attribute
(
name
)
def
sha_attribute
(
name
)
return
if
ENV
[
'STATIC_VERIFICATION'
]
return
if
ENV
[
'STATIC_VERIFICATION'
]
validate_binary_column_exists!
(
name
)
unless
Rails
.
env
.
production
?
validate_binary_column_exists!
(
name
)
if
Rails
.
env
.
development
?
attribute
(
name
,
Gitlab
::
Database
::
ShaAttribute
.
new
)
attribute
(
name
,
Gitlab
::
Database
::
ShaAttribute
.
new
)
end
end
...
@@ -17,18 +17,11 @@ module ShaAttribute
...
@@ -17,18 +17,11 @@ module ShaAttribute
# See https://gitlab.com/gitlab-org/gitlab/merge_requests/5502 for more discussion
# See https://gitlab.com/gitlab-org/gitlab/merge_requests/5502 for more discussion
def
validate_binary_column_exists!
(
name
)
def
validate_binary_column_exists!
(
name
)
return
unless
database_exists?
return
unless
database_exists?
return
unless
table_exists?
unless
table_exists?
warn
"WARNING: sha_attribute
#{
name
.
inspect
}
is invalid since the table doesn't exist - you may need to run database migrations"
return
end
column
=
columns
.
find
{
|
c
|
c
.
name
==
name
.
to_s
}
column
=
columns
.
find
{
|
c
|
c
.
name
==
name
.
to_s
}
unless
column
return
unless
column
warn
"WARNING: sha_attribute
#{
name
.
inspect
}
is invalid since the column doesn't exist - you may need to run database migrations"
return
end
unless
column
.
type
==
:binary
unless
column
.
type
==
:binary
raise
ArgumentError
.
new
(
"sha_attribute
#{
name
.
inspect
}
is invalid since the column type is not :binary"
)
raise
ArgumentError
.
new
(
"sha_attribute
#{
name
.
inspect
}
is invalid since the column type is not :binary"
)
...
...
spec/models/concerns/sha_attribute_spec.rb
View file @
a84476b5
...
@@ -15,7 +15,7 @@ RSpec.describe ShaAttribute do
...
@@ -15,7 +15,7 @@ RSpec.describe ShaAttribute do
end
end
describe
'#sha_attribute'
do
describe
'#sha_attribute'
do
context
'when in
non-production
'
do
context
'when in
development
'
do
before
do
before
do
stub_rails_env
(
'development'
)
stub_rails_env
(
'development'
)
end
end
...
@@ -38,24 +38,22 @@ RSpec.describe ShaAttribute do
...
@@ -38,24 +38,22 @@ RSpec.describe ShaAttribute do
end
end
context
'when the table does not exist'
do
context
'when the table does not exist'
do
it
'allows the attribute to be added
and issues a warning
'
do
it
'allows the attribute to be added'
do
allow
(
model
).
to
receive
(
:table_exists?
).
and_return
(
false
)
allow
(
model
).
to
receive
(
:table_exists?
).
and_return
(
false
)
expect
(
model
).
not_to
receive
(
:columns
)
expect
(
model
).
not_to
receive
(
:columns
)
expect
(
model
).
to
receive
(
:attribute
)
expect
(
model
).
to
receive
(
:attribute
)
expect
(
model
).
to
receive
(
:warn
)
model
.
sha_attribute
(
:name
)
model
.
sha_attribute
(
:name
)
end
end
end
end
context
'when the column does not exist'
do
context
'when the column does not exist'
do
it
'allows the attribute to be added
and issues a warning
'
do
it
'allows the attribute to be added'
do
allow
(
model
).
to
receive
(
:table_exists?
).
and_return
(
true
)
allow
(
model
).
to
receive
(
:table_exists?
).
and_return
(
true
)
expect
(
model
).
to
receive
(
:columns
)
expect
(
model
).
to
receive
(
:columns
)
expect
(
model
).
to
receive
(
:attribute
)
expect
(
model
).
to
receive
(
:attribute
)
expect
(
model
).
to
receive
(
:warn
)
model
.
sha_attribute
(
:no_name
)
model
.
sha_attribute
(
:no_name
)
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