@@ -11,6 +11,7 @@ module PostgreSQL
1111
1212 require 'arjdbc/postgresql/column'
1313 require 'arjdbc/postgresql/explain_support'
14+ require 'arjdbc/postgresql/schema_creation' # AR 4.x
1415
1516 # @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_connection_class
1617 def self . jdbc_connection_class
@@ -250,13 +251,6 @@ def migration_keys
250251 super + [ :array ]
251252 end if AR4_COMPAT
252253
253- if ActiveRecord ::VERSION ::MAJOR > 3
254-
255- require 'arjdbc/postgresql/schema_creation'
256- def schema_creation ; SchemaCreation . new ( self ) ; end
257-
258- end
259-
260254 # Enable standard-conforming strings if available.
261255 def set_standard_conforming_strings
262256 self . standard_conforming_strings = ( true )
@@ -975,7 +969,7 @@ def add_column(table_name, column_name, type, options = {})
975969
976970 change_column_default ( table_name , column_name , default ) if options_include_default? ( options )
977971 change_column_null ( table_name , column_name , false , default ) if notnull
978- end
972+ end if ActiveRecord :: VERSION :: MAJOR < 4
979973
980974 # Changes the column of a table.
981975 def change_column ( table_name , column_name , type , options = { } )
@@ -1004,24 +998,24 @@ def change_column(table_name, column_name, type, options = {})
1004998
1005999 change_column_default ( table_name , column_name , options [ :default ] ) if options_include_default? ( options )
10061000 change_column_null ( table_name , column_name , options [ :null ] , options [ :default ] ) if options . key? ( :null )
1007- end
1001+ end # unless const_defined? :SchemaCreation
10081002
10091003 # Changes the default value of a table column.
10101004 def change_column_default ( table_name , column_name , default )
10111005 execute "ALTER TABLE #{ quote_table_name ( table_name ) } ALTER COLUMN #{ quote_column_name ( column_name ) } SET DEFAULT #{ quote ( default ) } "
1012- end
1006+ end # unless const_defined? :SchemaCreation
10131007
10141008 def change_column_null ( table_name , column_name , null , default = nil )
10151009 unless null || default . nil?
10161010 execute ( "UPDATE #{ quote_table_name ( table_name ) } SET #{ quote_column_name ( column_name ) } =#{ quote ( default ) } WHERE #{ quote_column_name ( column_name ) } IS NULL" )
10171011 end
10181012 execute ( "ALTER TABLE #{ quote_table_name ( table_name ) } ALTER #{ quote_column_name ( column_name ) } #{ null ? 'DROP' : 'SET' } NOT NULL" )
1019- end
1013+ end # unless const_defined? :SchemaCreation
10201014
10211015 def rename_column ( table_name , column_name , new_column_name )
10221016 execute "ALTER TABLE #{ quote_table_name ( table_name ) } RENAME COLUMN #{ quote_column_name ( column_name ) } TO #{ quote_column_name ( new_column_name ) } "
10231017 rename_column_indexes ( table_name , column_name , new_column_name ) if respond_to? ( :rename_column_indexes ) # AR-4.0 SchemaStatements
1024- end
1018+ end # unless const_defined? :SchemaCreation
10251019
10261020 def add_index ( table_name , column_name , options = { } )
10271021 index_name , index_type , index_columns , index_options , index_algorithm , index_using = add_index_options ( table_name , column_name , options )
0 commit comments