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
c17f631a
Commit
c17f631a
authored
Oct 18, 2018
by
Toon Claes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Temporary drop foreign key when database is MySQL
parent
79a986f7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
17 deletions
+64
-17
db/schema.rb
db/schema.rb
+2
-1
ee/db/migrate/20181017131623_add_missing_geo_even_log_indexes.rb
...igrate/20181017131623_add_missing_geo_even_log_indexes.rb
+62
-16
No files found.
db/schema.rb
View file @
c17f631a
...
...
@@ -3225,6 +3225,7 @@ ActiveRecord::Schema.define(version: 20181017131623) do
add_foreign_key
"gcp_clusters"
,
"services"
,
on_delete: :nullify
add_foreign_key
"gcp_clusters"
,
"users"
,
on_delete: :nullify
add_foreign_key
"geo_event_log"
,
"geo_cache_invalidation_events"
,
column:
"cache_invalidation_event_id"
,
name:
"fk_42c3b54bed"
,
on_delete: :cascade
add_foreign_key
"geo_event_log"
,
"geo_hashed_storage_attachments_events"
,
column:
"hashed_storage_attachments_event_id"
,
name:
"fk_304067fc30"
,
on_delete: :cascade
add_foreign_key
"geo_event_log"
,
"geo_hashed_storage_migrated_events"
,
column:
"hashed_storage_migrated_event_id"
,
name:
"fk_27548c6db3"
,
on_delete: :cascade
add_foreign_key
"geo_event_log"
,
"geo_job_artifact_deleted_events"
,
column:
"job_artifact_deleted_event_id"
,
name:
"fk_176d3fbb5d"
,
on_delete: :cascade
add_foreign_key
"geo_event_log"
,
"geo_lfs_object_deleted_events"
,
column:
"lfs_object_deleted_event_id"
,
name:
"fk_d5af95fcd9"
,
on_delete: :cascade
...
...
@@ -3232,7 +3233,7 @@ ActiveRecord::Schema.define(version: 20181017131623) do
add_foreign_key
"geo_event_log"
,
"geo_repository_created_events"
,
column:
"repository_created_event_id"
,
name:
"fk_9b9afb1916"
,
on_delete: :cascade
add_foreign_key
"geo_event_log"
,
"geo_repository_deleted_events"
,
column:
"repository_deleted_event_id"
,
name:
"fk_c4b1c1f66e"
,
on_delete: :cascade
add_foreign_key
"geo_event_log"
,
"geo_repository_renamed_events"
,
column:
"repository_renamed_event_id"
,
name:
"fk_86c84214ec"
,
on_delete: :cascade
add_foreign_key
"geo_event_log"
,
"geo_repository_updated_events"
,
column:
"repository_updated_event_id"
,
on_delete: :cascade
add_foreign_key
"geo_event_log"
,
"geo_repository_updated_events"
,
column:
"repository_updated_event_id"
,
name:
"fk_78a6492f68"
,
on_delete: :cascade
add_foreign_key
"geo_event_log"
,
"geo_reset_checksum_events"
,
column:
"reset_checksum_event_id"
,
name:
"fk_cff7185ad2"
,
on_delete: :cascade
add_foreign_key
"geo_event_log"
,
"geo_upload_deleted_events"
,
column:
"upload_deleted_event_id"
,
name:
"fk_c1f241c70d"
,
on_delete: :cascade
add_foreign_key
"geo_hashed_storage_attachments_events"
,
"projects"
,
on_delete: :cascade
...
...
ee/db/migrate/20181017131623_add_missing_geo_even_log_indexes.rb
View file @
c17f631a
...
...
@@ -12,37 +12,83 @@ class AddMissingGeoEvenLogIndexes < ActiveRecord::Migration
repository_updated_event_id
reset_checksum_event_id]
OTHER_COLUMNS
=
%i[hashed_storage_migrated_event_id
lfs_object_deleted_event_id
hashed_storage_attachments_event_id
job_artifact_deleted_event_id
upload_deleted_event_id]
NON_INDEXED_COLUMNS
=
%i[hashed_storage_migrated_event_id
lfs_object_deleted_event_id
hashed_storage_attachments_event_id
job_artifact_deleted_event_id
upload_deleted_event_id]
MISSING_FK_COLUMNS
=
%i[hashed_storage_attachments_event_id]
disable_ddl_transaction!
def
up
# Re
move existing indexes that aren't partial
# Re
place existing indexes with partial indexes
INDEXED_COLUMNS
.
each
do
|
col
|
remove_concurrent_index
(
:geo_event_log
,
col
)
without_foreign_key
(
:geo_event_log
,
col
)
do
remove_concurrent_index
(
:geo_event_log
,
col
)
add_concurrent_index_not_null
(
:geo_event_log
,
col
)
end
end
# Create partial indexes on non-indexed columns
NON_INDEXED_COLUMNS
.
each
do
|
col
|
add_concurrent_index_not_null
(
:geo_event_log
,
col
)
end
# Create partial indexes on all
(
INDEXED_COLUMNS
+
OTHER_COLUMNS
).
each
do
|
col
|
add_concurrent_index
(
:geo_event_log
,
col
,
where:
"
#{
col
}
IS NOT NULL"
)
# Add missing foreign keys
MISSING_FK_COLUMNS
.
each
do
|
col
|
add_concurrent_foreign_key
(
:geo_event_log
,
foreign_table_name
(
col
),
column:
col
,
on_delete: :cascade
)
end
end
def
down
# Rollback all partial indexes
(
INDEXED_COLUMNS
+
OTHER_COLUMNS
).
each
do
|
col
|
remove_concurrent_index
(
:geo_event_log
,
col
)
# Remove missing foreign keys again
MISSING_FK_COLUMNS
.
each
do
|
col
|
remove_foreign_key
(
:geo_event_log
,
column:
col
)
end
# Drop indexes that didn't exist before
NON_INDEXED_COLUMNS
.
each
do
|
col
|
without_foreign_key
(
:geo_event_log
,
col
)
do
remove_concurrent_index
(
:geo_event_log
,
col
)
end
end
# Recreate full indexes
INDEXED_COLUMNS
.
each
do
|
col
|
add_concurrent_index
(
:geo_event_log
,
col
)
without_foreign_key
(
:geo_event_log
,
col
)
do
remove_concurrent_index
(
:geo_event_log
,
col
)
add_concurrent_index
(
:geo_event_log
,
col
)
end
end
end
private
def
add_concurrent_index_not_null
(
table
,
col
)
add_concurrent_index
(
table
,
col
,
where:
"
#{
col
}
IS NOT NULL"
)
end
def
without_foreign_key
(
table
,
col
)
return
yield
unless
drop_foreign_key?
(
table
,
col
)
begin
remove_foreign_key
(
table
,
column:
col
)
yield
ensure
add_concurrent_foreign_key
(
table
,
foreign_table_name
(
col
),
column:
col
,
on_delete: :cascade
)
end
end
def
drop_foreign_key?
(
table
,
col
)
Gitlab
::
Database
.
mysql?
&&
foreign_key_exists?
(
table
,
column:
col
)
end
def
foreign_table_name
(
col
)
(
'geo_'
+
col
.
to_s
.
sub
(
/_id$/
,
''
)).
pluralize
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