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
bf0b1a98
Commit
bf0b1a98
authored
Sep 06, 2021
by
Marcos Rocha
Committed by
Dylan Griffith
Sep 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add data migration to remove duplicate DastSiteTokens with same token
parent
319c6903
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
0 deletions
+79
-0
db/post_migrate/20210825182303_remove_duplicate_dast_site_tokens_with_same_token.rb
...2303_remove_duplicate_dast_site_tokens_with_same_token.rb
+23
-0
db/schema_migrations/20210825182303
db/schema_migrations/20210825182303
+1
-0
db/structure.sql
db/structure.sql
+2
-0
spec/migrations/remove_duplicate_dast_site_tokens_with_same_token_spec.rb
...remove_duplicate_dast_site_tokens_with_same_token_spec.rb
+53
-0
No files found.
db/post_migrate/20210825182303_remove_duplicate_dast_site_tokens_with_same_token.rb
0 → 100644
View file @
bf0b1a98
# frozen_string_literal: true
class
RemoveDuplicateDastSiteTokensWithSameToken
<
ActiveRecord
::
Migration
[
6.1
]
include
Gitlab
::
Database
::
MigrationHelpers
INDEX_NAME
=
'index_dast_site_token_on_token'
# rubocop: disable Migration/AddIndex
def
up
execute
(
"WITH duplicate_tokens AS(
SELECT id, rank() OVER (PARTITION BY token ORDER BY id) r FROM dast_site_tokens
)
DELETE FROM dast_site_tokens c USING duplicate_tokens t
WHERE c.id = t.id AND t.r > 1;"
)
add_index
:dast_site_tokens
,
:token
,
name:
INDEX_NAME
,
unique:
true
end
# rubocop: disable Migration/RemoveIndex
def
down
remove_index
:dast_site_tokens
,
:token
,
name:
INDEX_NAME
end
end
db/schema_migrations/20210825182303
0 → 100644
View file @
bf0b1a98
a7f4911fcb9ab939a6e5e9a6e5e927fd6828ff062324d8483d78c8f8a4ded4e6
\ No newline at end of file
db/structure.sql
View file @
bf0b1a98
...
...
@@ -24821,6 +24821,8 @@ CREATE UNIQUE INDEX index_dast_site_profiles_pipelines_on_ci_pipeline_id ON dast
CREATE UNIQUE INDEX index_dast_site_token_on_project_id_and_url ON dast_site_tokens USING btree (project_id, url);
CREATE UNIQUE INDEX index_dast_site_token_on_token ON dast_site_tokens USING btree (token);
CREATE INDEX index_dast_site_tokens_on_project_id ON dast_site_tokens USING btree (project_id);
CREATE INDEX index_dast_site_validations_on_dast_site_token_id ON dast_site_validations USING btree (dast_site_token_id);
spec/migrations/remove_duplicate_dast_site_tokens_with_same_token_spec.rb
0 → 100644
View file @
bf0b1a98
# frozen_string_literal: true
require
'spec_helper'
require_migration!
RSpec
.
describe
RemoveDuplicateDastSiteTokensWithSameToken
do
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:dast_site_tokens
)
{
table
(
:dast_site_tokens
)
}
let!
(
:namespace
)
{
namespaces
.
create!
(
id:
1
,
name:
'group'
,
path:
'group'
)
}
let!
(
:project1
)
{
projects
.
create!
(
id:
1
,
namespace_id:
namespace
.
id
,
path:
'project1'
)
}
# create non duplicate dast site token
let!
(
:dast_site_token1
)
{
dast_site_tokens
.
create!
(
project_id:
project1
.
id
,
url:
'https://gitlab.com'
,
token:
SecureRandom
.
uuid
)
}
context
'when duplicate dast site tokens exists'
do
# create duplicate dast site token
let_it_be
(
:duplicate_token
)
{
'duplicate_token'
}
let_it_be
(
:other_duplicate_token
)
{
'other_duplicate_token'
}
let!
(
:project2
)
{
projects
.
create!
(
id:
2
,
namespace_id:
namespace
.
id
,
path:
'project2'
)
}
let!
(
:dast_site_token2
)
{
dast_site_tokens
.
create!
(
project_id:
project2
.
id
,
url:
'https://gitlab2.com'
,
token:
duplicate_token
)
}
let!
(
:dast_site_token3
)
{
dast_site_tokens
.
create!
(
project_id:
project2
.
id
,
url:
'https://gitlab3.com'
,
token:
duplicate_token
)
}
let!
(
:dast_site_token4
)
{
dast_site_tokens
.
create!
(
project_id:
project2
.
id
,
url:
'https://gitlab4.com'
,
token:
duplicate_token
)
}
let!
(
:project3
)
{
projects
.
create!
(
id:
3
,
namespace_id:
namespace
.
id
,
path:
'project3'
)
}
let!
(
:dast_site_token5
)
{
dast_site_tokens
.
create!
(
project_id:
project3
.
id
,
url:
'https://gitlab2.com'
,
token:
other_duplicate_token
)
}
let!
(
:dast_site_token6
)
{
dast_site_tokens
.
create!
(
project_id:
project3
.
id
,
url:
'https://gitlab3.com'
,
token:
other_duplicate_token
)
}
let!
(
:dast_site_token7
)
{
dast_site_tokens
.
create!
(
project_id:
project3
.
id
,
url:
'https://gitlab4.com'
,
token:
other_duplicate_token
)
}
describe
'migration up'
do
it
'does remove duplicated dast site tokens with the same token'
do
expect
(
dast_site_tokens
.
count
).
to
eq
(
7
)
expect
(
dast_site_tokens
.
where
(
token:
duplicate_token
).
size
).
to
eq
(
3
)
migrate!
expect
(
dast_site_tokens
.
count
).
to
eq
(
3
)
expect
(
dast_site_tokens
.
where
(
token:
duplicate_token
).
size
).
to
eq
(
1
)
end
end
end
context
'when duplicate dast site tokens do not exist'
do
let!
(
:dast_site_token5
)
{
dast_site_tokens
.
create!
(
project_id:
1
,
url:
'https://gitlab5.com'
,
token:
SecureRandom
.
uuid
)
}
describe
'migration up'
do
it
'does not remove any dast site tokens'
do
expect
{
migrate!
}.
not_to
change
(
dast_site_tokens
,
:count
)
end
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