Module: ActiveRecord::ConnectionAdapters::SchemaStatements

Defined in:
lib/active_record/connection_adapters/ibm_db_pstmt.rb,
lib/active_record/connection_adapters/ibm_db_adapter.rb

Instance Method Summary collapse

Instance Method Details

#assume_migrated_upto_version(version) ⇒ Object



1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
# File 'lib/active_record/connection_adapters/ibm_db_pstmt.rb', line 1931

def assume_migrated_upto_version(version)
  version = version.to_i
  sm_table = quote_table_name(ActiveRecord::Migrator.schema_migrations_table_name)

  migrated = select_values("SELECT version FROM #{sm_table}").map(&:to_i)
  versions = Dir['db/migrate/[0-9]*_*.rb'].map do |filename|
    filename.split('/').last.split('_').first.to_i
  end

  unless migrated.include?(version)
    pstmt = prepare("INSERT INTO #{sm_table} (version) VALUES (?)")
    execute_prepared_stmt(pstmt, [version])
  end

  inserted = Set.new
  (versions - migrated).each do |v|
    if inserted.include?(v)
      raise "Duplicate migration #{v}. Please renumber your migrations to resolve the conflict."
    elsif v < version
      pstmt = prepare("INSERT INTO #{sm_table} (version) VALUES (?)")
      execute_prepared_stmt(pstmt, [v])
      inserted << v
    end
  end
end

#create_table_definition(*args, **options) ⇒ Object



571
572
573
574
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 571

def create_table_definition(*args, **options)
  puts_log 'create_table_definition SchemaStatements'
  TableDefinition.new(self, *args, **options)
end

#drop_table(table_name, options = {}) ⇒ Object



563
564
565
566
567
568
569
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 563

def drop_table(table_name, options = {})
  if options[:if_exists]
    execute("DROP TABLE IF EXISTS #{quote_table_name(table_name)}")
  else
    execute("DROP TABLE #{quote_table_name(table_name)}", options)
  end
end

#internal_string_options_for_primary_keyObject

:nodoc:



551
552
553
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 551

def internal_string_options_for_primary_key # :nodoc:
  { primary_key: true, null: false }
end

#unique_constraint_name(table_name, **options) ⇒ Object



576
577
578
579
580
581
582
583
584
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 576

def unique_constraint_name(table_name, **options)
  options.fetch(:name) do
    column_or_index = Array(options[:column] || options[:using_index]).map(&:to_s)
    identifier = "#{table_name}_#{column_or_index * '_and_'}_unique"
    hashed_identifier = Digest::SHA256.hexdigest(identifier).first(10)

    "uniq_rails_#{hashed_identifier}"
  end
end

#valid_column_definition_optionsObject

:nodoc:



559
560
561
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 559

def valid_column_definition_options # :nodoc:
  ColumnDefinition::OPTION_NAMES + [:auto_increment]
end

#valid_primary_key_optionsObject

:nodoc:



555
556
557
# File 'lib/active_record/connection_adapters/ibm_db_adapter.rb', line 555

def valid_primary_key_options # :nodoc:
  [:limit, :default, :precision, :auto_increment]
end