@@ -33,7 +33,36 @@ def self.find(version)
33
33
V7_1 = Current
34
34
35
35
class V7_0 < V7_1
36
+ module LegacyIndexName
37
+ private
38
+ def legacy_index_name ( table_name , options )
39
+ if Hash === options
40
+ if options [ :column ]
41
+ "index_#{ table_name } _on_#{ Array ( options [ :column ] ) * '_and_' } "
42
+ elsif options [ :name ]
43
+ options [ :name ]
44
+ else
45
+ raise ArgumentError , "You must specify the index name"
46
+ end
47
+ else
48
+ legacy_index_name ( table_name , index_name_options ( options ) )
49
+ end
50
+ end
51
+
52
+ def index_name_options ( column_names )
53
+ if expression_column_name? ( column_names )
54
+ column_names = column_names . scan ( /\w +/ ) . join ( "_" )
55
+ end
56
+
57
+ { column : column_names }
58
+ end
59
+
60
+ def expression_column_name? ( column_name )
61
+ column_name . is_a? ( String ) && /\W / . match? ( column_name )
62
+ end
63
+ end
36
64
module TableDefinition
65
+ include LegacyIndexName
37
66
def column ( name , type , **options )
38
67
options [ :_skip_validate_options ] = true
39
68
super
@@ -44,11 +73,18 @@ def change(name, type, **options)
44
73
super
45
74
end
46
75
76
+ def index ( column_name , **options )
77
+ options [ :name ] = legacy_index_name ( name , column_name ) if options [ :name ] . nil?
78
+ super
79
+ end
80
+
47
81
private
48
82
def raise_on_if_exist_options ( options )
49
83
end
50
84
end
51
85
86
+ include LegacyIndexName
87
+
52
88
def add_column ( table_name , column_name , type , **options )
53
89
options [ :_skip_validate_options ] = true
54
90
super
@@ -109,32 +145,6 @@ class << t
109
145
end
110
146
super
111
147
end
112
-
113
- def legacy_index_name ( table_name , options )
114
- if Hash === options
115
- if options [ :column ]
116
- "index_#{ table_name } _on_#{ Array ( options [ :column ] ) * '_and_' } "
117
- elsif options [ :name ]
118
- options [ :name ]
119
- else
120
- raise ArgumentError , "You must specify the index name"
121
- end
122
- else
123
- legacy_index_name ( table_name , index_name_options ( options ) )
124
- end
125
- end
126
-
127
- def index_name_options ( column_names )
128
- if expression_column_name? ( column_names )
129
- column_names = column_names . scan ( /\w +/ ) . join ( "_" )
130
- end
131
-
132
- { column : column_names }
133
- end
134
-
135
- def expression_column_name? ( column_name )
136
- column_name . is_a? ( String ) && /\W / . match? ( column_name )
137
- end
138
148
end
139
149
140
150
class V6_1 < V7_0
0 commit comments