|
| 1 | +class SplitSmartHttp < ActiveRecord::Migration |
| 2 | + |
| 3 | + def self.up |
| 4 | + add_column :repository_git_extras, :git_https, :boolean, default: false, after: :git_http |
| 5 | + add_column :repository_git_extras, :git_ssh, :boolean, default: true, after: :git_https |
| 6 | + add_column :repository_git_extras, :git_go, :boolean, default: false, after: :git_https |
| 7 | + |
| 8 | + add_column :repository_git_extras, :git_http_temp, :boolean, default: false, after: :git_http |
| 9 | + |
| 10 | + RepositoryGitExtra.reset_column_information |
| 11 | + |
| 12 | + RepositoryGitExtra.all.each do |git_extra| |
| 13 | + case git_extra[:git_http] |
| 14 | + when 1 # HTTPS only |
| 15 | + git_extra.update_column(:git_https, true) |
| 16 | + when 2 # HTTPS and HTTP |
| 17 | + git_extra.update_column(:git_https, true) |
| 18 | + git_extra.update_column(:git_http_temp, true) |
| 19 | + when # HTTP only |
| 20 | + git_extra.update_column(:git_http_temp, true) |
| 21 | + end |
| 22 | + end |
| 23 | + |
| 24 | + remove_column :repository_git_extras, :git_http |
| 25 | + rename_column :repository_git_extras, :git_http_temp, :git_http |
| 26 | + end |
| 27 | + |
| 28 | + def self.down |
| 29 | + add_column :repository_git_extras, :git_http_temp, :integer, after: :git_http |
| 30 | + |
| 31 | + RepositoryGitExtra.reset_column_information |
| 32 | + |
| 33 | + RepositoryGitExtra.all.each do |git_extra| |
| 34 | + if git_extra[:git_https] && git_extra[:git_http] |
| 35 | + git_extra.update_column(:git_http_temp, 2) |
| 36 | + elsif git_extra[:git_https] |
| 37 | + git_extra.update_column(:git_http_temp, 1) |
| 38 | + elsif git_extra[:git_http] |
| 39 | + git_extra.update_column(:git_http_temp, 3) |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + remove_column :repository_git_extras, :git_https |
| 44 | + remove_column :repository_git_extras, :git_ssh |
| 45 | + remove_column :repository_git_extras, :git_go |
| 46 | + |
| 47 | + remove_column :repository_git_extras, :git_http |
| 48 | + rename_column :repository_git_extras, :git_http_temp, :git_http |
| 49 | + end |
| 50 | + |
| 51 | +end |
0 commit comments