@@ -739,6 +739,40 @@ def update_table_definition(table_name, base) #:nodoc:
739
739
Table . new ( table_name , base )
740
740
end
741
741
742
+ def add_index_options ( table_name , column_name , options = { } ) #:nodoc:
743
+ column_names = Array ( column_name )
744
+ index_name = index_name ( table_name , column : column_names )
745
+
746
+ options . assert_valid_keys ( :unique , :order , :name , :where , :length , :internal , :using , :algorithm , :type )
747
+
748
+ index_type = options [ :unique ] ? "UNIQUE" : ""
749
+ index_type = options [ :type ] . to_s if options . key? ( :type )
750
+ index_name = options [ :name ] . to_s if options . key? ( :name )
751
+ max_index_length = options . fetch ( :internal , false ) ? index_name_length : allowed_index_name_length
752
+
753
+ if options . key? ( :algorithm )
754
+ algorithm = index_algorithms . fetch ( options [ :algorithm ] ) {
755
+ raise ArgumentError . new ( "Algorithm must be one of the following: #{ index_algorithms . keys . map ( &:inspect ) . join ( ', ' ) } " )
756
+ }
757
+ end
758
+
759
+ using = "USING #{ options [ :using ] } " if options [ :using ] . present?
760
+
761
+ if supports_partial_index?
762
+ index_options = options [ :where ] ? " WHERE #{ options [ :where ] } " : ""
763
+ end
764
+
765
+ if index_name . length > max_index_length
766
+ raise ArgumentError , "Index name '#{ index_name } ' on table '#{ table_name } ' is too long; the limit is #{ max_index_length } characters"
767
+ end
768
+ if table_exists? ( table_name ) && index_name_exists? ( table_name , index_name , false )
769
+ raise ArgumentError , "Index name '#{ index_name } ' on table '#{ table_name } ' already exists"
770
+ end
771
+ index_columns = quoted_columns_for_index ( column_names , options ) . join ( ", " )
772
+
773
+ [ index_name , index_type , index_columns , index_options , algorithm , using ]
774
+ end
775
+
742
776
protected
743
777
def add_index_sort_order ( option_strings , column_names , options = { } )
744
778
if options . is_a? ( Hash ) && order = options [ :order ]
@@ -769,40 +803,6 @@ def options_include_default?(options)
769
803
options . include? ( :default ) && !( options [ :null ] == false && options [ :default ] . nil? )
770
804
end
771
805
772
- def add_index_options ( table_name , column_name , options = { } )
773
- column_names = Array ( column_name )
774
- index_name = index_name ( table_name , column : column_names )
775
-
776
- options . assert_valid_keys ( :unique , :order , :name , :where , :length , :internal , :using , :algorithm , :type )
777
-
778
- index_type = options [ :unique ] ? "UNIQUE" : ""
779
- index_type = options [ :type ] . to_s if options . key? ( :type )
780
- index_name = options [ :name ] . to_s if options . key? ( :name )
781
- max_index_length = options . fetch ( :internal , false ) ? index_name_length : allowed_index_name_length
782
-
783
- if options . key? ( :algorithm )
784
- algorithm = index_algorithms . fetch ( options [ :algorithm ] ) {
785
- raise ArgumentError . new ( "Algorithm must be one of the following: #{ index_algorithms . keys . map ( &:inspect ) . join ( ', ' ) } " )
786
- }
787
- end
788
-
789
- using = "USING #{ options [ :using ] } " if options [ :using ] . present?
790
-
791
- if supports_partial_index?
792
- index_options = options [ :where ] ? " WHERE #{ options [ :where ] } " : ""
793
- end
794
-
795
- if index_name . length > max_index_length
796
- raise ArgumentError , "Index name '#{ index_name } ' on table '#{ table_name } ' is too long; the limit is #{ max_index_length } characters"
797
- end
798
- if table_exists? ( table_name ) && index_name_exists? ( table_name , index_name , false )
799
- raise ArgumentError , "Index name '#{ index_name } ' on table '#{ table_name } ' already exists"
800
- end
801
- index_columns = quoted_columns_for_index ( column_names , options ) . join ( ", " )
802
-
803
- [ index_name , index_type , index_columns , index_options , algorithm , using ]
804
- end
805
-
806
806
def index_name_for_remove ( table_name , options = { } )
807
807
index_name = index_name ( table_name , options )
808
808
0 commit comments