Commit 3c25eb26 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Migrate repository size limits from MB to Bytes

parent 930b098c
class ConvertApplicationSettingsRepositorySizeLimitToBytes < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
connection.transaction do
rename_column :application_settings, :repository_size_limit, :repository_size_limit_mb
add_column :application_settings, :repository_size_limit, :integer, default: 0, limit: 8
end
bigint_expression = if Gitlab::Database.postgresql?
'repository_size_limit_mb::bigint * 1024 * 1024'
else
'repository_size_limit_mb * 1024 * 1024'
end
connection.transaction do
update_column_in_batches(:application_settings, :repository_size_limit, Arel::Nodes::SqlLiteral.new(bigint_expression)) do |t, query|
query.where(t[:repository_size_limit_mb].not_eq(nil))
end
remove_column :application_settings, :repository_size_limit_mb
end
end
def down
connection.transaction do
rename_column :application_settings, :repository_size_limit, :repository_size_limit_bytes
add_column :application_settings, :repository_size_limit, :integer, default: 0, limit: nil
end
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|
query.where(t[:repository_size_limit_bytes].not_eq(nil))
end
remove_column :application_settings, :repository_size_limit_bytes
end
end
end
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class ConvertProjectsRepositorySizeLimitToBytes < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
connection.transaction do
rename_column :projects, :repository_size_limit, :repository_size_limit_mb
add_column :projects, :repository_size_limit, :integer, limit: 8
end
bigint_expression = if Gitlab::Database.postgresql?
'repository_size_limit_mb::bigint * 1024 * 1024'
else
'repository_size_limit_mb * 1024 * 1024'
end
connection.transaction do
update_column_in_batches(:projects, :repository_size_limit, Arel::Nodes::SqlLiteral.new(bigint_expression)) do |t, query|
query.where(t[:repository_size_limit_mb].not_eq(nil))
end
remove_column :projects, :repository_size_limit_mb
end
end
def down
connection.transaction do
rename_column :projects, :repository_size_limit, :repository_size_limit_bytes
add_column :projects, :repository_size_limit, :integer, limit: nil
end
connection.transaction do
update_column_in_batches(:projects, :repository_size_limit, Arel::Nodes::SqlLiteral.new('repository_size_limit_bytes / 1024 / 1024')) do |t, query|
query.where(t[:repository_size_limit_bytes].not_eq(nil))
end
remove_column :projects, :repository_size_limit_bytes
end
end
end
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class ConvertNamespacesRepositorySizeLimitToBytes < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
connection.transaction do
rename_column :namespaces, :repository_size_limit, :repository_size_limit_mb
add_column :namespaces, :repository_size_limit, :integer, limit: 8
end
bigint_expression = if Gitlab::Database.postgresql?
'repository_size_limit_mb::bigint * 1024 * 1024'
else
'repository_size_limit_mb * 1024 * 1024'
end
connection.transaction do
update_column_in_batches(:namespaces, :repository_size_limit, Arel::Nodes::SqlLiteral.new(bigint_expression)) do |t, query|
query.where(t[:repository_size_limit_mb].not_eq(nil))
end
remove_column :namespaces, :repository_size_limit_mb
end
end
def down
connection.transaction do
rename_column :namespaces, :repository_size_limit, :repository_size_limit_bytes
add_column :namespaces, :repository_size_limit, :integer, limit: nil
end
connection.transaction do
update_column_in_batches(:namespaces, :repository_size_limit, Arel::Nodes::SqlLiteral.new('repository_size_limit_bytes / 1024 / 1024')) do |t, query|
query.where(t[:repository_size_limit_bytes].not_eq(nil))
end
remove_column :namespaces, :repository_size_limit_bytes
end
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170106172237) do
ActiveRecord::Schema.define(version: 20170118200412) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -102,7 +102,6 @@ ActiveRecord::Schema.define(version: 20170106172237) do
t.boolean "usage_ping_enabled", default: true, null: false
t.boolean "koding_enabled"
t.string "koding_url"
t.integer "repository_size_limit", default: 0
t.text "sign_in_text_html"
t.text "help_page_text_html"
t.text "shared_runners_text_html"
......@@ -119,6 +118,7 @@ ActiveRecord::Schema.define(version: 20170106172237) do
t.string "plantuml_url"
t.boolean "plantuml_enabled"
t.integer "shared_runners_minutes", default: 0, null: false
t.integer "repository_size_limit", limit: 8, default: 0
end
create_table "approvals", force: :cascade do |t|
......@@ -853,10 +853,10 @@ ActiveRecord::Schema.define(version: 20170106172237) do
t.datetime "ldap_sync_last_sync_at"
t.datetime "deleted_at"
t.boolean "lfs_enabled"
t.integer "repository_size_limit"
t.text "description_html"
t.integer "parent_id"
t.integer "shared_runners_minutes_limit"
t.integer "repository_size_limit", limit: 8
end
add_index "namespaces", ["created_at"], name: "index_namespaces_on_created_at", using: :btree
......@@ -1105,8 +1105,8 @@ ActiveRecord::Schema.define(version: 20170106172237) do
t.boolean "repository_read_only"
t.boolean "lfs_enabled"
t.text "description_html"
t.integer "repository_size_limit"
t.boolean "only_allow_merge_if_all_discussions_are_resolved"
t.integer "repository_size_limit", limit: 8
end
add_index "projects", ["ci_id"], name: "index_projects_on_ci_id", using: :btree
......
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