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
ca01c4c6
Commit
ca01c4c6
authored
Jun 16, 2016
by
Paco Guzman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove Duplicated keys add UNIQUE index to fingerprint
parent
98cede7e
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
58 additions
and
3 deletions
+58
-3
CHANGELOG
CHANGELOG
+1
-0
app/models/key.rb
app/models/key.rb
+1
-1
db/migrate/20160616102642_remove_duplicated_keys.rb
db/migrate/20160616102642_remove_duplicated_keys.rb
+19
-0
db/migrate/20160616103005_remove_keys_fingerprint_index_if_exists.rb
...20160616103005_remove_keys_fingerprint_index_if_exists.rb
+21
-0
db/migrate/20160616103948_add_unique_index_to_keys_fingerprint.rb
...te/20160616103948_add_unique_index_to_keys_fingerprint.rb
+13
-0
db/schema.rb
db/schema.rb
+2
-1
spec/models/key_spec.rb
spec/models/key_spec.rb
+1
-1
No files found.
CHANGELOG
View file @
ca01c4c6
...
@@ -130,6 +130,7 @@ v 8.9.0 (unreleased)
...
@@ -130,6 +130,7 @@ v 8.9.0 (unreleased)
- Update tanuki logo highlight/loading colors
- Update tanuki logo highlight/loading colors
- Use Git cached counters for branches and tags on project page
- Use Git cached counters for branches and tags on project page
- Filter parameters for request_uri value on instrumented transactions.
- Filter parameters for request_uri value on instrumented transactions.
- Remove duplicated keys add UNIQUE index to keys fingerprint column
- Cache user todo counts from TodoService
- Cache user todo counts from TodoService
- Ensure Todos counters doesn't count Todos for projects pending delete
- Ensure Todos counters doesn't count Todos for projects pending delete
...
...
app/models/key.rb
View file @
ca01c4c6
...
@@ -9,7 +9,7 @@ class Key < ActiveRecord::Base
...
@@ -9,7 +9,7 @@ class Key < ActiveRecord::Base
before_validation
:strip_white_space
,
:generate_fingerprint
before_validation
:strip_white_space
,
:generate_fingerprint
validates
:title
,
presence:
true
,
length:
{
within:
0
..
255
}
validates
:title
,
presence:
true
,
length:
{
within:
0
..
255
}
validates
:key
,
presence:
true
,
length:
{
within:
0
..
5000
},
format:
{
with:
/\A(ssh|ecdsa)-.*\Z/
}
,
uniqueness:
true
validates
:key
,
presence:
true
,
length:
{
within:
0
..
5000
},
format:
{
with:
/\A(ssh|ecdsa)-.*\Z/
}
validates
:key
,
format:
{
without:
/\n|\r/
,
message:
'should be a single line'
}
validates
:key
,
format:
{
without:
/\n|\r/
,
message:
'should be a single line'
}
validates
:fingerprint
,
uniqueness:
true
,
presence:
{
message:
'cannot be generated'
}
validates
:fingerprint
,
uniqueness:
true
,
presence:
{
message:
'cannot be generated'
}
...
...
db/migrate/20160616102642_remove_duplicated_keys.rb
0 → 100644
View file @
ca01c4c6
# rubocop:disable all
class
RemoveDuplicatedKeys
<
ActiveRecord
::
Migration
def
up
select_all
(
"SELECT fingerprint FROM
#{
quote_table_name
(
:keys
)
}
GROUP BY fingerprint HAVING COUNT(*) > 1"
).
each
do
|
row
|
fingerprint
=
connection
.
quote
(
row
[
'fingerprint'
])
execute
(
%Q{
DELETE FROM keys
WHERE fingerprint =
#{
fingerprint
}
AND id != (
SELECT id FROM (
SELECT max(id) AS id
FROM keys
WHERE fingerprint =
#{
fingerprint
}
) max_ids
)
}
)
end
end
end
db/migrate/20160616103005_remove_keys_fingerprint_index_if_exists.rb
0 → 100644
View file @
ca01c4c6
class
RemoveKeysFingerprintIndexIfExists
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
disable_ddl_transaction!
# https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/250
# That MR was added on gitlab-ee so we need to check if the index
# already exists because we want to do is create an unique index instead.
def
up
if
index_exists?
(
:keys
,
:fingerprint
)
remove_index
:keys
,
:fingerprint
end
end
def
down
unless
index_exists?
(
:keys
,
:fingerprint
)
add_concurrent_index
:keys
,
:fingerprint
end
end
end
db/migrate/20160616103948_add_unique_index_to_keys_fingerprint.rb
0 → 100644
View file @
ca01c4c6
class
AddUniqueIndexToKeysFingerprint
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
disable_ddl_transaction!
def
up
add_concurrent_index
:keys
,
:fingerprint
,
unique:
true
end
def
down
remove_index
:keys
,
:fingerprint
end
end
db/schema.rb
View file @
ca01c4c6
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#
#
# It's strongly recommended that you check this file into your version control system.
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
20160616
084004
)
do
ActiveRecord
::
Schema
.
define
(
version:
20160616
103948
)
do
# These are extensions that must be enabled in order to support this database
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
enable_extension
"plpgsql"
...
@@ -507,6 +507,7 @@ ActiveRecord::Schema.define(version: 20160616084004) do
...
@@ -507,6 +507,7 @@ ActiveRecord::Schema.define(version: 20160616084004) do
end
end
add_index
"keys"
,
[
"created_at"
,
"id"
],
name:
"index_keys_on_created_at_and_id"
,
using: :btree
add_index
"keys"
,
[
"created_at"
,
"id"
],
name:
"index_keys_on_created_at_and_id"
,
using: :btree
add_index
"keys"
,
[
"fingerprint"
],
name:
"index_keys_on_fingerprint"
,
unique:
true
,
using: :btree
add_index
"keys"
,
[
"user_id"
],
name:
"index_keys_on_user_id"
,
using: :btree
add_index
"keys"
,
[
"user_id"
],
name:
"index_keys_on_user_id"
,
using: :btree
create_table
"label_links"
,
force: :cascade
do
|
t
|
create_table
"label_links"
,
force: :cascade
do
|
t
|
...
...
spec/models/key_spec.rb
View file @
ca01c4c6
...
@@ -26,7 +26,7 @@ describe Key, models: true do
...
@@ -26,7 +26,7 @@ describe Key, models: true do
end
end
end
end
context
"validation of uniqueness"
do
context
"validation of uniqueness
(based on fingerprint uniqueness)
"
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
it
"accepts the key once"
do
it
"accepts the key once"
do
...
...
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