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
b831914a
Commit
b831914a
authored
Jun 28, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
7abaee36
ae68c7ea
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
1 deletion
+25
-1
changelogs/unreleased/support-jsonb-default-value.yml
changelogs/unreleased/support-jsonb-default-value.yml
+5
-0
lib/gitlab/database/migration_helpers.rb
lib/gitlab/database/migration_helpers.rb
+2
-1
spec/lib/gitlab/database/migration_helpers_spec.rb
spec/lib/gitlab/database/migration_helpers_spec.rb
+18
-0
No files found.
changelogs/unreleased/support-jsonb-default-value.yml
0 → 100644
View file @
b831914a
---
title
:
Support jsonb default in add_column_with_default migration helper
merge_request
:
29871
author
:
type
:
other
lib/gitlab/database/migration_helpers.rb
View file @
b831914a
...
@@ -434,7 +434,8 @@ module Gitlab
...
@@ -434,7 +434,8 @@ module Gitlab
end
end
begin
begin
update_column_in_batches
(
table
,
column
,
default
,
&
block
)
default_after_type_cast
=
connection
.
type_cast
(
default
,
column_for
(
table
,
column
))
update_column_in_batches
(
table
,
column
,
default_after_type_cast
,
&
block
)
change_column_null
(
table
,
column
,
false
)
unless
allow_null
change_column_null
(
table
,
column
,
false
)
unless
allow_null
# We want to rescue _all_ exceptions here, even those that don't inherit
# We want to rescue _all_ exceptions here, even those that don't inherit
...
...
spec/lib/gitlab/database/migration_helpers_spec.rb
View file @
b831914a
...
@@ -583,6 +583,24 @@ describe Gitlab::Database::MigrationHelpers do
...
@@ -583,6 +583,24 @@ describe Gitlab::Database::MigrationHelpers do
model
.
add_column_with_default
(
:projects
,
:foo
,
:integer
,
default:
10
,
limit:
8
)
model
.
add_column_with_default
(
:projects
,
:foo
,
:integer
,
default:
10
,
limit:
8
)
end
end
end
end
it
'adds a column with an array default value for a jsonb type'
do
create
(
:project
)
allow
(
model
).
to
receive
(
:transaction_open?
).
and_return
(
false
)
allow
(
model
).
to
receive
(
:transaction
).
and_yield
expect
(
model
).
to
receive
(
:update_column_in_batches
).
with
(
:projects
,
:foo
,
'[{"foo":"json"}]'
).
and_call_original
model
.
add_column_with_default
(
:projects
,
:foo
,
:jsonb
,
default:
[{
foo:
"json"
}])
end
it
'adds a column with an object default value for a jsonb type'
do
create
(
:project
)
allow
(
model
).
to
receive
(
:transaction_open?
).
and_return
(
false
)
allow
(
model
).
to
receive
(
:transaction
).
and_yield
expect
(
model
).
to
receive
(
:update_column_in_batches
).
with
(
:projects
,
:foo
,
'{"foo":"json"}'
).
and_call_original
model
.
add_column_with_default
(
:projects
,
:foo
,
:jsonb
,
default:
{
foo:
"json"
})
end
end
end
context
'inside a transaction'
do
context
'inside a transaction'
do
...
...
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