Commit 343e42b6 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Improve migrations readability

parent 574b9c67
...@@ -10,14 +10,16 @@ class ConvertApplicationSettingsRepositorySizeLimitToBytes < ActiveRecord::Migra ...@@ -10,14 +10,16 @@ class ConvertApplicationSettingsRepositorySizeLimitToBytes < ActiveRecord::Migra
add_column :application_settings, :repository_size_limit, :integer, default: 0, limit: 8 add_column :application_settings, :repository_size_limit, :integer, default: 0, limit: 8
end end
bigint_expression = if Gitlab::Database.postgresql? bigint_string = if Gitlab::Database.postgresql?
'repository_size_limit_mb::bigint * 1024 * 1024' 'repository_size_limit_mb::bigint * 1024 * 1024'
else else
'repository_size_limit_mb * 1024 * 1024' 'repository_size_limit_mb * 1024 * 1024'
end end
sql_expression = Arel::Nodes::SqlLiteral.new(bigint_string)
connection.transaction do connection.transaction do
update_column_in_batches(:application_settings, :repository_size_limit, Arel::Nodes::SqlLiteral.new(bigint_expression)) do |t, query| update_column_in_batches(:application_settings, :repository_size_limit, sql_expression) do |t, query|
query.where(t[:repository_size_limit_mb].not_eq(nil)) query.where(t[:repository_size_limit_mb].not_eq(nil))
end end
...@@ -31,8 +33,10 @@ class ConvertApplicationSettingsRepositorySizeLimitToBytes < ActiveRecord::Migra ...@@ -31,8 +33,10 @@ class ConvertApplicationSettingsRepositorySizeLimitToBytes < ActiveRecord::Migra
add_column :application_settings, :repository_size_limit, :integer, default: 0, limit: nil add_column :application_settings, :repository_size_limit, :integer, default: 0, limit: nil
end end
sql_expression = Arel::Nodes::SqlLiteral.new('repository_size_limit_bytes / 1024 / 1024')
connection.transaction do connection.transaction do
update_column_in_batches(:application_settings, :repository_size_limit, Arel::Nodes::SqlLiteral.new('repository_size_limit_bytes / 1024 / 1024')) do |t, query| update_column_in_batches(:application_settings, :repository_size_limit, sql_expression) do |t, query|
query.where(t[:repository_size_limit_bytes].not_eq(nil)) query.where(t[:repository_size_limit_bytes].not_eq(nil))
end end
......
...@@ -13,14 +13,16 @@ class ConvertProjectsRepositorySizeLimitToBytes < ActiveRecord::Migration ...@@ -13,14 +13,16 @@ class ConvertProjectsRepositorySizeLimitToBytes < ActiveRecord::Migration
add_column :projects, :repository_size_limit, :integer, limit: 8 add_column :projects, :repository_size_limit, :integer, limit: 8
end end
bigint_expression = if Gitlab::Database.postgresql? bigint_string = if Gitlab::Database.postgresql?
'repository_size_limit_mb::bigint * 1024 * 1024' 'repository_size_limit_mb::bigint * 1024 * 1024'
else else
'repository_size_limit_mb * 1024 * 1024' 'repository_size_limit_mb * 1024 * 1024'
end end
sql_expression = Arel::Nodes::SqlLiteral.new(bigint_string)
connection.transaction do connection.transaction do
update_column_in_batches(:projects, :repository_size_limit, Arel::Nodes::SqlLiteral.new(bigint_expression)) do |t, query| update_column_in_batches(:projects, :repository_size_limit, sql_expression) do |t, query|
query.where(t[:repository_size_limit_mb].not_eq(nil)) query.where(t[:repository_size_limit_mb].not_eq(nil))
end end
...@@ -34,8 +36,10 @@ class ConvertProjectsRepositorySizeLimitToBytes < ActiveRecord::Migration ...@@ -34,8 +36,10 @@ class ConvertProjectsRepositorySizeLimitToBytes < ActiveRecord::Migration
add_column :projects, :repository_size_limit, :integer, limit: nil add_column :projects, :repository_size_limit, :integer, limit: nil
end end
sql_expression = Arel::Nodes::SqlLiteral.new('repository_size_limit_bytes / 1024 / 1024')
connection.transaction do connection.transaction do
update_column_in_batches(:projects, :repository_size_limit, Arel::Nodes::SqlLiteral.new('repository_size_limit_bytes / 1024 / 1024')) do |t, query| update_column_in_batches(:projects, :repository_size_limit, sql_expression) do |t, query|
query.where(t[:repository_size_limit_bytes].not_eq(nil)) query.where(t[:repository_size_limit_bytes].not_eq(nil))
end end
......
...@@ -13,14 +13,16 @@ class ConvertNamespacesRepositorySizeLimitToBytes < ActiveRecord::Migration ...@@ -13,14 +13,16 @@ class ConvertNamespacesRepositorySizeLimitToBytes < ActiveRecord::Migration
add_column :namespaces, :repository_size_limit, :integer, limit: 8 add_column :namespaces, :repository_size_limit, :integer, limit: 8
end end
bigint_expression = if Gitlab::Database.postgresql? bigint_string = if Gitlab::Database.postgresql?
'repository_size_limit_mb::bigint * 1024 * 1024' 'repository_size_limit_mb::bigint * 1024 * 1024'
else else
'repository_size_limit_mb * 1024 * 1024' 'repository_size_limit_mb * 1024 * 1024'
end end
sql_expression = Arel::Nodes::SqlLiteral.new(bigint_string)
connection.transaction do connection.transaction do
update_column_in_batches(:namespaces, :repository_size_limit, Arel::Nodes::SqlLiteral.new(bigint_expression)) do |t, query| update_column_in_batches(:namespaces, :repository_size_limit, sql_expression) do |t, query|
query.where(t[:repository_size_limit_mb].not_eq(nil)) query.where(t[:repository_size_limit_mb].not_eq(nil))
end end
...@@ -34,8 +36,10 @@ class ConvertNamespacesRepositorySizeLimitToBytes < ActiveRecord::Migration ...@@ -34,8 +36,10 @@ class ConvertNamespacesRepositorySizeLimitToBytes < ActiveRecord::Migration
add_column :namespaces, :repository_size_limit, :integer, limit: nil add_column :namespaces, :repository_size_limit, :integer, limit: nil
end end
sql_expression = Arel::Nodes::SqlLiteral.new('repository_size_limit_bytes / 1024 / 1024')
connection.transaction do connection.transaction do
update_column_in_batches(:namespaces, :repository_size_limit, Arel::Nodes::SqlLiteral.new('repository_size_limit_bytes / 1024 / 1024')) do |t, query| update_column_in_batches(:namespaces, :repository_size_limit, sql_expression) do |t, query|
query.where(t[:repository_size_limit_bytes].not_eq(nil)) query.where(t[:repository_size_limit_bytes].not_eq(nil))
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment