1
1
class UpdateMultiRepoPerProject < ActiveRecord ::Migration
2
2
def self . up
3
- begin
3
+ if ! columns ( "repository_mirrors" ) . index { | x | x . name == "repository_id" }
4
4
add_column :repository_mirrors , :repository_id , :integer
5
5
begin
6
6
say "Detaching repository mirrors from projects; attaching them to repositories..."
@@ -9,16 +9,16 @@ def self.up
9
9
mirror . save!
10
10
end
11
11
say "Success. Changed #{ RepositoryMirror . all . count } records."
12
- remove_column :repository_mirrors , :project_id rescue nil
13
12
rescue => e
14
13
say "Failed to attach repository mirrors to repositories."
15
14
say "Error: #{ e . message } "
16
- remove_column :repository_mirrors , :repository_id rescue nil
17
15
end
18
- rescue
16
+ if columns ( "repository_mirrors" ) . index { |x | x . name =="project_id" }
17
+ remove_column :repository_mirrors , :project_id
18
+ end
19
19
end
20
20
21
- begin
21
+ if ! columns ( "repository_post_receive_urls" ) . index { | x | x . name == "repository_id" }
22
22
add_column :repository_post_receive_urls , :repository_id , :integer
23
23
begin
24
24
say "Detaching repository post-receive-urls from projects; attaching them to repositories..."
@@ -27,20 +27,19 @@ def self.up
27
27
prurl . save!
28
28
end
29
29
say "Success. Changed #{ RepositoryPostReceiveUrl . all . count } records."
30
- remove_column :repository_post_receive_urls , :project_id rescue nil
31
30
rescue => e
32
31
say "Failed to attach repositories post-receive-urls to repositories."
33
32
say "Error: #{ e . message } "
34
- remove_column :repository_post_receive_urls , :repository_id rescue nil
35
33
end
36
- rescue
34
+ if columns ( "repository_post_receive_urls" ) . index { |x | x . name =="project_id" }
35
+ remove_column :repository_post_receive_urls , :project_id
36
+ end
37
37
end
38
38
39
39
add_index :projects , [ :identifier ]
40
- begin
40
+ if columns ( "repositories" ) . index { | x | x . name == "identifier" }
41
41
add_index :repositories , [ :identifier ]
42
42
add_index :repositories , [ :identifier , :project_id ]
43
- rescue
44
43
end
45
44
rename_column :git_caches , :proj_identifier , :repo_identifier
46
45
@@ -51,7 +50,7 @@ def self.up
51
50
h [ x ] +=1 unless x . blank?
52
51
h
53
52
end . values . max ) || 0 ) > 1
54
- # Oops -- have duplication. Force to false.
53
+ # Oops -- have duplication. Force to false.
55
54
valuehash [ 'gitRepositoryIdentUnique' ] = "false"
56
55
else
57
56
# If no duplication -- set to true only if it doesn't already exist
@@ -68,7 +67,7 @@ def self.up
68
67
end
69
68
70
69
def self . down
71
- begin
70
+ if ! columns ( "repository_mirrors" ) . index { | x | x . name == "project_id" }
72
71
add_column :repository_mirrors , :project_id , :integer
73
72
begin
74
73
say "Detaching repository mirrors from repositories; re-attaching them to projects..."
@@ -77,16 +76,16 @@ def self.down
77
76
mirror . save!
78
77
end
79
78
say "Success. Changed #{ RepositoryMirror . all . count } records."
80
- remove_column :repository_mirrors , :repository_id rescue nil
81
- rescue => e
79
+ rescue => e
82
80
say "Failed to re-attach repository mirrors to projects."
83
81
say "Error: #{ e . message } "
84
- remove_column :repository_mirrors , :project_id rescue nil
85
82
end
86
- rescue
83
+ if columns ( "repository_mirrors" ) . index { |x | x . name =="repository_id" }
84
+ remove_column :repository_mirrors , :repository_id
85
+ end
87
86
end
88
87
89
- begin
88
+ if ! columns ( "repository_post_receive_urls" ) . index { | x | x . name == "project_id" }
90
89
add_column :repository_post_receive_urls , :project_id , :integer
91
90
begin
92
91
say "Detaching repository post-receive-urls from repositories; re-attaching them to projects..."
@@ -95,20 +94,19 @@ def self.down
95
94
prurl . save!
96
95
end
97
96
say "Success. Changed #{ RepositoryPostReceiveUrl . all . count } records."
98
- remove_column :repository_post_receive_urls , :repository_id rescue nil
99
97
rescue => e
100
98
say "Failed to re-attach repository post-receive urls to projects."
101
99
say "Error: #{ e . message } "
102
- remove_column :repository_post_receive_urls , :project_id rescue nil
103
100
end
104
- rescue
101
+ if columns ( "repository_post_receive_urls" ) . index { |x | x . name =="repository_id" }
102
+ remove_column :repository_post_receive_urls , :repository_id
103
+ end
105
104
end
106
105
107
106
remove_index :projects , [ :identifier ]
108
- begin
107
+ if columns ( "repositories" ) . index { | x | x . name == "identifier" }
109
108
remove_index :repositories , [ :identifier ]
110
109
remove_index :repositories , [ :identifier , :project_id ]
111
- rescue
112
110
end
113
111
rename_column :git_caches , :repo_identifier , :proj_identifier
114
112
0 commit comments