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
1b190ea5
Commit
1b190ea5
authored
Apr 23, 2020
by
Adam Hegyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adjust rubocop rule for not valid FKs
parent
bf0f5ac9
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
20 additions
and
8 deletions
+20
-8
db/migrate/20200215222507_drop_forked_project_links_fk.rb
db/migrate/20200215222507_drop_forked_project_links_fk.rb
+0
-1
db/migrate/20200407171133_add_protected_tag_create_access_levels_user_id_foreign_key.rb
...protected_tag_create_access_levels_user_id_foreign_key.rb
+0
-1
db/migrate/20200408154331_add_protected_branch_merge_access_levels_user_id_foreign_key.rb
...otected_branch_merge_access_levels_user_id_foreign_key.rb
+0
-1
db/migrate/20200408154411_add_path_locks_user_id_foreign_key.rb
...rate/20200408154411_add_path_locks_user_id_foreign_key.rb
+0
-1
db/migrate/20200408154455_add_protected_branch_push_access_levels_user_id_foreign_key.rb
...rotected_branch_push_access_levels_user_id_foreign_key.rb
+0
-1
db/migrate/20200408154604_add_u2f_registrations_user_id_foreign_key.rb
...200408154604_add_u2f_registrations_user_id_foreign_key.rb
+0
-1
doc/development/database/add_foreign_key_to_existing_column.md
...evelopment/database/add_foreign_key_to_existing_column.md
+1
-1
rubocop/cop/migration/add_concurrent_foreign_key.rb
rubocop/cop/migration/add_concurrent_foreign_key.rb
+13
-1
spec/rubocop/cop/migration/add_concurrent_foreign_key_spec.rb
.../rubocop/cop/migration/add_concurrent_foreign_key_spec.rb
+6
-0
No files found.
db/migrate/20200215222507_drop_forked_project_links_fk.rb
View file @
1b190ea5
...
...
@@ -19,7 +19,6 @@ class DropForkedProjectLinksFk < ActiveRecord::Migration[6.0]
unless
foreign_key_exists?
(
:forked_project_links
,
:projects
,
column: :forked_to_project_id
)
# rubocop: disable Migration/WithLockRetriesWithoutDdlTransaction
with_lock_retries
do
# rubocop: disable Migration/AddConcurrentForeignKey
add_foreign_key
:forked_project_links
,
:projects
,
column: :forked_to_project_id
,
on_delete: :cascade
,
validate:
false
end
# rubocop: enable Migration/WithLockRetriesWithoutDdlTransaction
...
...
db/migrate/20200407171133_add_protected_tag_create_access_levels_user_id_foreign_key.rb
View file @
1b190ea5
# frozen_string_literal: true
# rubocop: disable Migration/AddConcurrentForeignKey
# rubocop: disable Migration/WithLockRetriesWithoutDdlTransaction
class
AddProtectedTagCreateAccessLevelsUserIdForeignKey
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
...
...
db/migrate/20200408154331_add_protected_branch_merge_access_levels_user_id_foreign_key.rb
View file @
1b190ea5
# frozen_string_literal: true
# rubocop: disable Migration/AddConcurrentForeignKey
# rubocop: disable Migration/WithLockRetriesWithoutDdlTransaction
class
AddProtectedBranchMergeAccessLevelsUserIdForeignKey
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
...
...
db/migrate/20200408154411_add_path_locks_user_id_foreign_key.rb
View file @
1b190ea5
# frozen_string_literal: true
# rubocop: disable Migration/AddConcurrentForeignKey
# rubocop: disable Migration/WithLockRetriesWithoutDdlTransaction
class
AddPathLocksUserIdForeignKey
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
...
...
db/migrate/20200408154455_add_protected_branch_push_access_levels_user_id_foreign_key.rb
View file @
1b190ea5
# frozen_string_literal: true
# rubocop: disable Migration/AddConcurrentForeignKey
# rubocop: disable Migration/WithLockRetriesWithoutDdlTransaction
class
AddProtectedBranchPushAccessLevelsUserIdForeignKey
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
...
...
db/migrate/20200408154604_add_u2f_registrations_user_id_foreign_key.rb
View file @
1b190ea5
# frozen_string_literal: true
# rubocop: disable Migration/AddConcurrentForeignKey
# rubocop: disable Migration/WithLockRetriesWithoutDdlTransaction
class
AddU2fRegistrationsUserIdForeignKey
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
...
...
doc/development/database/add_foreign_key_to_existing_column.md
View file @
1b190ea5
...
...
@@ -64,7 +64,7 @@ class AddNotValidForeignKeyToEmailsUser < ActiveRecord::Migration[5.2]
def
up
# safe to use: it requires short lock on the table since we don't validate the foreign key
add_foreign_key
:emails
,
:users
,
on_delete: :cascade
,
validate:
false
# rubocop:disable Migration/AddConcurrentForeignKey
add_foreign_key
:emails
,
:users
,
on_delete: :cascade
,
validate:
false
end
def
down
...
...
rubocop/cop/migration/add_concurrent_foreign_key.rb
View file @
1b190ea5
...
...
@@ -10,17 +10,29 @@ module RuboCop
MSG
=
'`add_foreign_key` requires downtime, use `add_concurrent_foreign_key` instead'
.
freeze
def_node_matcher
:false_node?
,
<<~
PATTERN
(false)
PATTERN
def
on_send
(
node
)
return
unless
in_migration?
(
node
)
name
=
node
.
children
[
1
]
add_offense
(
node
,
location: :selector
)
if
name
==
:add_foreign_key
if
name
==
:add_foreign_key
&&
!
not_valid_fk?
(
node
)
add_offense
(
node
,
location: :selector
)
end
end
def
method_name
(
node
)
node
.
children
.
first
end
def
not_valid_fk?
(
node
)
node
.
each_node
(
:pair
).
any?
do
|
pair
|
pair
.
children
[
0
].
children
[
0
]
==
:validate
&&
false_node?
(
pair
.
children
[
1
])
end
end
end
end
end
...
...
spec/rubocop/cop/migration/add_concurrent_foreign_key_spec.rb
View file @
1b190ea5
...
...
@@ -33,5 +33,11 @@ describe RuboCop::Cop::Migration::AddConcurrentForeignKey do
expect
(
cop
.
offenses
.
map
(
&
:line
)).
to
eq
([
1
])
end
end
it
'does not register an offense when a `NOT VALID` foreign key is added'
do
inspect_source
(
'def up; add_foreign_key(:projects, :users, column: :user_id, validate: false); end'
)
expect
(
cop
.
offenses
).
to
be_empty
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