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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
3d4cfad4
Commit
3d4cfad4
authored
Mar 07, 2018
by
Mayra Cabrera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure orphaned rows are deleted before adding the foreign key
parent
e9657acf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
2 deletions
+18
-2
db/migrate/20180302152117_ensure_foreign_keys_on_clusters_applications.rb
...302152117_ensure_foreign_keys_on_clusters_applications.rb
+16
-0
db/schema.rb
db/schema.rb
+2
-2
No files found.
db/migrate/20180302152117_ensure_foreign_keys_on_clusters_applications.rb
View file @
3d4cfad4
...
@@ -9,12 +9,28 @@ class EnsureForeignKeysOnClustersApplications < ActiveRecord::Migration
...
@@ -9,12 +9,28 @@ class EnsureForeignKeysOnClustersApplications < ActiveRecord::Migration
disable_ddl_transaction!
disable_ddl_transaction!
def
up
def
up
existing
=
Clusters
::
Cluster
.
joins
(
:application_ingress
)
.
where
(
'clusters.id = clusters_applications_ingress.cluster_id'
)
Clusters
::
Applications
::
Ingress
.
where
(
'NOT EXISTS (?)'
,
existing
).
in_batches
do
|
batch
|
batch
.
delete_all
end
unless
foreign_keys_for
(
:clusters_applications_ingress
,
:cluster_id
).
any?
unless
foreign_keys_for
(
:clusters_applications_ingress
,
:cluster_id
).
any?
add_concurrent_foreign_key
:clusters_applications_ingress
,
:clusters
,
add_concurrent_foreign_key
:clusters_applications_ingress
,
:clusters
,
column: :cluster_id
,
column: :cluster_id
,
on_delete: :cascade
on_delete: :cascade
end
end
existing
=
Clusters
::
Cluster
.
joins
(
:application_prometheus
)
.
where
(
'clusters.id = clusters_applications_prometheus.cluster_id'
)
Clusters
::
Applications
::
Ingress
.
where
(
'NOT EXISTS (?)'
,
existing
).
in_batches
do
|
batch
|
batch
.
delete_all
end
unless
foreign_keys_for
(
:clusters_applications_prometheus
,
:cluster_id
).
any?
unless
foreign_keys_for
(
:clusters_applications_prometheus
,
:cluster_id
).
any?
add_concurrent_foreign_key
:clusters_applications_prometheus
,
:clusters
,
add_concurrent_foreign_key
:clusters_applications_prometheus
,
:clusters
,
column: :cluster_id
,
column: :cluster_id
,
...
...
db/schema.rb
View file @
3d4cfad4
...
@@ -2028,8 +2028,8 @@ ActiveRecord::Schema.define(version: 20180307012445) do
...
@@ -2028,8 +2028,8 @@ ActiveRecord::Schema.define(version: 20180307012445) do
add_foreign_key
"cluster_providers_gcp"
,
"clusters"
,
on_delete: :cascade
add_foreign_key
"cluster_providers_gcp"
,
"clusters"
,
on_delete: :cascade
add_foreign_key
"clusters"
,
"users"
,
on_delete: :nullify
add_foreign_key
"clusters"
,
"users"
,
on_delete: :nullify
add_foreign_key
"clusters_applications_helm"
,
"clusters"
,
on_delete: :cascade
add_foreign_key
"clusters_applications_helm"
,
"clusters"
,
on_delete: :cascade
add_foreign_key
"clusters_applications_ingress"
,
"clusters"
,
on_delete: :cascade
add_foreign_key
"clusters_applications_ingress"
,
"clusters"
,
name:
"fk_753a7b41c1"
,
on_delete: :cascade
add_foreign_key
"clusters_applications_prometheus"
,
"clusters"
,
on_delete: :cascade
add_foreign_key
"clusters_applications_prometheus"
,
"clusters"
,
name:
"fk_557e773639"
,
on_delete: :cascade
add_foreign_key
"clusters_applications_runners"
,
"ci_runners"
,
column:
"runner_id"
,
name:
"fk_02de2ded36"
,
on_delete: :nullify
add_foreign_key
"clusters_applications_runners"
,
"ci_runners"
,
column:
"runner_id"
,
name:
"fk_02de2ded36"
,
on_delete: :nullify
add_foreign_key
"clusters_applications_runners"
,
"clusters"
,
on_delete: :cascade
add_foreign_key
"clusters_applications_runners"
,
"clusters"
,
on_delete: :cascade
add_foreign_key
"container_repositories"
,
"projects"
add_foreign_key
"container_repositories"
,
"projects"
...
...
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