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
2d3e84ef
Commit
2d3e84ef
authored
Sep 05, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
7c61c977
dd80d622
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
39 deletions
+46
-39
doc/development/what_requires_downtime.md
doc/development/what_requires_downtime.md
+2
-2
lib/gitlab/database/migration_helpers.rb
lib/gitlab/database/migration_helpers.rb
+44
-37
No files found.
doc/development/what_requires_downtime.md
View file @
2d3e84ef
...
...
@@ -88,7 +88,7 @@ class RenameUsersUpdatedAtToUpdatedAtTimestamp < ActiveRecord::Migration[4.2]
end
def
down
cleanup_concurrent_column_rename
:users
,
:updated_at_timestamp
,
:updated_at
undo_rename_column_concurrently
:users
,
:updated_at
,
:updated_at_timestamp
end
end
```
...
...
@@ -118,7 +118,7 @@ class CleanupUsersUpdatedAtRename < ActiveRecord::Migration[4.2]
end
def
down
rename_column_concurrently
:users
,
:updated_at_timestamp
,
:updated_at
undo_cleanup_concurrent_column_rename
:users
,
:updated_at
,
:updated_at_timestamp
end
end
```
...
...
lib/gitlab/database/migration_helpers.rb
View file @
2d3e84ef
...
...
@@ -459,29 +459,19 @@ module Gitlab
check_trigger_permissions!
(
table
)
old_col
=
column_for
(
table
,
old
)
new_type
=
type
||
old_col
.
type
add_column
(
table
,
new
,
new_type
,
limit:
old_col
.
limit
,
precision:
old_col
.
precision
,
scale:
old_col
.
scale
)
# We set the default value _after_ adding the column so we don't end up
# updating any existing data with the default value. This isn't
# necessary since we copy over old values further down.
change_column_default
(
table
,
new
,
old_col
.
default
)
unless
old_col
.
default
.
nil?
create_column_from
(
table
,
old
,
new
,
type:
type
)
install_rename_triggers
(
table
,
old
,
new
)
update_column_in_batches
(
table
,
new
,
Arel
::
Table
.
new
(
table
)[
old
])
change_column_null
(
table
,
new
,
false
)
unless
old_col
.
null
copy_indexes
(
table
,
old
,
new
)
copy_foreign_keys
(
table
,
old
,
new
)
end
# Reverses operations performed by rename_column_concurrently.
#
# This method takes care of removing previously installed triggers as well
# as removing the new column.
#
# table - The name of the database table.
# old - The name of the old column.
# new - The name of the new column.
def
undo_rename_column_concurrently
(
table
,
old
,
new
)
trigger_name
=
rename_trigger_name
(
table
,
old
,
new
)
...
...
@@ -557,6 +547,18 @@ module Gitlab
remove_column
(
table
,
old
)
end
# Reverses the operations performed by cleanup_concurrent_column_rename.
#
# This method adds back the old_column removed
# by cleanup_concurrent_column_rename.
# It also adds back the (old_column > new_column) trigger that is removed
# by cleanup_concurrent_column_rename.
#
# table - The name of the database table containing the column.
# old - The old column name.
# new - The new column name.
# type - The type of the old column. If no type is given the new column's
# type is used.
def
undo_cleanup_concurrent_column_rename
(
table
,
old
,
new
,
type:
nil
)
if
transaction_open?
raise
'undo_cleanup_concurrent_column_rename can not be run inside a transaction'
...
...
@@ -564,26 +566,9 @@ module Gitlab
check_trigger_permissions!
(
table
)
new_column
=
column_for
(
table
,
new
)
add_column
(
table
,
old
,
type
||
new_column
.
type
,
limit:
new_column
.
limit
,
precision:
new_column
.
precision
,
scale:
new_column
.
scale
)
# We set the default value _after_ adding the column so we don't end up
# updating any existing data with the default value. This isn't
# necessary since we copy over old values further down.
change_column_default
(
table
,
old
,
new_column
.
default
)
unless
new_column
.
default
.
nil?
create_column_from
(
table
,
new
,
old
,
type:
type
)
install_rename_triggers
(
table
,
old
,
new
)
update_column_in_batches
(
table
,
old
,
Arel
::
Table
.
new
(
table
)[
new
])
change_column_null
(
table
,
old
,
false
)
unless
new_column
.
null
copy_indexes
(
table
,
new
,
old
)
copy_foreign_keys
(
table
,
new
,
old
)
end
# Changes the column type of a table using a background migration.
...
...
@@ -1076,6 +1061,28 @@ into similar problems in the future (e.g. when new tables are created).
private
def
create_column_from
(
table
,
old
,
new
,
type:
nil
)
old_col
=
column_for
(
table
,
old
)
new_type
=
type
||
old_col
.
type
add_column
(
table
,
new
,
new_type
,
limit:
old_col
.
limit
,
precision:
old_col
.
precision
,
scale:
old_col
.
scale
)
# We set the default value _after_ adding the column so we don't end up
# updating any existing data with the default value. This isn't
# necessary since we copy over old values further down.
change_column_default
(
table
,
new
,
old_col
.
default
)
unless
old_col
.
default
.
nil?
update_column_in_batches
(
table
,
new
,
Arel
::
Table
.
new
(
table
)[
old
])
change_column_null
(
table
,
new
,
false
)
unless
old_col
.
null
copy_indexes
(
table
,
old
,
new
)
copy_foreign_keys
(
table
,
old
,
new
)
end
def
validate_timestamp_column_name!
(
column_name
)
return
if
PERMITTED_TIMESTAMP_COLUMNS
.
member?
(
column_name
)
...
...
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