Открыть боковую панель
nt_test111
nt_project_u8hcxr42ygkw
Коммиты
96b116d0
Коммит
96b116d0
создал
Июн 28, 2019
по автору
Jason Goodman
Зафиксировано автором
Thong Kuah
Июн 28, 2019
Просмотр файлов
Support jsonb Default Value in add_column_with_default Migration Helper
владелец
732ee606
Изменения
3
Скрыть пробелы
Построчно
Рядом
changelogs/unreleased/support-jsonb-default-value.yml
0 → 100644
Просмотр файла @
96b116d0
---
title
:
Support jsonb default in add_column_with_default migration helper
merge_request
:
29871
author
:
type
:
other
lib/gitlab/database/migration_helpers.rb
Просмотр файла @
96b116d0
...
...
@@ -434,7 +434,8 @@ def add_column_with_default(table, column, type, default:, limit: nil, allow_nul
end
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
# We want to rescue _all_ exceptions here, even those that don't inherit
...
...
spec/lib/gitlab/database/migration_helpers_spec.rb
Просмотр файла @
96b116d0
...
...
@@ -583,6 +583,24 @@
model
.
add_column_with_default
(
:projects
,
:foo
,
:integer
,
default:
10
,
limit:
8
)
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
context
'inside a transaction'
do
...
...
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать