Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #4721: db2_migrations.diff

File db2_migrations.diff, 3.4 kB (added by contact@maik-schmidt.de, 2 years ago)

ActiveRecord DB2 database adapter: Migrations support

  • test/migration_test.rb

    old new  
    113113      Person.connection.drop_table :testings rescue nil 
    114114    end 
    115115   
    116     # SQL Server and Sybase will not allow you to add a NOT NULL column 
     116    # SQL Server, Sybase, and DB2 will not allow you to add a NOT NULL column 
    117117    # to a table without specifying a default value, so the 
    118118    # following test must be skipped   
    119     unless current_adapter?(:SQLServerAdapter) || current_adapter?(:SybaseAdapter) 
     119    unless current_adapter?(:SQLServerAdapter) || current_adapter?(:SybaseAdapter) || current_adapter?(:DB2Adapter) 
    120120      def test_add_column_not_null_without_default 
    121121        Person.connection.create_table :testings do |t| 
    122122          t.column :foo, :string 
  • lib/active_record/connection_adapters/db2_adapter.rb

    old new  
    4242          super(connection, logger) 
    4343          @connection_options = connection_options 
    4444          if schema = @connection_options[:schema] 
    45             with_statement do |stmt| 
    46               stmt.exec_direct("SET SCHEMA=#{schema}") 
    47             end 
     45            execute "SET SCHEMA=#{schema}" 
    4846          end 
     47          db_version = select_value('select versionnumber from sysibm.sysversions') 
     48          @db2_major_version = db_version.to_s[0].chr.to_i 
    4949        end 
    5050         
    5151        def select_all(sql, name = nil) 
     
    179179          '0' 
    180180        end 
    181181 
     182        def current_database 
     183          select_value('select current server from sysibm.sysdummy1') 
     184        end 
     185 
     186        def supports_migrations? 
     187          @db2_major_version > 7 
     188        end 
     189 
     190        def rename_table(name, new_name) 
     191          execute "rename table #{name} to #{new_name}" 
     192        end   
     193           
     194        def remove_column(table_name, column_name) 
     195          execute "alter table #{name} drop column #{column_name}" 
     196        end 
     197 
     198        def change_column_default(table_name, column_name, default) 
     199          execute "alter table #{table_name} alter column #{column_name} set #{default}" 
     200        end 
     201 
    182202        def active? 
    183203          @connection.select_one 'select 1 from ibm.sysdummy1' 
    184204          true 
  • lib/active_record/vendor/db2.rb

    old new  
    111111    end 
    112112 
    113113    def columns(table_name, schema_name = '%') 
    114       check_rc(SQLColumns(@handle, '', schema_name.upcase, table_name.upcase, '%')) 
     114      check_rc(SQLColumns(@handle, '', schema_name.to_s.upcase, table_name.to_s.upcase, '%')) 
    115115      fetch_all 
    116116    end 
    117117 
    118118    def tables(schema_name = '%') 
    119       check_rc(SQLTables(@handle, '', schema_name.upcase, '%', 'TABLE')) 
     119      check_rc(SQLTables(@handle, '', schema_name.to_s.upcase, '%', 'TABLE')) 
    120120      fetch_all 
    121121    end 
    122122 
    123123    def indexes(table_name, schema_name = '') 
    124       check_rc(SQLStatistics(@handle, '', schema_name.upcase, table_name.upcase, SQL_INDEX_ALL, SQL_ENSURE)) 
     124      check_rc(SQLStatistics(@handle, '', schema_name.to_s.upcase, table_name.to_s.upcase, SQL_INDEX_ALL, SQL_ENSURE)) 
    125125      fetch_all 
    126126    end 
    127127